Skip to content

Commit f3c552f

Browse files
feat: implement codeql analysis
1 parent 06c64a0 commit f3c552f

File tree

2 files changed

+165
-0
lines changed

2 files changed

+165
-0
lines changed

.github/codeql/codeql-config.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: ProStaff API — CodeQL Config
2+
3+
# Queries beyond the default security suite
4+
# security-extended adds: path traversal, SSRF, code injection, regex DoS
5+
queries:
6+
- uses: security-extended
7+
- uses: security-and-quality
8+
9+
# Focus analysis on application code only
10+
paths-ignore:
11+
- vendor/**
12+
- node_modules/**
13+
- load_tests/**
14+
- security_tests/**
15+
- .pentest/**
16+
- db/migrate/**
17+
- db/schema.rb
18+
- db/seeds.rb
19+
- scripts/**
20+
- '**/*.min.js'
21+
- '**/*_spec.rb'
22+
- spec/**

.github/workflows/codeql.yml

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
name: CodeQL Analysis
2+
3+
# Complementa o security-scan.yml (Brakeman + Semgrep + TruffleHog).
4+
# CodeQL traz engine diferente: detecta SQL injection, path traversal,
5+
# SSRF e code injection no Ruby que as outras ferramentas podem perder.
6+
# Resultados publicados no GitHub Security tab (SARIF).
7+
8+
on:
9+
push:
10+
branches: [ master ]
11+
paths:
12+
- 'app/**'
13+
- 'lib/**'
14+
- 'config/**'
15+
- 'Gemfile'
16+
- 'Gemfile.lock'
17+
- '.github/workflows/codeql.yml'
18+
- '.github/codeql/**'
19+
pull_request:
20+
branches: [ master ]
21+
paths:
22+
- 'app/**'
23+
- 'lib/**'
24+
- 'config/**'
25+
- 'Gemfile'
26+
- 'Gemfile.lock'
27+
schedule:
28+
# Sábado 3am UTC — nao conflita com nightly-security (weekdays) nem security-scan (push/PR)
29+
- cron: '0 3 * * 6'
30+
31+
permissions:
32+
security-events: write # upload SARIF para o Security tab
33+
packages: read
34+
actions: read
35+
contents: read
36+
37+
jobs:
38+
analyze-ruby:
39+
name: Analyze Ruby
40+
runs-on: ubuntu-latest
41+
42+
steps:
43+
- name: Checkout repository
44+
uses: actions/checkout@v4
45+
46+
- name: Initialize CodeQL
47+
uses: github/codeql-action/init@v3
48+
with:
49+
languages: ruby
50+
build-mode: none
51+
config-file: .github/codeql/codeql-config.yml
52+
53+
- name: Perform CodeQL Analysis
54+
uses: github/codeql-action/analyze@v3
55+
with:
56+
category: /language:ruby
57+
output: codeql-results/ruby
58+
59+
- name: Upload SARIF results
60+
uses: github/codeql-action/upload-sarif@v3
61+
if: always()
62+
with:
63+
sarif_file: codeql-results/ruby
64+
category: /language:ruby
65+
66+
analyze-actions:
67+
name: Analyze GitHub Actions Workflows
68+
runs-on: ubuntu-latest
69+
70+
steps:
71+
- name: Checkout repository
72+
uses: actions/checkout@v4
73+
74+
- name: Initialize CodeQL
75+
uses: github/codeql-action/init@v3
76+
with:
77+
languages: actions
78+
build-mode: none
79+
# Sem security-extended aqui — actions usa config padrao
80+
# (security-extended nao tem queries extras para Actions)
81+
82+
- name: Perform CodeQL Analysis
83+
uses: github/codeql-action/analyze@v3
84+
with:
85+
category: /language:actions
86+
output: codeql-results/actions
87+
88+
- name: Upload SARIF results
89+
uses: github/codeql-action/upload-sarif@v3
90+
if: always()
91+
with:
92+
sarif_file: codeql-results/actions
93+
category: /language:actions
94+
95+
codeql-summary:
96+
name: CodeQL Summary
97+
runs-on: ubuntu-latest
98+
needs: [ analyze-ruby, analyze-actions ]
99+
if: always()
100+
101+
steps:
102+
- name: Job Summary
103+
run: |
104+
cat >> $GITHUB_STEP_SUMMARY << 'EOF'
105+
## CodeQL Analysis
106+
107+
| Language | Result |
108+
|----------|--------|
109+
| Ruby | ${{ needs.analyze-ruby.result }} |
110+
| Actions | ${{ needs.analyze-actions.result }} |
111+
112+
Resultados completos disponiveis no [Security tab](../../security/code-scanning).
113+
114+
**Query suite**: `security-extended` + `security-and-quality`
115+
**Escopo**: `app/`, `lib/`, `config/` (exclui vendor, tests, scripts)
116+
EOF
117+
118+
- name: Comment on PR
119+
if: github.event_name == 'pull_request'
120+
uses: actions/github-script@v6
121+
with:
122+
script: |
123+
const ruby = '${{ needs.analyze-ruby.result }}';
124+
const actions = '${{ needs.analyze-actions.result }}';
125+
const status = (r) => r === 'success' ? 'OK' : r === 'failure' ? 'FAIL' : r;
126+
127+
const body = [
128+
'## CodeQL Analysis',
129+
'',
130+
'| Language | Status |',
131+
'|----------|--------|',
132+
`| Ruby (security-extended) | ${status(ruby)} |`,
133+
`| GitHub Actions workflows | ${status(actions)} |`,
134+
'',
135+
'Ver alertas completos no [Security tab](../../security/code-scanning).',
136+
].join('\n');
137+
138+
github.rest.issues.createComment({
139+
issue_number: context.issue.number,
140+
owner: context.repo.owner,
141+
repo: context.repo.repo,
142+
body,
143+
});

0 commit comments

Comments
 (0)