Skip to content

fix(oauth): sanitize Firebase ID token verification errors in 401 responses - #20168

Merged
Git-on-my-level merged 1 commit into
mainfrom
oauth-token-error-sanitize
Oct 1, 2026
Merged

Git-on-my-level merged 1 commit into
mainfrom
oauth-token-error-sanitize

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

What: POST /v1/oauth/token reflected raw Firebase verification exceptions (InvalidIdTokenError details, 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 main before 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 unpatched main code, pass with this diff)
  • scripts/pr-preflight --pr-body-file passes with the citations below

Invariants: 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.

Review in cubic

…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
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-01T12:25:44.045491Z 6ff4955 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

This was referenced Oct 1, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread backend/routers/oauth.py
Comment on lines +188 to +191
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}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. Sanitize str(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

Comment thread backend/routers/oauth.py
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}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

@Git-on-my-level
Git-on-my-level merged commit 57079b3 into main Oct 1, 2026
59 checks passed
@Git-on-my-level
Git-on-my-level deleted the oauth-token-error-sanitize branch October 1, 2026 12:36
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