Repository navigation
fix(oauth): sanitize Firebase ID token verification errors in 401 responses - #20168
Conversation
…ponses The oauth_token exchange endpoint reflected raw Firebase verification exceptions (InvalidIdTokenError details, cert fetch URLs, key IDs, claim state) directly into HTTP 401 response bodies. Moves the detail to server-side logging (warning/error) and returns static messages. Cherry-picked from #16029 by @Mateidslx (code + regression tests as authored there; verified against current main — the leak is still present). Original bounty proposal #16028 declined; this lands the fix under the maintainer account instead. Verification: backend/.venv pytest tests/unit/test_oauth_firebase_error_sanitization.py — 2 passed. Failure-Class: none
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6ff4955618
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| logger.warning(f"Invalid Firebase ID token: {e}") | ||
| raise HTTPException(status_code=401, detail="Invalid Firebase ID token.") | ||
| except Exception as e: | ||
| raise HTTPException(status_code=401, detail=f"Error verifying Firebase ID token: {e}") | ||
| logger.error(f"Error verifying Firebase ID token: {e}") |
There was a problem hiding this comment.
Sanitize verification exceptions before logging
Both branches now write str(e) verbatim to application logs, relocating the certificate IDs, claim values, URLs, and connection details removed from the response into centralized logging. Because callers with a valid public OAuth CSRF exchange can submit malformed, attacker-controlled tokens, sanitize the exception with sanitize() or log only static/type information; the backend logging policy explicitly requires sanitization of error bodies.
AGENTS.md reference: backend/AGENTS.md:L183-L190
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
1 issue found across 2 files
Confidence score: 3/5
- In
backend/routers/oauth.py, logging raw Firebase exception text can expose certificate IDs and timestamps in logs. Sanitizestr(e)in both branches before logging.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="backend/routers/oauth.py">
<violation number="1" location="backend/routers/oauth.py:188">
P2: These calls log raw Firebase exception text, including the certificate IDs and timestamps in the regression cases. Sanitize `str(e)` in both branches before logging.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| uid = decoded_token['uid'] | ||
| except firebase_admin.auth.InvalidIdTokenError as e: | ||
| raise HTTPException(status_code=401, detail=f"Invalid Firebase ID token: {e}") | ||
| logger.warning(f"Invalid Firebase ID token: {e}") |
There was a problem hiding this comment.
P2: These calls log raw Firebase exception text, including the certificate IDs and timestamps in the regression cases. Sanitize str(e) in both branches before logging.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/routers/oauth.py, line 188:
<comment>These calls log raw Firebase exception text, including the certificate IDs and timestamps in the regression cases. Sanitize `str(e)` in both branches before logging.</comment>
<file context>
@@ -185,9 +185,11 @@ async def oauth_token(
uid = decoded_token['uid']
except firebase_admin.auth.InvalidIdTokenError as e:
- raise HTTPException(status_code=401, detail=f"Invalid Firebase ID token: {e}")
+ logger.warning(f"Invalid Firebase ID token: {e}")
+ raise HTTPException(status_code=401, detail="Invalid Firebase ID token.")
except Exception as e:
</file context>
What:
POST /v1/oauth/tokenreflected raw Firebase verification exceptions (InvalidIdTokenErrordetails, cert fetch URLs, key IDs, claim state) directly into HTTP 401 response bodies. Unauthenticated surface: any caller can submit a malformed token and read internal verification traces.Why: Internal error-detail leakage on an auth endpoint; real (if minor) security hygiene issue, not template hardening against impossible inputs.
Risk: Low — error bodies become static strings; status codes unchanged; detail preserved in server logs.
Solution: Log exception detail server-side (
logger.warning/logger.error), return static 401 messages. Regression tests assert the leak strings no longer appear in the raised HTTPException.Cherry-picked from #16029 by @Mateidslx (code + regression tests as authored; verified the leak still exists on current
mainbefore re-landing). Original bounty proposal #16028 is declined per the maintainer's standing bounty-policy ruling; the fix lands here with credit.Verification evidence:
backend/.venv/bin/python -m pytest tests/unit/test_oauth_firebase_error_sanitization.py— 2 passed (both tests fail on unpatchedmaincode, pass with this diff)scripts/pr-preflight --pr-body-filepasses with the citations belowInvariants: INV-DATA-1
Failure-Class: none
by AI on behalf of David — if you need David's attention urgently, please @Git-on-my-level and escalate with
need human response.