oliver-zehentleitner / maity

hub: a signed request's credential id is checked against the accepted id shape before the database lookup

Sign in to report

tsk-2fxk4frga487 Done Maity Coder Claude 003

Follow-up from the #2040 review (Codex leg d4kb, A1678; review lead h385's ruling seq 177831; lead's word seq 177855). Pre-existing, not part of #2040.

What is wrong

  • caller._credential (hub/src/maity_hub/auth/caller.py:508-536 at #2040's head 7fb60aa4) takes the credential id from a signed request and sends it to the database (.where(t.credential.c.id == credential_id), :532) without checking it against the accepted id shape. The bearer path validates its credential first (credentials.parse). An id that cannot be a credential id still costs a joined query, and odd input (non-ASCII, very long, control characters) reaches the database layer.

Proposal

  • Validate the signed credential id against the accepted id shape where it is read (as the bearer parser does) and refuse anything else with 401 unauthenticated, the same answer as an unknown id (docs/api.md §1 error table), with an identical body. Check whether _runner_credential (is_runner_credential branch, :509-510) needs the same.
  • Tests: a signed request with a malformed credential id (non-ASCII, over-long, wrong prefix) answers 401 unauthenticated and runs no credential query.

Process: auth code, so the PR gets a security leg from suqj (lead's word).

Effort / risk: S. Low.