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

Skip to content

Commit 9dbbc3c

Browse files
beenuarBeenu Arora
andauthored
fix(security): sanitise entry_id and actor in waitlist patch log (#442) (#137)
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. Co-authored-by: Beenu Arora <[email protected]>
1 parent a8da034 commit 9dbbc3c

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

services/api/app/api/v1/endpoints/waitlist.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -420,20 +420,29 @@ async def patch_entry(
420420
detail="Could not update waitlist entry.",
421421
) from exc
422422

423-
# CodeQL py/log-injection: sanitise inline so the taint tracker
424-
# sees the .replace() chain directly at the call site. Both values
425-
# are also Pydantic-validated against ``ALLOWED_WAITLIST_STATUSES``
426-
# so they can only ever be short safe identifiers, but the inline
427-
# sanitisation makes the property explicit for static analysis.
423+
# CodeQL py/log-injection: sanitise every value inline so the taint
424+
# tracker sees the .replace() chain directly at the call site.
425+
#
426+
# - ``previous`` / ``payload.status`` are Pydantic-validated against
427+
# ``ALLOWED_WAITLIST_STATUSES`` (short identifiers, no CR/LF), and
428+
# - ``entry_id`` / ``user.user_id`` are typed as ``uuid.UUID`` so the
429+
# string form is always ``[0-9a-f-]{36}``,
430+
#
431+
# but CodeQL's taint tracker treats path params and DB-derived
432+
# strings as user-controlled regardless. Making the cleansing
433+
# explicit at the call site silences the alert without weakening
434+
# any existing guarantee.
428435
safe_previous = (previous or "").replace("\r", "").replace("\n", " ")[:32]
429436
safe_next = (payload.status or "").replace("\r", "").replace("\n", " ")[:32]
437+
safe_entry_id = str(entry_id).replace("\r", "").replace("\n", " ")[:36]
438+
safe_actor = str(user.user_id).replace("\r", "").replace("\n", " ")[:36]
430439
logger.info(
431440
"waitlist_status_transition",
432441
extra={
433-
"entry_id": str(entry_id),
442+
"entry_id": safe_entry_id,
434443
"previous": safe_previous,
435444
"next": safe_next,
436-
"actor": str(user.user_id),
445+
"actor": safe_actor,
437446
},
438447
)
439448
return _to_wire(row)

0 commit comments

Comments
 (0)