Skip to content

Commit 2287839

Browse files
committed
Spring Boot Code QL
1 parent d5c3ed8 commit 2287839

File tree

22 files changed

+1786
-2
lines changed

22 files changed

+1786
-2
lines changed

.github/codeql/config.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: "CodeQL Config"
2+
3+
disable-default-queries: false
4+
5+
queries:
6+
- uses: security-and-quality
7+
- uses: security-extended
8+
- uses: .
9+
from: userapp/secrets
10+
11+
paths:
12+
- 'UserApp/src/main/java'
13+
14+
paths-ignore:
15+
- '**/test/**'
16+
- '**/generated/**'
17+
- '**/target/**'
18+
19+
query-filters:
20+
- exclude:
21+
tags contain: test

.github/codeql/qlpack.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name: userapp/secrets
2+
version: 0.0.1
3+
dependencies:
4+
codeql/java-all: "*"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @name Find hardcoded secrets
3+
* @description Detects hardcoded secrets in code
4+
* @kind problem
5+
* @problem.severity warning
6+
* @security-severity 8.0
7+
* @id java/hardcoded-secrets
8+
* @tags security
9+
*/
10+
11+
import java
12+
13+
from StringLiteral literal
14+
where
15+
exists(Field field |
16+
// Match field name patterns (case-insensitive)
17+
field.getName().regexpMatch("(?i).*(api_?key|token|secret|password).*") and
18+
// Match field initialization - this links the literal to the field
19+
literal = field.getInitializer() and
20+
// Match common secret patterns in the literal's value
21+
literal.getValue().regexpMatch("(?i).*(sk_.*|apikey_.*|token_.*|[a-zA-Z0-9+/=]{32,})")
22+
)
23+
select
24+
literal,
25+
"Hardcoded secret detected: '" + literal.getValue() + "'"

.github/dependabot.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "maven"
4+
directory: "UserApp"
5+
schedule:
6+
interval: "daily"
7+
labels:
8+
- "dependencies"
9+
- "automerge"
10+
open-pull-requests-limit: 10
11+
pull-request-branch-name:
12+
separator: "-"
13+
commit-message:
14+
prefix: "📦 deps:"

.github/workflows/ci.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Java CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
build:
9+
name: Build and Test User App
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout Repository
13+
uses: actions/checkout@v3
14+
- name: Set up JDK 21
15+
uses: actions/setup-java@v3
16+
with:
17+
java-version: '21'
18+
distribution: 'temurin'
19+
- name: Build with Maven
20+
run: mvn clean package
21+
working-directory: UserApp

.github/workflows/codeql.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: CodeQL
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
permissions:
10+
security-events: write
11+
contents: read
12+
13+
jobs:
14+
analyze:
15+
name: CodeQL Analyze Java
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v3
20+
21+
- name: Set up JDK 21
22+
uses: actions/setup-java@v3
23+
with:
24+
java-version: '21'
25+
distribution: 'temurin'
26+
cache: maven
27+
28+
- name: Enable Debug Mode
29+
run: |
30+
echo "ACTIONS_STEP_DEBUG=true" >> $GITHUB_ENV
31+
echo "CODEQL_EXTRACTOR_JAVA_ROOT_CAUSE_ANALYSIS=true" >> $GITHUB_ENV
32+
33+
- name: Initialize CodeQL
34+
uses: github/codeql-action/init@v3
35+
with:
36+
languages: java
37+
config-file: .github/codeql/config.yml
38+
39+
- name: Build with Maven
40+
run: |
41+
cd session2/java/UserApp
42+
mvn -B clean compile --no-transfer-progress
43+
44+
- name: Perform CodeQL Analysis
45+
uses: github/codeql-action/analyze@v3
46+
with:
47+
category: "/language:java"
48+
output: results
49+
50+
- name: Debug Info
51+
run: |
52+
echo "Contents of .github/codeql:"
53+
ls -R .github/codeql/
54+
echo "Maven build directory:"
55+
ls -R UserApp/target/
56+
57+
- name: Upload SARIF
58+
uses: actions/upload-artifact@v4
59+
with:
60+
name: codeql-results
61+
path: results/java.sarif
62+
retention-days: 5

CONTRIBUTING.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
CONTRIBUTING.md
2+
3+
Contributing Guide for UserApp (Spring Boot + Maven)
4+
5+
- Prerequisites: Java 21, Maven 3.8+
6+
- Fork the repository and clone your fork:
7+
git clone <your-fork-url>
8+
cd session2/java/UserApp
9+
10+
- Build the project:
11+
mvn clean install
12+
13+
- Run the application:
14+
./mvnw spring-boot:run
15+
or
16+
mvn spring-boot:run
17+
18+
- Code style:
19+
- Follow Java and Spring Boot conventions
20+
- Add Javadoc to public classes and methods
21+
- Organize imports
22+
23+
- Testing:
24+
- Add or update unit tests for new features and bug fixes
25+
26+
- Submitting changes:
27+
- Push your branch to your fork
28+
- Open a pull request against the main repository
29+
- Ensure all CI checks pass
30+
31+
- Reporting issues:
32+
- Use GitHub Issues for bugs and feature requests
33+
- Provide clear steps to reproduce and expected behavior
34+
- Test 1:
35+
- code ql
36+
- dependentbot
37+

INSTRUCTIONS.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
INSTRUCTIONS.md
2+
3+
Setup instructions:
4+
- Prerequisites: Java 21, Maven 3.8+
5+
- Clone the repository:
6+
git clone <your-repo-url>
7+
cd session2/java/UserApp
8+
- Configure application properties:
9+
Edit src/main/resources/application.properties for API key, database, and Hibernate settings
10+
11+
How to run the app:
12+
- ./mvnw spring-boot:run
13+
- or: mvn spring-boot:run
14+
15+
API endpoints:
16+
- GET /api/user — Get user by email (query param: email)
17+
- POST /api/user — Create user (JSON body)
18+
- PUT /api/user — Update user (JSON body)
19+
- DELETE /api/user — Delete user by email (query param: email)
20+
21+
Technologies used:
22+
- Spring Boot 3.x
23+
- Java 21
24+
- Maven
25+
- Spring Web
26+
- Spring Data JPA
27+
- H2 Database
28+
- GitHub

0 commit comments

Comments
 (0)