Skip to content

fix(notion): sanitize uid and eliminate reflected parameter injection in html routes (#14490) - #14491

Merged
kodjima33 merged 2 commits into
BasedHardware:mainfrom
PINYOPATTANAWASANPORN:fix-notion-xss-security
Sep 18, 2026
Merged

kodjima33 merged 2 commits into
BasedHardware:mainfrom
PINYOPATTANAWASANPORN:fix-notion-xss-security

Conversation

@PINYOPATTANAWASANPORN

@PINYOPATTANAWASANPORN PINYOPATTANAWASANPORN commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary of Changes

  • Enforce strict UID format validation via _sanitize_uid(uid: Optional[str]) -> Optional[str] adhering to ^[a-zA-Z0-9_\-]{1,128}$.
  • Escape rendered attributes in root endpoint (GET /) using html.escape(clean_uid, quote=True) to eliminate reflected parameter breakout and script injection vulnerabilities.
  • Provide defensive fallback to default JSON metadata when uid is missing or invalid.
  • Add format validation guards to /auth/notion (raises HTTP 400), /setup/notion (returns {"is_setup_completed": False}), and /disconnect.
  • Register full unit test suite in plugins/omi-notion-app/test_notion_security.py verifying valid formats, attack vectors, and response escaping.
  • Import re and html in plugins/omi-notion-app/main.py resolving reviewer blocker.

Fixes #14490.

Failure-Class: none

@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 for picking up #14490 — the overall approach here is the right one: positive allowlist validation of uid (^[a-zA-Z0-9_-]{1,128}$ in _sanitize_uid), html.escape(..., quote=True) for attribute contexts, and fail-safe defaults on every route (/auth/notion -> 400, /setup/notion -> is_setup_completed: false, /disconnect -> redirect to /). The new test suite is a welcome addition. One blocking defect, though — it looks like the tests were never run:

Blocking: re and html are never imported

plugins/omi-notion-app/main.py calls re.fullmatch(...) (line 934, inside _sanitize_uid) and html.escape(...) (lines 962, 1005–1006), but neither import re nor import html appears anywhere in the file (the import block at lines 7–31 includes neither, and there are no star imports). Every route that touches a uid — GET /, /auth/notion, /setup/notion, /disconnect — will raise NameError: name 're' is not defined and return a 500, including for well-formed uids. That is a regression versus current behavior for all uid-bearing requests.

Consequently plugins/omi-notion-app/test_notion_security.py cannot pass as written: test_sanitize_uid_valid would crash with NameError on its first assertion. Once the two imports are added, the suite itself looks structurally sound — valid-format cases, injection payloads ("><script ...>, javascript:, path traversal, oversize), per-route rejection checks, and the escaped-link vs default-JSON split in test_root_escapes_uid_and_neutralizes_xss all target the right behavior.

CI: missing Failure-Class declaration

Both failing checks (PR Metadata Preflight, Hygiene) fail on failure-class-protocol: the commit subject begins with fix: and the PR body carries no Failure-Class: line. Adding Failure-Class: none to the PR body should clear both — no whitespace/conflict-marker hygiene issue was reported.

Non-blocking, pre-existing (fine to leave for a follow-up)

  • notion_callback (~line 1081) reflects the error query parameter into the failure page unescaped (<p>{error}</p>) — same family of reflected XSS this PR eliminates for uid, but outside its stated scope.
  • The success page (~line 1164) interpolates {uid} (recovered from the OAuth state) into a link unescaped. Since state is now only minted from a sanitized uid (/auth/notion line ~1046), this is defense-in-depth only.

Requesting changes for the missing imports plus the Failure-Class line; with those fixed this is in good shape for maintainer sign-off on the security approach.

Automated review on behalf of the Omi maintainers. Security fix in an OAuth-adjacent HTML surface — maintainer sign-off on the sanitization approach is needed before merge.


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 Git-on-my-level added security-review Touches auth, provider routing, secrets, or security-sensitive surfaces needs-maintainer-review Needs a human maintainer to sign off before merge python labels Sep 18, 2026
…aping (BasedHardware#14490)

- Closes BasedHardware#14490.
- Add missing `import html` and `import re` in `plugins/omi-notion-app/main.py`.
- Resolves review blocker on PR BasedHardware#14491.
@PINYOPATTANAWASANPORN

Copy link
Copy Markdown
Contributor Author

Thank you for the review and catching that @Git-on-my-level!

Both blocking items have been resolved:

  1. Added import html and import re to plugins/omi-notion-app/main.py in commit 3e39c6f9, resolving the NameError.
  2. Added Failure-Class: none to the PR body to satisfy the CI Preflight and Hygiene checks.

@kodjima33 kodjima33 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.

Confirmed unsanitized uid reflected into notion-app root/auth/disconnect HTML+redirects on main. Fixes #14490 with strict allowlist + html.escape + tests, 5/5. Merging.

@kodjima33
kodjima33 merged commit a6d3f77 into BasedHardware:main Sep 18, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-maintainer-review Needs a human maintainer to sign off before merge python security-review Touches auth, provider routing, secrets, or security-sensitive surfaces

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bounty proposal] fix(notion): sanitize uid and eliminate reflected parameter injection in html routes ($25 proposed)

3 participants