From 0cd86124b21d96f470a383dcc5be884372c01f6b Mon Sep 17 00:00:00 2001 From: lecodev-26 Date: Sat, 14 Nov 2026 10:10:56 +0100 Subject: [PATCH 1/2] ci(security): add reproducible CodeQL SAST --- .github/codeql/codeql-config.yml | 13 ++++ .github/workflows/codeql.yml | 96 ++++++++++++++++++++++++++++ SECURITY.md | 4 ++ docs/security/STATIC_ANALYSIS.md | 103 +++++++++++++++++++++++++++++++ 4 files changed, 216 insertions(+) create mode 100644 .github/codeql/codeql-config.yml create mode 100644 .github/workflows/codeql.yml create mode 100644 docs/security/STATIC_ANALYSIS.md diff --git a/.github/codeql/codeql-config.yml b/.github/codeql/codeql-config.yml new file mode 100644 index 00000000..cd1adb6f --- /dev/null +++ b/.github/codeql/codeql-config.yml @@ -0,0 +1,13 @@ +# NEXUS-Q CodeQL policy. Keep exclusions narrow and review every change. +name: NEXUS-Q CodeQL security-extended + +queries: + - uses: security-extended + +paths-ignore: + # Third-party source is maintained and reviewed upstream, not as project code. + - '**/vendor/**' + - 'vendor/**' + # Build output and generated sources are not authoritative source inputs. + - '**/target/**' + - '**/generated/**' diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 00000000..c1e03e06 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,96 @@ +name: NEXUS-Q CodeQL SAST + +on: + push: + branches: [main] + pull_request: + branches: [main] + types: [opened, synchronize, reopened, ready_for_review] + schedule: + - cron: '23 5 * * 1' + workflow_dispatch: + +permissions: + contents: read + actions: read + security-events: write + +concurrency: + group: nexusq-codeql-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + analyze-compiled: + name: CodeQL (${{ matrix.language }}) + runs-on: ubuntu-latest + timeout-minutes: 60 + strategy: + fail-fast: false + matrix: + include: + - language: rust + build-mode: none + - language: c-cpp + build-mode: none + - language: go + build-mode: manual + steps: + - name: Checkout repository + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + + - name: Install pinned Rust toolchain for source extraction + if: matrix.language == 'rust' + run: | + rustup toolchain install 1.88.0 --profile minimal + rustup default 1.88.0 + + - name: Set up pinned Go toolchain + if: matrix.language == 'go' + uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5 + with: + go-version: '1.22.0' + + - name: Initialize CodeQL + uses: github/codeql-action/init@33d7b85da1a04171e211befe2c739303b9a4c066 # v4 + with: + languages: ${{ matrix.language }} + build-mode: ${{ matrix.build-mode }} + tools: linked + config-file: ./.github/codeql/codeql-config.yml + + - name: Build Go modules for analysis + if: matrix.language == 'go' + run: | + (cd bindings/go && go build ./...) + (cd arena/adapters/circl && go build ./...) + + - name: Analyze + uses: github/codeql-action/analyze@33d7b85da1a04171e211befe2c739303b9a4c066 # v4 + with: + category: /language:${{ matrix.language }} + upload: ${{ (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && 'always' || 'never' }} + + analyze-interpreted: + name: CodeQL (${{ matrix.language }}) + runs-on: ubuntu-latest + timeout-minutes: 45 + strategy: + fail-fast: false + matrix: + language: [python, actions] + steps: + - name: Checkout repository + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + + - name: Initialize CodeQL + uses: github/codeql-action/init@33d7b85da1a04171e211befe2c739303b9a4c066 # v4 + with: + languages: ${{ matrix.language }} + tools: linked + config-file: ./.github/codeql/codeql-config.yml + + - name: Analyze + uses: github/codeql-action/analyze@33d7b85da1a04171e211befe2c739303b9a4c066 # v4 + with: + category: /language:${{ matrix.language }} + upload: ${{ (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && 'always' || 'never' }} diff --git a/SECURITY.md b/SECURITY.md index 0a3174c0..f5c17a0b 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -61,6 +61,10 @@ and the configured fuzzing gates. Main-branch fuzz soak is configured for 45 minutes per designated parser target; V2 development PRs use the shorter 5-minute smoke gate. +## Static analysis + +The repository runs CodeQL SAST for Rust, C/C++, Go, Python, and GitHub Actions. The versioned workflow, query scope, exclusions, local reproduction guidance, and false-positive triage process are documented in [`docs/security/STATIC_ANALYSIS.md`](docs/security/STATIC_ANALYSIS.md). A clean scan is not a guarantee that the code is vulnerability-free. + ## Scope and limitations NEXUS-Q is software. The software backend does not provide hardware isolation diff --git a/docs/security/STATIC_ANALYSIS.md b/docs/security/STATIC_ANALYSIS.md new file mode 100644 index 00000000..9aa49e7b --- /dev/null +++ b/docs/security/STATIC_ANALYSIS.md @@ -0,0 +1,103 @@ +# Static application security testing (SAST) + +NEXUS-Q uses GitHub CodeQL as its versioned SAST engine. CodeQL was selected +instead of adding both CodeQL and Semgrep because GitHub code scanning supports +the repository's principal implementation languages (Rust, C/C++, Go, and +Python) and GitHub Actions workflows, and publishes findings in the repository's +Security/code-scanning interface. For public repositories on GitHub.com, +GitHub documents code scanning as available without requiring a paid GitHub +Code Security entitlement. This workflow does not depend on Semgrep's hosted +platform or an API token. + +The workflow is defined in `.github/workflows/codeql.yml`; its query and path +policy is `.github/codeql/codeql-config.yml`. The CodeQL Action is pinned to the +full v4 commit `33d7b85da1a04171e211befe2c739303b9a4c066`, and checkout is pinned +to `11bd71901bbe5b1630ceea73d27597364c9af683` (v4.2.2). The workflow sets +`tools: linked`, so the CodeQL CLI bundle comes from the pinned Action revision +instead of resolving a floating recommended bundle. Update pins only in a +reviewed change, and record the release/version beside each pin. See the +[GitHub CodeQL code-scanning documentation](https://docs.github.com/en/code-security/concepts/code-scanning/codeql/codeql-code-scanning) +for supported languages and public-repository availability. + +## Coverage and execution + +The workflow analyzes these languages independently so a failure is attributable +to one language: + +| Language | CodeQL mode | Scope | +| --- | --- | --- | +| Rust | `none` | Rust source without invoking a full Cargo build | +| C/C++ | `none` | Native backend and C/C++ SDK source | +| Go | `manual` | Go SDK and CIRCL adapter modules, built with Go 1.22.0 | +| Python | interpreted | Repository Python tooling and scripts | +| GitHub Actions | interpreted | Workflow definitions | + +Analysis runs for pull requests targeting `main`, pushes to `main`, a weekly +schedule, and manual dispatch. Pull requests from forks are still analyzed, +but SARIF upload is disabled for those runs because GitHub does not grant +write access to fork-originated `pull_request` workflows. Their analysis job +status remains visible in Actions. Results from trusted repository events are +uploaded to GitHub code scanning. + +The `security-extended` query suite is enabled. The configuration excludes +third-party vendored source (`**/vendor/**`), build output (`**/target/**`), +and generated source (`**/generated/**`). These exclusions are intentional: +NEXUS-Q does not own upstream vendor code, build products, or generated output. +Project-maintained code, tests, scripts, SDKs, and workflow files remain in +scope. Do not add broad exclusions for cryptographic or native-code directories. + +## Reproducing a scan locally + +Use the CodeQL CLI bundle corresponding to the pinned CodeQL Action release +and the official CodeQL CLI documentation for installation and query-pack +resolution. The workflow uses the bundle linked to that Action revision. From the +repository root, create one database per compiled language (Rust and C/C++ use +`none`; Go uses explicit module build commands): + +```sh +codeql database create /tmp/nexusq-codeql-rust \ + --language=rust --build-mode=none --source-root=. + +codeql database create /tmp/nexusq-codeql-cpp \ + --language=c-cpp --build-mode=none --source-root=. + +codeql database create /tmp/nexusq-codeql-go \ + --language=go --command='(cd bindings/go && go build ./...) && (cd arena/adapters/circl && go build ./...)' --source-root=. +``` + +For each database, run `codeql database analyze` with the matching built-in +`codeql/-queries` security-extended suite and emit SARIF, for example: + +```sh +codeql database analyze /tmp/nexusq-codeql-rust \ + codeql/rust-queries:codeql-suites/rust-security-extended.qls \ + --format=sarif-latest --output=/tmp/nexusq-rust.sarif +``` + +Repeat with `cpp` and `go` query packs for the corresponding databases. For +Python and GitHub Actions, use `codeql database create` with their respective +language identifiers and no build command. Local scans are optional developer +checks; GitHub Actions is the authoritative validation and merge gate for this +repository. + +## Findings, false positives, and exceptions + +1. Review each alert in GitHub code scanning and confirm the affected commit, + source path, query, data flow, and reachable execution path. +2. Fix confirmed findings in a normal pull request and add regression coverage + where practical. +3. If an alert is a false positive or not applicable, dismiss only that alert + with the most accurate GitHub dismissal reason and a concise explanation + referencing the code invariant or evidence. Do not suppress a query globally + to silence one finding. +4. If a query exclusion or path exclusion is genuinely necessary, change the + version-controlled CodeQL config in a pull request and document its scope, + rationale, owner, and review date here. +5. Reopen the alert if later changes invalidate the original rationale. + +A clean CodeQL run is evidence that the configured queries did not report a +finding in the analyzed scope. It is not proof of absence of vulnerabilities, +constant-time behavior, memory safety, cryptographic correctness, certification, +or completion of an independent security audit. CodeQL complements, but does +not replace, review, tests, fuzzing, dependency auditing, and platform-specific +security analysis. From fc09f700379b5a7d3475775f5933de4eb6f8e759 Mon Sep 17 00:00:00 2001 From: lecodev-26 Date: Sat, 14 Nov 2026 10:21:21 +0100 Subject: [PATCH 2/2] ci(security): align CodeQL Go toolchain --- .github/workflows/codeql.yml | 2 +- docs/security/STATIC_ANALYSIS.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index c1e03e06..93cff57d 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -48,7 +48,7 @@ jobs: if: matrix.language == 'go' uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5 with: - go-version: '1.22.0' + go-version: '1.25.0' - name: Initialize CodeQL uses: github/codeql-action/init@33d7b85da1a04171e211befe2c739303b9a4c066 # v4 diff --git a/docs/security/STATIC_ANALYSIS.md b/docs/security/STATIC_ANALYSIS.md index 9aa49e7b..e9181f68 100644 --- a/docs/security/STATIC_ANALYSIS.md +++ b/docs/security/STATIC_ANALYSIS.md @@ -28,7 +28,7 @@ to one language: | --- | --- | --- | | Rust | `none` | Rust source without invoking a full Cargo build | | C/C++ | `none` | Native backend and C/C++ SDK source | -| Go | `manual` | Go SDK and CIRCL adapter modules, built with Go 1.22.0 | +| Go | `manual` | Go SDK and CIRCL adapter modules, built with Go 1.25.0 | | Python | interpreted | Repository Python tooling and scripts | | GitHub Actions | interpreted | Workflow definitions |