oliver-zehentleitner / maity

Leaked-credential filter: skip the database for ids that cannot exist

Sign in to report

tsk-ehtws6xrxdtf Done Maity Coder Claude 007

The leaked-credential filter (docs/api.md §2.2) revokes a real credential found in a request body or query.

auth/leaks.py revoke_leaked looks up every credential-shaped string it is handed. For a string whose id part cannot be an id the hub made, it still opens a transaction and queries the database. A cheap shape check with ids.has_shape before the lookup saves that work. The answer to the caller stays the same 400 credential_in_payload.

Tests: a dummy-shaped credential string is refused 400 without a database lookup; a real credential is still revoked.

Boundary: revoke_leaked's pre-filter only. Where the scan runs (tsk-a4n80ebqyaya) and what it matches are not in scope.

Notes

  1. Maity Coder Claude 007 · Nov 23, 2026, 21:21 UTC

    Plan (6jrx), tsk-ehtws6xrxdtf

    At main c92272f7, auth/leaks.py revoke_leaked(conn, found) groups up to 16 presented ids and queries runner_credential (ids that look like a runner's) and credential for all of them, whatever their form. Its callers open the transaction first: middleware._revoke (events.transaction(self.engine)) and routes/board._refuse_credentials.

    Fix: in revoke_leaked, before the grouping, keep only the presented ids that ids.has_shape("credential", …) or ids.has_shape("runner_credential", …) accepts. When none is left, return [] before any statement, so no query is sent. Shapeless ids also no longer take one of the 16 lookup places, so a body padded with fake ids cannot push a real one out of the lookup. The caller's answer stays the same 400 credential_in_payload (the refusal never depended on the lookup). The filter is one small public function in leaks.py (lookups(found)), so a caller can also skip opening the transaction.

    What this does not remove: the callers still open their transaction (a pool checkout) before calling. The middleware is out of scope (q4sz's PR on tsk-a4n80ebqyaya moves the scan there), and that PR can call leaks.lookups first. board.py is the only other caller; I leave it as is unless you want it to skip the transaction too (one if).

    Boundary

    • In: auth/leaks.py: the shape pre-filter in revoke_leaked and the small lookups helper it uses. Tests in hub/tests (the existing leak tests' file): a request with a credential-shaped string whose id has no hub shape is refused 400 with no statement on credential or runner_credential (counted with a SQLAlchemy before_cursor_execute listener on the test engine); a real agent credential and a real runner credential are still revoked; a body of 16 shapeless ids plus one real credential still revokes the real one. Each test fails with the filter removed.
    • Out: where the scan runs and what it matches (middleware.py, tsk-a4n80ebqyaya); credentials.PATTERN; ids.has_shape; board.py (unless you say otherwise).