csrf: session-bound CSRF primitive for app POST routes (Jinja global + csrf_protect)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 38/100
- Issue type
- Feature
- Clarity
- Clearly specified
- Activity status
- Active
- Domain
- authentication, backend, security
Research direction
Start by reading the worked example in nyjc-computing/campus-profile PR #67 and the flask_campus login flow that stores OAuth state. Identify where the Jinja environment and auth.logout route are registered, then check the app’s existing tests for route and session behavior. Done means unsafe methods require a matching session token, logout uses POST with protection, and the consumer migration path is documented.
Written by the indexing model from the issue text.
Description
Every campus-family Flask consumer with a POST route currently rolls its own
CSRF. flask_campus owns the session and already handles the login flow's CSRF
(OAuth state), but app POST routes are on their own — so apps invent
per-app idioms that drift.
Worked example: nyjc-computing/campus-profile#61, implemented in PR
nyjc-computing/campus-profile#67: a session-bound synchronizer token (~20
lines — mint-or-return secrets.token_urlsafe() into the session, hidden
form field, secrets.compare_digest on POST, 400 on mismatch/absence). The
same app already carries a second bespoke session nonce (classroom connect,
CLASSROOM_CONNECT_STATE); the next consumer app will invent a third
pattern.
Proposal — a primitive, not a form framework (no Flask-WTF/WTForms; the
ecosystem's wheel-pinning model favours a small dependency-free primitive):
csrf_token(): mint-or-return session token, registered as a Jinja global
so templates render{{ csrf_token() }}directly. This kills the
"forgot to pass it to render_template" failure mode — campus-profile had to
thread the token explicitly through both render paths of the page.csrf_protect(decorator orbefore_requestcheck for unsafe methods —
POST/PUT/PATCH/DELETE): require a non-empty form field and non-empty
session token, compare withsecrets.compare_digest, abort 400 otherwise.
Companion fix in the same change: auth.logout is currently a GET route
(@bp.get("/logout")), which is logout-CSRF-able (a cross-site <img> or
link can sign a user out — nuisance-grade, not a breach). Moving logout to
POST + CSRF token is only possible here; flask_campus owns the route.
Migration: consumers migrate to the primitive and delete their local
implementations (campus-profile's is written and reviewed — use PR #67's
shape as the reference). Ship alongside other changes in the next
flask-campus release so consumers bump the wheel pin once.
- Dominant language
- Python
- Stars
- 0
- Forks
- 0
- Avg merge
- 9m
- Merged PRs (30d)
- 40
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from nyjc-computing/flask-campus
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 25/100
nyjc-computing/flask-campus#46 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 3/5 1-2 days Newbie friendliness 58/100
nyjc-computing/flask-campus#44 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
nyjc-computing/flask-campus#30 ·
Maintainers usually reply within 1 day
All issues in nyjc-computing/flask-campus
Similar issues
-
triage
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
kornia/kornia-rs#1416 · 1 comment ·
Maintainers usually reply within 2 days
-
ui
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
PolicyEngine/ai-inequality#64 ·
Maintainers usually reply within 1 day
-
LinearGaussianStateSpace.dist splits states and observations wrongly when the transition varies over timePossibly taken @PabloRoque claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
pymc-devs/pymc-extras#839 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day