Repository navigation
security: timing-safe HMAC and CORS wildcard fix - #617
Conversation
- Use hmac.compare_digest with bitwise OR for constant-time JWT signature verification - Reject wildcard CORS origins when allow_credentials=True - Fix Python 2 exception syntax (except TypeError, ValueError -> except (TypeError, ValueError))
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
WalkthroughThe pull request changes legacy subscription-token signature validation to use constant-time comparisons. It also disables CORS credentials when the allowed origins include ChangesLegacy token validation
CORS credential handling
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to The change hardens legacy token signature comparison and stops sending CORS credentials for wildcard origins. No actionable merge-blocking risk is evident. Pre-merge checks |
|
dev restructured app/utils/jwt.py (new HMAC token format, Python 3.14 except syntax), so take dev's version here; the constant-time compare is re-applied to the legacy branch in the next commit.
…e legacy signatures in constant time ALLOWED_ORIGINS defaults to "*". With allow_credentials on, Starlette then echoes every cross-origin request's Origin back together with Access-Control-Allow-Credentials, so any site could make credentialed requests and read the responses. Credentials are now only allowed when the origins are listed explicitly. The panel authenticates with bearer tokens, so the dashboard is unaffected; there is no startup warning, since the wildcard is the default. The legacy subscription token branch still matched its signature with `in`. It now uses hmac.compare_digest on bytes for both encodings (str input must be ASCII, and the signature comes from the URL).
|
@coderabbitai review |
✅ Action performedReview finished.
|
…am PR PasarGuard#617) With the default ALLOWED_ORIGINS=* and allow_credentials=True, Starlette answers every foreign origin with that origin echoed back and Access-Control-Allow-Credentials: true. The panel authenticates with a bearer token and sets no cookie, so no credential was exposed, but the configuration is the one upstream PR PasarGuard#617 flags. Credentials are now allowed only when the origins are listed explicitly; a wildcard keeps serving plain cross-origin reads. PasarGuard#617's other two changes, the constant-time subscription signature check and the except-clause syntax, are already in the fork's app/utils/jwt.py. Test: tests/test_cors_credentials.py, RED 2 of 3 before and GREEN 3 of 3 after.
hardening, PasarGuard#617 CORS, PasarGuard#879 loopback Xray client inbounds, Fork Tests, and the parity-gate follow-ups Migrations: P13's fork migration bfd88026565b (after fd33c6013baa) was a second head. The integration's own merge revision 8158387867c9 now joins 0374ac83604b with bfd88026565b instead of fd33c6013baa (the approved re-seat; no upstream-authored migration is edited). One head. SQLite: upgrade from d8b2c4f60a17, alembic check, downgrade to d8b2c4f60a17, re-upgrade and alembic check all pass. OVERRIDES.md: union. app/utils/jwt.py keeps P10's revocation-epoch clause and adds P13's PasarGuard#756 iat/exp rule; app/notification/webhook/__init__.py takes P13's PasarGuard#756 proxy_settings clause; the P4b user-modal.tsx entry and P13's client-template-form.ts entry both stay; the P5 and P11 clauses on node/__init__.py, node_checker.py and record_usages.py are kept.
The ledger parser took any line starting with # as a heading, so a wrapped prose line such as "PasarGuard#879 and PasarGuard#617 ..." closed the Port queue and every entry after it was ignored, and a line "#waived" inside the Port queue moved the following entries into the Waived section, where they counted as decided with no deadline and no security classification. Markdown renders both lines as text, so a reader of the ledger could not see either effect. Headings now follow the CommonMark ATX rule: up to three spaces, one to six hashes, then a space, a tab or the end of the line. A line that names a ledger section without that space ("#waived", "##Port queue") still switches the section as before but is a ledger error, so the gate fails closed; any other hash line is text and leaves the section open. Tests: "#waived", "##ported by design" and " #Waived #" inside the Port queue fail the gate with the new error, "#Waived: moved from the queue" leaves the next security: yes entry red, and a wrapped "PasarGuard#879 ..." line keeps every queued entry counted. All five fail on the previous parser; the existing "##Port queue" case still reports its missing until.
…e03754dec Checked with git ls-remote on 2026-10-11 14:49 UTC; every other forked repository, tag and release is unchanged since 02:55 UTC. - PasarGuard#617 (ef84f21) and the confirmation-dialog escaping (1c25036) are ported by design: the fork has 24bcbba and 0e08156 for the CORS credentials and the constant-time signature compare, and 9c3ae14 for the dialogs (escapeValue on, Trans instead of raw HTML). - The chart stylesheet escaping (a1d697b) and PasarGuard#859 (ba4a0ab, the device-limit race and the proxy_settings leak in /info and /raw) are queued security: yes; the fork has neither, so the gate is red on them until they are ported. - PasarGuard#950, PasarGuard#947, PasarGuard#857, PasarGuard#903, PasarGuard#908 and PasarGuard#996 are queued security: no until 2026-10-25, each with its reason. - Node PasarGuard#64 (e03754dec, WireGuard peers through Xray's UserManager, Go 1.27.1, unpinned pre-release Xray by default) is queued security: no until 2026-10-25; a port must pin the Xray tag. Against live upstream the panel gate now fails only on the 19 port-queue commits classified security: yes, and the node ledger only on f72ac0efacdb (security: yes).
… waiver B7-ADV F9: a bridge waiver whose reason named a CVE and an auth bypass passed, Waived and Ported by design entries for a "fix(auth): ... (CVE-...)" commit passed with no security note, and npm waivers had no classification at all. - Waived entries need exactly one security: yes|no. A waived security: yes entry also needs owner-decision: YYYY-MM-DD-<name>, dated no later than today. - An entry classified security: no fails in every section when the upstream subject or the reason names a CVE or GHSA id or carries a (security) mark. - A Ported by design entry needs a classification when the keyword hint fires on its subject or reason; Waived and Ported by design security: no entries with a hint get the re-review note. - The bridge and npm waivers need security = "yes"|"no", and owner_decision = "YYYY-MM-DD-<name>" for yes. The real ledgers are classified: every Waived entry is security: no (the upstream notifier, telemt and feature commits have no counterpart in the fork); PasarGuard#879, PasarGuard#617, the dashboard name escaping and node PasarGuard#100 are Ported by design with security: yes. The bridge and npm waivers are security = "no"; xray-config-kit 0.3.10 to 0.4.1 only add Xray parity data and MASQUE and XDrive support.
…e files The real ledger's PasarGuard#617 entry cites fork commit 24bcbba for the CORS change in app/middlewares/__init__.py; the commit's OVERRIDES.md line was reworded later, so checking every hunk of the commit refuses a port that is still in place. A cited fork commit is checked in the files the reason names, and in all its files when it names none. RED on 46e6459: the guard.py case fails.
A Ported by design security entry passes on a fork commit that is an ancestor of HEAD and whose change is still there. When the reason names files the fork commit touched, only those files' hunks are checked, so a later rewording of an unrelated line in the same commit (the OVERRIDES.md line of 24bcbba behind PasarGuard#617) no longer refuses a port whose code is in place; a reason that names no file still needs every hunk of the commit. A file counts as named only as a whole path, not as the tail of a longer one.
Changes
app/utils/jwt.py): Replacedinmembership check withhmac.compare_digestusing bitwise OR to ensure both comparisons always execute, preventing timing side-channelsapp/middlewares/__init__.py): Whenallow_credentials=True, any wildcard origin (*) in the allowed origins list now disables credentials with a warningapp/utils/jwt.py): Fixedexcept TypeError, ValueError:toexcept (TypeError, ValueError):What was removed (per project owner feedback)
get_secret_key: The JWT secret key is permanent and doesn't need a TTLinvalidate_secret_key_cache: Unused function removedFiles Changed
app/utils/jwt.pyapp/middlewares/__init__.pyVerification
Summary by CodeRabbit