Skip to content

fix(api): require exact match for CSRF whitelist paths - #42118

Merged
fatelei merged 1 commit into
langgenius:mainfrom
soroush5:fix/csrf-whitelist-exact-match
Sep 10, 2026
Merged

fatelei merged 1 commit into
langgenius:mainfrom
soroush5:fix/csrf-whitelist-exact-match

Conversation

@soroush5

Copy link
Copy Markdown
Contributor

Summary

Fixes #42117.

check_csrf_token() matched CSRF_WHITE_LIST with pattern.match(), which anchors only at the start of the path. That silently exempted every route starting with a whitelisted prefix — e.g. all workflows/draft/* variable CRUD and iteration/loop node-run endpoints — from CSRF validation. Only the two intended endpoints (keepalive draft autosave, archive file download) should be exempt.

One-line change: match() -> fullmatch() in api/libs/token.py, plus regression tests locking the exact-path exemptions in and the prefix paths out.

Screenshots

Before After
.../workflows/draft/variables with no tokens passes the CSRF check same request raises Unauthorized

Checklist

  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I ran the backend unit tests for the touched area (tests/unit_tests/libs/, plus neighboring controller suites) — all green.
  • This change requires a documentation update

From Hermes Agent

check_csrf_token used pattern.match(), which only anchors at the start
of the path. Any route starting with a whitelisted prefix (e.g. all
workflows/draft/* variable and node-run endpoints) skipped CSRF
validation. Use fullmatch() so only the two intended endpoints
(keepalive draft sync, archive file download) are exempt.
@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 64.07% 64.06% -0.00%
Strict coverage 63.67% 63.67% -0.00%
Typed symbols 45,906 45,907 +1
Untyped symbols 25,907 25,909 +2
Modules 3397 3397 0

@fatelei
fatelei added this pull request to the merge queue Sep 10, 2026
Merged via the queue into langgenius:main with commit a425a12 Sep 10, 2026
45 checks passed
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.

CSRF whitelist matches URL prefixes, exempting workflows/draft/* endpoints from CSRF checks

2 participants