|
| 1 | +name: CodeQL Analysis |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, master] |
| 6 | + paths: |
| 7 | + # Trigger on changes to source code only |
| 8 | + - 'server/**' |
| 9 | + - 'harness/**' |
| 10 | + - 'gui/**' |
| 11 | + - 'conftest.py' |
| 12 | + pull_request: |
| 13 | + branches: [main, master] |
| 14 | + paths: |
| 15 | + - 'server/**' |
| 16 | + - 'harness/**' |
| 17 | + - 'gui/**' |
| 18 | + - 'conftest.py' |
| 19 | + schedule: |
| 20 | + # Run weekly on Sundays at 3:00 AM UTC (after nightly scans) |
| 21 | + - cron: '0 3 * * 0' |
| 22 | + workflow_dispatch: |
| 23 | + # Allow manual trigger for debugging |
| 24 | + # NOTE: Do NOT use pull_request_target here - it runs with elevated permissions |
| 25 | + # from the base branch, which can be exploited by malicious fork PRs |
| 26 | + |
| 27 | +# Only one CodeQL run per branch at a time |
| 28 | +concurrency: |
| 29 | + group: codeql-${{ github.ref }} |
| 30 | + cancel-in-progress: true |
| 31 | + |
| 32 | +# Permissions required for CodeQL and security tab |
| 33 | +# Fork PRs: security-events: write is required for SARIF upload but GitHub |
| 34 | +# restricts this for fork PRs - CodeQL handles this gracefully |
| 35 | +permissions: |
| 36 | + security-events: write # Required: upload SARIF results |
| 37 | + contents: read # Required: checkout code |
| 38 | + actions: read # Required: detect workflow changes |
| 39 | + |
| 40 | +jobs: |
| 41 | + analyze: |
| 42 | + name: Analyze (${{ matrix.language }}) |
| 43 | + runs-on: ubuntu-latest |
| 44 | + |
| 45 | + strategy: |
| 46 | + fail-fast: false |
| 47 | + matrix: |
| 48 | + # CodeQL supports: cpp, csharp, go, java, javascript, python, ruby, swift |
| 49 | + language: ['python', 'javascript'] |
| 50 | + |
| 51 | + steps: |
| 52 | + - name: Checkout repository |
| 53 | + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 |
| 54 | + |
| 55 | + # Initialize CodeQL tools for scanning |
| 56 | + - name: Initialize CodeQL |
| 57 | + uses: github/codeql-action/init@45c373516f557556c15d420e3f5e0aa3d64366bc # v3 |
| 58 | + with: |
| 59 | + languages: ${{ matrix.language }} |
| 60 | + # Configure paths to scan (consistent with meta.lintScope) |
| 61 | + # and paths to exclude (consistent with meta.excludePatterns) |
| 62 | + config: | |
| 63 | + paths: |
| 64 | + - server |
| 65 | + - harness |
| 66 | + - gui |
| 67 | + - conftest.py |
| 68 | + paths-ignore: |
| 69 | + - runs |
| 70 | + - .venv |
| 71 | + - .pytest_cache |
| 72 | + - '**/node_modules' |
| 73 | + - '**/__pycache__' |
| 74 | + - 'tasks/**/workspace' |
| 75 | + - '**/*.pyc' |
| 76 | + # Use security-and-quality queries for comprehensive analysis |
| 77 | + # Brownfield-safe: start with default queries, expand later |
| 78 | + queries: +security-and-quality |
| 79 | + |
| 80 | + # For Python, we don't need to build - CodeQL can analyze source directly |
| 81 | + # For JavaScript, CodeQL also analyzes source directly (no build needed) |
| 82 | + - name: Autobuild |
| 83 | + uses: github/codeql-action/autobuild@45c373516f557556c15d420e3f5e0aa3d64366bc # v3 |
| 84 | + |
| 85 | + # Perform CodeQL Analysis |
| 86 | + - name: Perform CodeQL Analysis |
| 87 | + uses: github/codeql-action/analyze@45c373516f557556c15d420e3f5e0aa3d64366bc # v3 |
| 88 | + with: |
| 89 | + category: "/language:${{ matrix.language }}" |
| 90 | + # Upload SARIF results to GitHub Security tab |
| 91 | + upload: true |
| 92 | + # Brownfield-safe: warn-only initially |
| 93 | + # To fail on high/critical alerts, add: |
| 94 | + # fail-on: error |
| 95 | + # For now, we report all findings without failing the job |
0 commit comments