Skip to content

ci(codeql): two open alerts keep Code Quality red on main #20611

Open

Description

@mrveiss

Problem

Code Quality on main fails at pipeline-scripts/check_codeql_alert_ceiling.sh: 2 open alerts against a ceiling of 0. Runs on main were being cancelled until recently, so this stayed hidden. First seen failing on 87eae8a; the alerts date from 2026-10-27 and 2026-10-31.

Alert Rule Where Reading
1219 py/path-injection autobot-backend/chat_history/session.py:911 The session id passes _sanitize_session_id, and the path comes from validate_relative_path. It looks like a false positive; the validators weren't traced end to end.
1213 py/weak-sensitive-data-hashing autobot-slm-backend/user_management/services/api_key_service.py:182 HMAC-SHA256 of a random secrets.token_hex(20) API token under a pepper, a lookup digest, not password storage. It looks like a false positive.

Dismissing an alert needs a maintainer: an agent's dismissal was refused as a CI bypass.

Acceptance criteria

  • Each alert is fixed, or dismissed by a maintainer with its reason.
  • Code Quality passes on main.

Activity

  1. mrveiss commented on Nov 2, 2026

    @mrveiss
    OwnerAuthor

    Traced both alerts end to end on main at 655489c: both are false positives, with no code to fix. Dismissal needs a maintainer.

    1219, py/path-injection, autobot-backend/chat_history/session.py:911. get_session_owner opens chat_file. Before that:

    1. _sanitize_session_id rejects an empty id, null bytes, .., / and \.
    2. validate_relative_path (autobot_shared/security/path_validator.py:157) rejects absolute paths, parent references and drive qualifiers, then compares realpath results with relative_to(base), which also catches a symlink pointing out of the base.

    The base is _get_chats_directory(), from configuration. CodeQL's Python analysis can't be taught custom sanitizers (noted in .github/codeql/codeql-config.yml), so it can't see this barrier. Not run against a live system; the validator's tests are path_validator_test.py.

    1213, py/weak-sensitive-data-hashing, autobot-slm-backend/user_management/services/api_key_service.py:182. _hmac_hex is HMAC-SHA256 under a pepper, used as a lookup digest for API tokens. Its callers are all in this file, and the only outside entry is validate_key(x_api_key) from the X-API-Key header (services/auth.py:383). Tokens are secrets.token_hex(20), 160 random bits, so a slow password hash adds nothing, and a lookup digest must be deterministic. No account password reaches it. What CodeQL treats as the password source wasn't established, because the alert's message gives only the rule text.

    Close-by, not in this alert: _hash_key_legacy is bare SHA-256 kept to verify old rows. It's also a lookup of random tokens, so it isn't a password weakness; if it's alerted later, the same reasoning applies.

  2. mrveiss commented on Nov 5, 2026

    @mrveiss
    OwnerAuthor

    Maintainer decision 2026-11-05: both alerts are fixed in code, not dismissed ("alert has a reason and it needs to be fixed").

    • 1213: hash through the repo's canonical credential path, keeping every issued API key working.
    • 1219: path containment in the canonical validator, in a shape the analysis models as a sanitiser, used by every chat-file path.

    One PR, Refs #20611.

  3. mrveiss commented on Nov 6, 2026

    @mrveiss
    OwnerAuthor

    Maintainer decision 2026-11-06 for alert 1213: sunset the old key formats, 30-day cutoff.

    • New SLM API keys are stored as a deterministic PBKDF2-HMAC-SHA256 digest with the pepper as salt. The iteration count is set from a latency measurement.
    • An old-format key (HMAC-SHA256 under the current pepper, HMAC under the legacy pepper, or bare SHA-256) is re-hashed to PBKDF2 on its next successful use.
    • 30 days after the change lands, old-format keys that were never re-hashed expire and must be reissued. The legacy verifiers are then removed, and alert 1213 closes on the next scan.

    Alert 1219 is not blocked: one containment fix in validate_relative_path (or an allow-pattern on the session id), covering the chat-file sinks in chat_history/session.py at 125, 137, 253, 428, 769, 780 and 911.

  4. mrveiss commented on Nov 6, 2026

    @mrveiss
    OwnerAuthor

    Maintainer decision 2026-11-06, superseding the 30-day sunset: no integration uses SLM API keys yet, and the existing keys are test keys issued by automation. So the old-format verifiers are removed now. Only the PBKDF2 digest is accepted, and old-format keys must be reissued. The cutoff clock and the follow-up #20869 are no longer needed. Review fixes go into the same PR: a fixed iteration constant, and the two chat-file sinks (session_listing.py:395, terminal_logger.py:76) routed through validate_relative_path.

  5. mrveiss commented on Nov 6, 2026

    @mrveiss
    OwnerAuthor

    AC check against main after the PR #20870 landing (merge bb1f46a, via train PR #20836). Issue stays open; no box ticked.

    AC 1, each alert fixed or dismissed: partly proven, not complete.

    • 1213 (py/weak-sensitive-data-hashing): code-scanning state is fixed (fixed_at 2026-11-06T06:33Z, refs/heads/main). Code on main: autobot-slm-backend/user_management/services/api_key_service.py:161, hashlib.pbkdf2_hmac("sha256", ..., PBKDF2_ITERATIONS); _hash_key_legacy and _hmac_hex are no longer present.
    • 1219 (py/path-injection, autobot-backend/chat_history/session.py:911): state is still open. Code on main has an inline os.path.realpath plus startswith(root + os.sep) containment at the read (session.py get_session_owner), and validate_relative_path is wired into session.py (lines 105, 111, 133, 533, 645, 652, 671, 678, 778, 865), session_listing.py:410 and autobot_logging/terminal_logger.py:66. But the latest CodeQL analysis of main is on d6899a3 (2026-11-06T11:17+02:00), which is before bb1f46a (13:19+02:00). CodeQL has not rescanned main since the fix, so the alert closing is unproven.

    AC 2, Code Quality passes on main: not proven. The latest completed Code Quality run on main (d6899a3) failed. The runs on bb1f46a are still queued.

    Pending: a CodeQL scan of main at or after bb1f46a showing 1219 fixed, then a green Code Quality on main. Will re-check then.

  6. mrveiss commented on Nov 8, 2026

    @mrveiss
    OwnerAuthor

    PR #20870 landed in main via merge train #20836 (merge bb1f46a). Checked against current origin/main:

    • AC1 "Each alert is fixed, or dismissed by a maintainer with its reason." — ✅ ticked. Code-scanning alerts 1213 and 1219 are both state fixed (fixed 2026-11-06); api_key_service.py:161 uses hashlib.pbkdf2_hmac.
    • AC2 "Code Quality passes on main." — NOT ticked: the latest Code Quality runs on main (push and pull_request) are cancelled, so no passing run shows it. Stays open until one completes green on main.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinginfrastructurephase:M1.4Wizard and SLM: choose a mode, apply it, default models workpriority: high

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions