Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(security): resolve CodeQL alert #442 (waitlist log injection)#137

Merged
beenuar merged 1 commit into
mainfrom
fix/codeql-442
May 14, 2026
Merged

fix(security): resolve CodeQL alert #442 (waitlist log injection)#137
beenuar merged 1 commit into
mainfrom
fix/codeql-442

Conversation

@beenuar
Copy link
Copy Markdown
Owner

@beenuar beenuar commented May 14, 2026

Summary

Resolves the last open CodeQL alert: #442 py/log-injection in services/api/app/api/v1/endpoints/waitlist.py.

PR #136 already inlined .replace() sanitisation for previous / payload.status (the values flagged by alerts #413 / #441), but the next CodeQL scan surfaced a new sub-alert against the same logger.info call — this time tainting on entry_id (path param) and user.user_id (auth context), which also flow into the log extra dict.

Both values are typed as uuid.UUID, so their string form is always [0-9a-f-]{36} and cannot contain CR/LF. But CodeQL's taint tracker treats path params and auth-context values as user-controlled regardless of upstream validation, so the alert re-fired.

Fix

Apply the same inline sanitisation pattern that already covered the status fields:

safe_entry_id = str(entry_id).replace("\r", "").replace("\n", " ")[:36]
safe_actor    = str(user.user_id).replace("\r", "").replace("\n", " ")[:36]

and log safe_entry_id / safe_actor in place of str(entry_id) / str(user.user_id). No behaviour change — these were already canonical UUID strings — but now the sanitiser is explicit at the call site, which is what CodeQL's static analyser needs.

Verification

  • python3 -m py_compile services/api/app/api/v1/endpoints/waitlist.py
  • ruff format ✅ (no changes)
  • ruff check

After merge, CodeQL re-runs on main and alert #442 should auto-close, bringing open alerts to 0.

Test plan

  • Local syntax + format + lint pass
  • CI green on this PR (Python lint, tests, OpenAPI, etc.)
  • Post-merge CodeQL scan closes #442
  • No new alerts surface (verify open count == 0)

Made with Cursor

CodeQL py/log-injection alert #442 flagged the `logger.info` call in
`patch_entry` because the `entry_id` path param (uuid.UUID) and
`user.user_id` (also a UUID) flow into the log record's `extra` dict.

The previous (`previous`) and next (`payload.status`) status fields
were already sanitised inline in PR #136 to clear alerts #413 / #441,
but CodeQL then surfaced #442 against the remaining two values.

Both `entry_id` and `user.user_id` are typed as `uuid.UUID`, so their
string form is always `[0-9a-f-]{36}` and cannot contain CR/LF. But
CodeQL's taint tracker treats path params and auth-context values as
user-controlled regardless of upstream validation, so the alert
re-fired on the next scan.

Apply the same inline `.replace("\r", "").replace("\n", " ")[:36]`
sanitisation to `entry_id` and `user.user_id`, matching the pattern
used for `previous` / `payload.status`. This silences the alert
without weakening any existing guarantee.
@beenuar beenuar merged commit 9dbbc3c into main May 14, 2026
25 checks passed
@beenuar beenuar deleted the fix/codeql-442 branch May 14, 2026 16:32
beenuar added a commit that referenced this pull request May 14, 2026
Brings every cross-cutting doc surface in line with the 21 PRs that
landed on `main` on 2026-05-14, anchored by the v8.0 architectural
foundation (PR #125) and the security + correctness wave that
followed it.

- `CHANGELOG.md` — new `[Unreleased]` block covering the v8.0
  architectural foundation (graph at ingest, four-agent rebrand,
  `/hunt`, sixteen connectors, automation maturity, public
  scoreboard), the eight-PR security hardening wave (PRs #116-#128),
  the three-PR CodeQL alert sweep to zero (#133, #136, #137), the
  UEBA env-var alignment (PR #135, first community contribution,
  closes #134), the security-smoke + UX cleanup pair (PR #132,
  closes #131 + #130), and the playbook engine correctness pass
  (PR #129).
- `README.md` — new `v8.0 wave-1 (on main, not yet tagged)` entry
  in the version-history section; `Next` block rewritten as
  `v8.0 wave-2` with the still-`[~]` items from
  `AISOC_V8_PROGRESS.md`. Version badge intentionally not bumped
  (still 7.3.1) because wave-1 is on `main` but not tagged.
- `AGENTS.md` — new `v8.0 wave-1` block under "Learned Workspace
  Facts" documenting the four-agent topology, `/hunt` surface,
  connector inventory, automation maturity ladder, security wave
  outcomes, CodeQL hygiene patterns (inline `replace`-chain
  sanitisation for `py/log-injection`, single import style for
  `py/import-and-import-from`), and the UEBA env-var dual-alias
  convention.
- `AISOC_V8_PROGRESS.md` — `Status` block refreshed to record that
  PR #125 shipped at `b854010e` on 2026-05-14, list the 12
  post-merge PRs that landed on `main` after it, and clarify that
  wave-2 is the still-tracked `[~]` work.
- `apps/docs/docs/deployment/env-vars.md` — UEBA section rewritten
  around the dual-alias rule (unprefixed wins over `UEBA_`-prefixed,
  matches every other Python service and the `docker-compose.yml`
  exports); table now lists canonical + legacy names side by side.
- `apps/docs/docs/operations/security.md` — new `Static analysis
  (CodeQL)` section: zero alerts on `main` as a CI gate, plus the
  two patterns that came up repeatedly during the sweep
  (inline-at-call-site sanitisation for `py/log-injection`, single
  import style for `py/import-and-import-from`).

No code changes; pure documentation sync.

Co-authored-by: Beenu Arora <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant