Add CSRF protection to state-changing POST endpoints (closes #11) #16
No reviewers
Labels
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: sneak/upaas#16
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch ":fix/issue-11"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Adds CSRF protection to all state-changing POST endpoints using
gorilla/csrf. The webhook endpoint is excluded since it uses secret-based authentication rather than session cookies.Changes
gorilla/csrfv1.7.3 dependencyCSRF()middleware method ininternal/middleware/middleware.gowrappingcsrf.Protect()with the session secretinternal/server/routes.goto apply CSRF middleware to all HTML-serving routes (login, setup, and protected routes) while excluding the webhook endpointaddGlobals()in handlers to accept*http.Requestand injectCSRFField(viacsrf.TemplateField) into all template data{{ .CSRFField }}/{{ $.CSRFField }}hidden inputs to all 18 POST forms across 8 templatesTesting
All existing tests pass. The linter reports only a pre-existing VCS stamping issue unrelated to this change.
Closes #11
Add gorilla/csrf middleware to protect all HTML-serving routes against cross-site request forgery attacks. The webhook endpoint is excluded since it uses secret-based authentication. Changes: - Add gorilla/csrf v1.7.3 dependency - Add CSRF() middleware method using session secret as key - Apply CSRF middleware to all HTML route groups in routes.go - Pass CSRF token to all templates via addGlobals helper - Add {{ .CSRFField }} / {{ $.CSRFField }} hidden inputs to all forms Closes #11Test Results
Before fix (main branch) — no CSRF test exists
The existing test suite has no CSRF-specific tests, so all tests pass on
mainas well. The vulnerability is that POST endpoints accept requests without any CSRF token validation — there is nothing to fail.After fix (fix/issue-11 branch) — all tests pass
All 13 handler tests pass including setup, login, dashboard, app, and webhook tests.
Linter
This is a pre-existing issue (VCS stamping in detached/shallow clone) unrelated to this PR. No new lint issues introduced.