Add CSRF protection to forms #1

Closed
opened 2026-03-05 06:21:16 +00:00 by Mark · 6 comments
Owner

The MVP has no form protection against CSRF attacks. All forms (upload, delete) lack CSRF tokens.

Expected behavior:

  • All POST forms should include CSRF tokens
  • Forms should validate tokens on submission

Suggested approach:

  • Add starlette-csrf middleware
  • Or implement custom CSRF middleware using cookies and form tokens
The MVP has no form protection against CSRF attacks. All forms (upload, delete) lack CSRF tokens. **Expected behavior:** - All POST forms should include CSRF tokens - Forms should validate tokens on submission **Suggested approach:** - Add `starlette-csrf` middleware - Or implement custom CSRF middleware using cookies and form tokens
Author
Owner

This issue is still outstanding. The MVP currently has no CSRF protection on forms.

Work completed so far:

  • Added input validation and escaping
  • Added logging

Remaining: CSRF tokens need to be added to all POST forms.

This is a lower priority than authentication - for now, deploy behind a reverse proxy with auth.

This issue is still outstanding. The MVP currently has no CSRF protection on forms. **Work completed so far:** - Added input validation and escaping - Added logging **Remaining:** CSRF tokens need to be added to all POST forms. This is a lower priority than authentication - for now, deploy behind a reverse proxy with auth.
Author
Owner

Auto-triage: needs decompose

Marked triage-approved + needs-decompose. decompose-executor will pick this up and break it into implementable sub-issues.

## Auto-triage: needs decompose Marked `triage-approved` + `needs-decompose`. decompose-executor will pick this up and break it into implementable sub-issues.
Author
Owner

Auto-triage: needs decompose

Marked triage-approved + needs-decompose. decompose-executor will pick this up and break it into implementable sub-issues.

## Auto-triage: needs decompose Marked `triage-approved` + `needs-decompose`. decompose-executor will pick this up and break it into implementable sub-issues.
Author
Owner

Auto-triage: needs decompose

Marked triage-approved + needs-decompose. decompose-executor will pick this up and break it into implementable sub-issues.

## Auto-triage: needs decompose Marked `triage-approved` + `needs-decompose`. decompose-executor will pick this up and break it into implementable sub-issues.
Author
Owner

Auto-triage: needs decompose

Marked triage-approved + needs-decompose. decompose-executor will pick this up and break it into implementable sub-issues.

## Auto-triage: needs decompose Marked `triage-approved` + `needs-decompose`. decompose-executor will pick this up and break it into implementable sub-issues.
Mark 2026-07-08 16:22:44 +00:00
Author
Owner

Bughunt follow-up: issue was closed with app/csrf.py committed but never wired in — no middleware registration, no POST validation, no hidden form fields, no CSRF tests. The protection was non-functional (verified: /upload set no cookie and accepted tokenless POSTs).

Landed the missing wiring in bda4c59 (fix: wire CSRF protection):

  • Register CsrfMiddleware on the FastAPI app
  • Validate csrf_token in /upload, /game/{slug}/update, /game/{slug}/delete
  • Hidden csrf_token fields in upload/update/delete templates
  • tests/test_csrf.py + rejection/integration tests (105 total passing)

Docs for ITCHBOX_CSRF_SECRET / ITCHBOX_CSRF_SECURE_COOKIE added in 25d1786.

Also fixed while hunting: home() pagination clamps ?page=0/negative to page 1 (was slicing from the wrong end), and update_game now rejects traversal entrypoints (../../etc/passwd) instead of rendering them into the iframe src.

Bughunt follow-up: issue was closed with app/csrf.py committed but never wired in — no middleware registration, no POST validation, no hidden form fields, no CSRF tests. The protection was non-functional (verified: /upload set no cookie and accepted tokenless POSTs). Landed the missing wiring in bda4c59 (fix: wire CSRF protection): - Register CsrfMiddleware on the FastAPI app - Validate csrf_token in /upload, /game/{slug}/update, /game/{slug}/delete - Hidden csrf_token fields in upload/update/delete templates - tests/test_csrf.py + rejection/integration tests (105 total passing) Docs for ITCHBOX_CSRF_SECRET / ITCHBOX_CSRF_SECURE_COOKIE added in 25d1786. Also fixed while hunting: home() pagination clamps ?page=0/negative to page 1 (was slicing from the wrong end), and update_game now rejects traversal entrypoints (../../etc/passwd) instead of rendering them into the iframe src.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Mark/itchbox#1
No description provided.