Skip to content

Commit 4db51bb

Browse files
committed
Implement comprehensive security measures including workflows for security scans, secret scanning, and vulnerability assessments; update configuration files to enhance security practices.
1 parent c3db77c commit 4db51bb

17 files changed

Lines changed: 607 additions & 13 deletions

.github/dependabot.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
version: 2
2+
3+
registries: {}
4+
5+
updates:
6+
# NuGet packages for ERP.PL
7+
- package-ecosystem: "nuget"
8+
directory: "/"
9+
schedule:
10+
interval: "weekly"
11+
day: "monday"
12+
time: "06:00"
13+
timezone: "UTC"
14+
open-pull-requests-limit: 10
15+
labels:
16+
- "dependencies"
17+
- "security"
18+
commit-message:
19+
prefix: "deps"
20+
include: "scope"
21+
# Group minor/patch updates together to reduce PR noise
22+
groups:
23+
dotnet-minor-patch:
24+
update-types:
25+
- "minor"
26+
- "patch"
27+
# Auto-merge patch-level security updates
28+
reviewers:
29+
- "Som3a99"
30+
31+
# GitHub Actions workflows
32+
- package-ecosystem: "github-actions"
33+
directory: "/"
34+
schedule:
35+
interval: "weekly"
36+
day: "monday"
37+
time: "06:00"
38+
timezone: "UTC"
39+
open-pull-requests-limit: 5
40+
labels:
41+
- "dependencies"
42+
- "ci"
43+
commit-message:
44+
prefix: "ci"
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: "CodeQL Security Analysis"
2+
3+
on:
4+
push:
5+
branches: [main, develop]
6+
pull_request:
7+
branches: [main, develop]
8+
schedule:
9+
# Run weekly on Monday at 4 AM UTC
10+
- cron: "0 4 * * 1"
11+
12+
permissions:
13+
actions: read
14+
contents: read
15+
security-events: write
16+
17+
jobs:
18+
analyze:
19+
name: Analyze C# Code
20+
runs-on: ubuntu-latest
21+
timeout-minutes: 30
22+
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
language: ["csharp"]
27+
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@v4
31+
32+
- name: Setup .NET
33+
uses: actions/setup-dotnet@v4
34+
with:
35+
dotnet-version: 8.0.x
36+
37+
- name: Initialize CodeQL
38+
uses: github/codeql-action/init@v3
39+
with:
40+
languages: ${{ matrix.language }}
41+
queries: security-extended,security-and-quality
42+
43+
- name: Build solution
44+
run: dotnet build CompanyManagementSystem.sln --configuration Release --no-restore || dotnet build CompanyManagementSystem.sln --configuration Release
45+
46+
- name: Perform CodeQL Analysis
47+
uses: github/codeql-action/analyze@v3
48+
with:
49+
category: "/language:${{ matrix.language }}"

.github/workflows/gitleaks.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Gitleaks Secret Scanning
2+
3+
on:
4+
push:
5+
branches: [main, develop]
6+
pull_request:
7+
branches: [main, develop]
8+
schedule:
9+
# Weekly full scan on Monday at 3 AM UTC
10+
- cron: "0 3 * * 1"
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
gitleaks:
17+
name: Scan for Secrets
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Run Gitleaks
26+
uses: gitleaks/gitleaks-action@v2
27+
env:
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
GITLEAKS_CONFIG: .gitleaks.toml
30+
31+
- name: Upload Gitleaks SARIF report
32+
if: always()
33+
uses: github/codeql-action/upload-sarif@v3
34+
with:
35+
sarif_file: results.sarif
36+
continue-on-error: true

.github/workflows/owasp-zap.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: OWASP ZAP Dynamic Security Scan
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
schedule:
9+
# Weekly scan on Wednesday at 2 AM UTC
10+
- cron: "0 2 * * 3"
11+
12+
permissions:
13+
contents: read
14+
issues: write
15+
16+
jobs:
17+
zap-baseline:
18+
name: ZAP Baseline Scan
19+
runs-on: ubuntu-latest
20+
services:
21+
sqlserver:
22+
image: mcr.microsoft.com/mssql/server:2022-latest
23+
env:
24+
ACCEPT_EULA: Y
25+
SA_PASSWORD: TestP@ssw0rd123!
26+
ports:
27+
- 1433:1433
28+
options: >-
29+
--health-cmd "/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P 'TestP@ssw0rd123!' -C -Q 'SELECT 1'"
30+
--health-interval 10s
31+
--health-timeout 5s
32+
--health-retries 5
33+
34+
steps:
35+
- name: Checkout repository
36+
uses: actions/checkout@v4
37+
38+
- name: Setup .NET
39+
uses: actions/setup-dotnet@v4
40+
with:
41+
dotnet-version: 8.0.x
42+
43+
- name: Restore and build
44+
run: |
45+
dotnet restore CompanyManagementSystem.sln
46+
dotnet build ERP.PL/ERP.PL.csproj --configuration Release --no-restore
47+
48+
- name: Start application
49+
env:
50+
ASPNETCORE_ENVIRONMENT: Testing
51+
ASPNETCORE_URLS: http://localhost:5000
52+
ConnectionStrings__DefaultConnection: "Server=localhost,1433;Database=ERPDB_ZAP;User Id=sa;Password=TestP@ssw0rd123!;TrustServerCertificate=True;"
53+
Database__ApplyMigrationsOnStartup: "true"
54+
Seed__Mode: "None"
55+
run: |
56+
dotnet run --project ERP.PL/ERP.PL.csproj --configuration Release --no-build &
57+
echo "Waiting for application to start..."
58+
for i in $(seq 1 30); do
59+
if curl -s -o /dev/null -w "%{http_code}" http://localhost:5000/health | grep -q "200"; then
60+
echo "Application is ready!"
61+
break
62+
fi
63+
echo "Attempt $i: Waiting..."
64+
sleep 5
65+
done
66+
67+
- name: Run OWASP ZAP Baseline Scan
68+
uses: zaproxy/action-baseline@v0.14.0
69+
with:
70+
target: "http://localhost:5000"
71+
rules_file_name: ".zap/rules.tsv"
72+
cmd_options: "-a -j"
73+
allow_issue_writing: true
74+
fail_action: true
75+
artifact_name: "zap-report"
76+
77+
- name: Upload ZAP Report
78+
if: always()
79+
uses: actions/upload-artifact@v4
80+
with:
81+
name: zap-security-report
82+
path: |
83+
report_html.html
84+
report_json.json
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: Security Gate
2+
3+
# This workflow acts as a required check that aggregates all security scan results.
4+
# Configure this as a required status check for branch protection.
5+
6+
on:
7+
push:
8+
branches: [main, develop]
9+
pull_request:
10+
branches: [main, develop]
11+
12+
permissions:
13+
contents: read
14+
security-events: write
15+
16+
jobs:
17+
security-lint:
18+
name: Security Lint & Configuration Check
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Check for hardcoded secrets in config files
25+
run: |
26+
echo "=== Scanning for potential hardcoded secrets ==="
27+
FOUND=0
28+
29+
# Check appsettings files for non-empty passwords/keys
30+
for file in $(find . -name "appsettings*.json" -not -path "*/bin/*" -not -path "*/obj/*"); do
31+
echo "Checking $file..."
32+
33+
# Check for non-empty password fields
34+
if grep -Pi '"(password|secret|apikey|api_key|token)":\s*"[^"]{8,}"' "$file"; then
35+
echo "::error file=$file::Potential hardcoded secret found in $file"
36+
FOUND=1
37+
fi
38+
39+
# Check for connection strings with inline passwords
40+
if grep -Pi 'Password=[^;]{6,}' "$file"; then
41+
echo "::error file=$file::Potential hardcoded database password in $file"
42+
FOUND=1
43+
fi
44+
done
45+
46+
if [ $FOUND -eq 1 ]; then
47+
echo ""
48+
echo "::error::Hardcoded secrets detected! Move secrets to environment variables or user-secrets."
49+
exit 1
50+
else
51+
echo "No hardcoded secrets found."
52+
fi
53+
54+
- name: Check .gitignore completeness
55+
run: |
56+
echo "=== Checking .gitignore ==="
57+
MISSING=0
58+
59+
REQUIRED_PATTERNS=(
60+
"appsettings.Production.json"
61+
"*.pfx"
62+
"*.key"
63+
".env"
64+
)
65+
66+
for pattern in "${REQUIRED_PATTERNS[@]}"; do
67+
if ! grep -qF "$pattern" .gitignore; then
68+
echo "::warning::Missing .gitignore entry: $pattern"
69+
MISSING=1
70+
fi
71+
done
72+
73+
# Check for dangerous negation rules that expose secret files
74+
if grep -q '!.*appsettings.*\.json' .gitignore; then
75+
echo "::error::Dangerous .gitignore negation rule found that may expose config files with secrets"
76+
exit 1
77+
fi
78+
79+
if [ $MISSING -eq 1 ]; then
80+
echo "::warning::Some recommended .gitignore patterns are missing"
81+
else
82+
echo ".gitignore looks good."
83+
fi
84+
85+
- name: Verify SECURITY.md exists
86+
run: |
87+
if [ ! -f "SECURITY.md" ]; then
88+
echo "::warning::SECURITY.md not found. Consider adding a security policy."
89+
else
90+
echo "SECURITY.md found."
91+
fi
92+
93+
build-and-test:
94+
name: Build Verification
95+
runs-on: ubuntu-latest
96+
steps:
97+
- name: Checkout
98+
uses: actions/checkout@v4
99+
100+
- name: Setup .NET
101+
uses: actions/setup-dotnet@v4
102+
with:
103+
dotnet-version: 8.0.x
104+
105+
- name: Restore
106+
run: dotnet restore CompanyManagementSystem.sln
107+
108+
- name: Build
109+
run: dotnet build CompanyManagementSystem.sln --configuration Release --no-restore
110+
111+
- name: Run tests
112+
run: |
113+
dotnet test Tests/Tests.csproj \
114+
--configuration Release \
115+
--no-build \
116+
--verbosity normal \
117+
--logger "trx;LogFileName=test-results.trx"

.github/workflows/security-scans.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
name: Security Scans
22

33
on:
4+
push:
5+
branches: [main, develop]
46
pull_request:
57
schedule:
68
- cron: "0 3 * * 1"
79

10+
permissions:
11+
contents: read
12+
813
jobs:
914
dependency-review:
1015
if: github.event_name == 'pull_request'
@@ -14,6 +19,8 @@ jobs:
1419
uses: actions/checkout@v4
1520
- name: Dependency Review
1621
uses: actions/dependency-review-action@v4
22+
with:
23+
fail-on-severity: moderate
1724

1825
dotnet-vulnerability-scan:
1926
runs-on: ubuntu-latest
@@ -30,4 +37,23 @@ jobs:
3037
run: dotnet restore CompanyManagementSystem.sln
3138

3239
- name: Scan NuGet vulnerabilities
33-
run: dotnet list CompanyManagementSystem.sln package --vulnerable --include-transitive
40+
run: |
41+
dotnet list CompanyManagementSystem.sln package --vulnerable --include-transitive 2>&1 | tee vuln-report.txt
42+
if grep -q "has the following vulnerable packages" vuln-report.txt; then
43+
echo "::error::Vulnerable packages detected!"
44+
exit 1
45+
fi
46+
47+
dotnet-build-warnings:
48+
runs-on: ubuntu-latest
49+
steps:
50+
- name: Checkout
51+
uses: actions/checkout@v4
52+
53+
- name: Setup .NET
54+
uses: actions/setup-dotnet@v4
55+
with:
56+
dotnet-version: 8.0.x
57+
58+
- name: Build with security analyzers
59+
run: dotnet build CompanyManagementSystem.sln --configuration Release /p:TreatWarningsAsErrors=false

0 commit comments

Comments
 (0)