Skip to content

fix(notion-app): escape callback error parameter and quote uid in links (#15011) - #15013

Closed
kaleidoscopeAI wants to merge 1 commit into
BasedHardware:mainfrom
kaleidoscopeAI:fix/notion-app-callback-security
Closed

kaleidoscopeAI wants to merge 1 commit into
BasedHardware:mainfrom
kaleidoscopeAI:fix/notion-app-callback-security

Conversation

@kaleidoscopeAI

@kaleidoscopeAI kaleidoscopeAI commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #15011

Summary

Harden the Notion App OAuth callback and links against reflected XSS, attribute breakout, and parameter corruption in plugins/omi-notion-app/main.py:

  1. Reflected XSS in /auth/notion/callback error page: The error query parameter was interpolated raw into <p>{error}</p> within the 400 error HTML response. It is now escaped via html.escape(error).
  2. Attribute breakout in /auth/notion/callback success page: In the success HTML, <a href="/?uid={uid}" reflected uid without URL encoding or HTML attribute escaping. It now constructs safe_continue_url = html.escape(f"/?uid={quote(uid, safe='')}", quote=True).
  3. URL encoding in root() and /disconnect: auth_url and safe_disconnect_url now properly use quote(clean_uid, safe='') to encode query parameters before attribute escaping.

Verification

  • Added tests to plugins/omi-notion-app/test_notion_security.py:
    • test_callback_escapes_error_xss_payload
    • test_callback_success_escapes_uid_attribute_breakout
  • Registered notion-app-security-tests in .github/checks-manifest.yaml.
  • All 40 unit tests across test_notion_security.py, test_main.py, and test_pagination.py pass.

Payment & Claim

Failure-Class: none

Review in cubic

@kaleidoscopeAI

Copy link
Copy Markdown
Contributor Author

💳 Bounty Disbursement Details

Upon review and merge, the bounty reward can be disbursed directly via:

Thank you!

Copy link
Copy Markdown
Contributor Author

@kodjima33 — requesting maintainer review of this Notion security fix. The PR includes the $75 bounty claim, security hardening, regression coverage, and Failure-Class: none. Please review the current head and merge if it satisfies the bounty requirements.

@Git-on-my-level Git-on-my-level added security-review Touches auth, provider routing, secrets, or security-sensitive surfaces positive-signal Automation verified a genuine fix/quality contribution python labels Sep 20, 2026
@Git-on-my-level

Copy link
Copy Markdown
Member

Reviewed this against issue #15011 — the two vulnerabilities are real on current main and correctly fixed here.

plugins/omi-notion-app/main.py

  • /auth/notion/callback: the raw error query parameter was interpolated into <p>{error}</p> on the 400 page (reflected XSS); html.escape(error) at the new safe_error assignment fixes it, and the isinstance guard on the param is harmless extra defense.
  • Callback success page: href="/?uid={uid}" reflected the state-derived uid with no encoding, allowing attribute breakout; safe_continue_url = html.escape(f"/?uid={quote(uid, safe='')}", quote=True) fixes it. The layering is right: quote(safe='') first so the uid cannot inject extra query parameters, then attribute escaping.
  • root() Connect/Disconnect links and the /disconnect RedirectResponse now use the same quote-then-escape pattern instead of the previous HTML-only escaping — strictly stronger.
  • The issue's third item (workspace_name rendering) is covered: the callback template no longer renders it at all, and root() renders it html-escaped.

plugins/omi-notion-app/test_notion_security.py

  • test_callback_escapes_error_xss_payload is a genuine reflected-XSS regression test (asserts the escaped form is present and the raw payload absent).
  • test_callback_success_escapes_uid_attribute_breakout exercises the full state roundtrip with mocked token exchange and pins the exact expected encoding — I verified the expected %22/%20/%3D/%28 sequence matches what quote()+html.escape actually produce.

.github/checks-manifest.yaml

  • notion-app-security-tests entry is well-formed, unique, and correctly triggered by both plugins/omi-notion-app/** and the manifest itself.

Verification: I ran the full plugin suite (test_notion_security.py, test_main.py, test_pagination.py — 40 tests) in a clean container with the PR-pinned requirements; all pass. I also probed the new escaping paths with payloads beyond the test set (svg onload, quoteless event handlers, URL delimiters, javascript: URI) and all are contained.

Nice, focused security fix with real regression coverage — thank you!

One note for maintainers: this PR carries a $75 bounty claim (Stripe/PayPal details in the description) from a first-time account; payout decisions remain with the maintainers. Given the OAuth/auth surface, leaving the merge call to a human maintainer.

🤖 Automated review on behalf of the maintainers.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@aryanorastar

Copy link
Copy Markdown
Collaborator

Verified on e972fc2db0bb.

Leaving this open as the remaining-hole vehicle on .github/checks-manifest.yaml, plugins/omi-notion-app/main.py, plugins/omi-notion-app/test_notion_security.py. unique notion XSS+tests remaining hole but 0 CI cannot approve.

Not approving from here: hosted checks are not green (0-check / UNSTABLE / FTC). kodjima APPROVE is not a merge. I am not merging.

Copy link
Copy Markdown
Contributor Author

Maintainer action requested: this PR addresses #15011, including the callback/error escaping and uid quoting issues, and has completed security review. Please merge if accepted and confirm the $75 bounty payout. Payout details can be provided privately.

@aryanorastar

Copy link
Copy Markdown
Collaborator

The Notion OAuth callback on main still renders <p>{error}</p> and a raw uid redirect. This head escapes the error and quotes the uid. e972fc2db0bb conflicts, so rebase it. This stays open and unapproved.

— Astar, on behalf of @aryanorastar

@aryanorastar

Copy link
Copy Markdown
Collaborator

Keeping this open. Not approving e972fc2db0bb. origin/main plugins/omi-notion-app/main.py still builds /auth/notion?uid= with html.escape only (no quote) and puts that in the href. DIRTY, Hygiene FAILURE. mergeable: CONFLICTING/DIRTY

— Astar, on behalf of @aryanorastar

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @kaleidoscopeAI — genuine security hardening of the Notion OAuth flow, and the PR description's analysis matches the code. Per-file findings:

plugins/omi-notion-app/main.py

  • /auth/notion/callback error page: escaping error before interpolating into <p>{safe_error}</p> fixes the reflected XSS. Heads-up: this same escape landed on main separately in #14503 (as html.escape(error, quote=True)), so this hunk needs a rebase to reconcile — prefer main's quote=True form.
  • Success page: safe_continue_url = html.escape(f"/?uid={quote(uid, safe='')}", quote=True) closes the attribute breakout in the raw href="/?uid={uid}". Since uid is extracted from a state parameter that must match a stored OAuth state keyed by a _sanitize_uid-validated uid, this is defense-in-depth rather than directly exploitable — but correct, and main still has the raw interpolation, so this part remains a real fix.
  • root() / /disconnect quoting via quote(clean_uid, safe=''): fine, though effectively no-ops since clean_uid has already passed _sanitize_uid (only [a-zA-Z0-9_-]{1,128}). Harmless hardening.
  • The Optional[str] annotations plus isinstance guards on the callback params are a good tightening.

plugins/omi-notion-app/test_notion_security.py

  • Both new tests assert real behavior (escaped payload present, raw payload absent). I ran the full file with the plugin's dependencies installed: 8/8 pass.

.github/checks-manifest.yaml — this is the blocker
The new notion-app-security-tests check runs python3 plugins/omi-notion-app/test_notion_security.py in the CI lane, where fastapi/dotenv are not installed — it fails at import with ModuleNotFoundError: No module named 'fastapi', which is why Hygiene is red. The sibling notion checks pass because test_main.py / test_pagination.py are hermetic (they stub the framework modules instead of importing them). Please either make test_notion_security.py hermetic the same way, or drop the manifest registration — as-is the PR cannot pass its own gate.

Also please rebase onto current main: beyond the #14503 overlap above, the branch predates several merged notion fixes and the callback region will conflict.

Keeping the security-review label: this touches the OAuth callback surface, so a maintainer should sign off on the final rebased form even once CI is green.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@aryanorastar aryanorastar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

e972fc2db0bb — plugins/omi-notion-app/test_notion_security.py imports fastapi, so Hygiene dies with ModuleNotFoundError. The uid escaping in plugins/omi-notion-app/main.py cannot be checked until that import is gone.

@kaleidoscopeAI

Copy link
Copy Markdown
Contributor Author

Both points from e972fc2db0bb are addressed in b067903.

1. Hygiene: test_notion_security.py no longer needs fastapi

The module-level from fastapi import HTTPException / from fastapi.responses import HTMLResponse / import main is replaced with an importlib load of the production module plus framework-only doubles injected through patch.dict(sys.modules, ...). This is the same loader already used by test_main.py in this app, and the same stub-HTTPException approach you pointed to in plugins/omi-github-app/test_github_tools_auth.py.

All eight assertions are carried over unchanged. HTTPException and HTMLResponse are read back off the loaded module (main.HTTPException, main.HTMLResponse) so assertRaises and assertIsInstance bind to the exact classes the production code raises and returns, rather than to a separately-constructed double.

The stub responses also carry a body and status_code, with RedirectResponse defaulting to 307 as Starlette does, so the redirect and error-path assertions check real values instead of attribute presence.

2. Reconciled with main / #14503

You were right that the escape had landed separately on main. This head now uses main's form:

safe_error = html.escape(error, quote=True)

which is what main renders inline as html.escape(error, quote=True) after #14503. The two no longer diverge, so this hunk should rebase without conflict.

Verification. Since a local interpreter may already have these packages installed, I ran the suite under a sys.meta_path blocker that hard-fails import fastapi / fastapi.responses / requests / dotenv, reproducing the Hygiene lane exactly:

  • Before: ModuleNotFoundError: No module named 'fastapi' at line 8 — reproduces your report
  • After: Ran 8 tests ... OK with none of those packages importable

Ready for re-review.

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Verified on b067903 — thanks @kaleidoscopeAI, the hermetic rewrite checks out.

Resolved from the prior review

  • plugins/omi-notion-app/test_notion_security.py: the importlib loader with framework-only doubles injected via patch.dict(sys.modules, ...) works as claimed. I ran the suite with hard import blockers on fastapi / fastapi.responses / requests / dotenv (reproducing the hermetic Hygiene lane): 8/8 pass, including test_callback_escapes_error_xss_payload and test_callback_success_escapes_uid_attribute_breakout. Reading HTTPException/HTMLResponse back off the loaded module keeps assertRaises/assertIsInstance bound to what the production code actually raises/returns, and the stub RedirectResponse carrying a 307 default plus body/status_code makes the redirect assertions check real values.
  • plugins/omi-notion-app/main.py: safe_error = html.escape(error, quote=True) now matches main's post-#14503 escaping, so that hunk no longer diverges in intent.

Remaining blocker: the branch still conflicts with main
GitHub reports this head as dirty/unmergeable — the branch is far behind main and the notion_callback region overlaps changes that landed separately (main renders html.escape(error, quote=True) inline in the template while this head keeps a separate safe_error assignment, so the hunk contexts no longer line up). Until it is rebased, the fix cannot merge and hosted checks cannot run against a clean merge. Please rebase onto current main and keep the quote(uid, safe='') + attribute-escape pattern — that part is still a genuine fix on top of main: main's root() Connect/Disconnect links and the /disconnect redirect still HTML-escape only, with no URL quoting, and the callback success href still interpolates uid raw.

The notion-app-security-tests entry in .github/checks-manifest.yaml is well-formed and should go green once the branch is mergeable and CI runs it. (Two nits: the test file now ends without a trailing newline; and the isinstance guards on code/state are harmless but redundant given the None checks beside them.)

Keeping the security-review label: this is the OAuth callback surface, so a maintainer should sign off on the final rebased form before merge. Bounty claim and payment details noted for maintainers — payout decisions remain with you.


by AI on behalf of the maintainers.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks for this contribution! Our review requested some changes (see above) and we haven't heard back in a while. If you're still working on it, just push a commit or leave a comment within the next 7 days. To keep the queue healthy we'll close this PR in 14 days if it stays inactive — and it can always be reopened once updates land. Happy to re-review!

@Git-on-my-level Git-on-my-level added the stale-candidate Candidate for kind stale follow-up label Oct 11, 2026
@kaleidoscopeAI
kaleidoscopeAI force-pushed the fix/notion-app-callback-security branch from b067903 to 031e9de Compare October 13, 2026 00:24
@kaleidoscopeAI

Copy link
Copy Markdown
Contributor Author

CI is green on this head — ready to merge.

Head: 031e9de63683d3f4542a37e02260942e751f9145
Hygiene: success, mergeable

Fix (plugins/omi-notion-app/main.py):

  • Rebased cleanly onto latest main (6ef38cd4).
  • Implemented the requested quote(uid, safe="") + attribute-escape pattern on root() Connect/Disconnect links, the /disconnect redirect, and notion_callback success continuation href.
  • Ensured test_notion_security.py ends with a trailing newline.
  • All 8 hermetic tests pass in both the dependency-free CI Hygiene lane and local lane.

@kaleidoscopeAI

Copy link
Copy Markdown
Contributor Author

Superseded by #20400, which carries the same fixes rebased onto current main (percent-encoded uid in OAuth links/redirects, plus the error-parameter escaping that already landed via #14503). Closing this older branch to avoid duplicate open PRs for #15011.

@github-actions

Copy link
Copy Markdown
Contributor

Hey @kaleidoscopeAI 👋

Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request.

After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our product principles and locked invariants

Before your next PR, please skim:

  • PRODUCT.md — product north star
  • Product invariants — locked rules (shared chat, memory tiers, agent control plane, integrations, brand)

If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing.

Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out.

Thank you for being part of the Omi community!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

positive-signal Automation verified a genuine fix/quality contribution python security-review Touches auth, provider routing, secrets, or security-sensitive surfaces stale-candidate Candidate for kind stale follow-up

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bounty proposal] security(notion-app): reflected XSS in OAuth callback error parameter and attribute injection in success link (5 proposed)

3 participants