Repository navigation
fix(notion): sanitize uid and eliminate reflected parameter injection in html routes (#14490) - #14491
Conversation
Git-on-my-level
left a comment
There was a problem hiding this comment.
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 theerrorquery parameter into the failure page unescaped (<p>{error}</p>) — same family of reflected XSS this PR eliminates foruid, but outside its stated scope.- The success page (~line 1164) interpolates
{uid}(recovered from the OAuthstate) into a link unescaped. Sincestateis now only minted from a sanitized uid (/auth/notionline ~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.
…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.
|
Thank you for the review and catching that @Git-on-my-level! Both blocking items have been resolved:
|
Summary of Changes
_sanitize_uid(uid: Optional[str]) -> Optional[str]adhering to^[a-zA-Z0-9_\-]{1,128}$.GET /) usinghtml.escape(clean_uid, quote=True)to eliminate reflected parameter breakout and script injection vulnerabilities.uidis missing or invalid./auth/notion(raises HTTP 400),/setup/notion(returns{"is_setup_completed": False}), and/disconnect.plugins/omi-notion-app/test_notion_security.pyverifying valid formats, attack vectors, and response escaping.reandhtmlinplugins/omi-notion-app/main.pyresolving reviewer blocker.Fixes #14490.
Failure-Class: none