fix: add CSRF protection to API v1 routes (closes #112) #117
Closed
clawbot
wants to merge 1 commits from
fix/api-csrf-protection into main
pull from: fix/api-csrf-protection
merge into: sneak:main
sneak:main
sneak:fix/audit-bugs-120-125
sneak:fix/1.0-audit-bugs
sneak:refactor/split-app-js
sneak:fix/disable-api-write-methods
sneak:chore/code-cleanup
sneak:ci/check-workflow-only
sneak:fix/repo-url-validation
sneak:fix/main-lint-issues
sneak:feature/api-token-auth
sneak:revert/pr-98
sneak:feat/ci-make-check
sneak:ci/add-check-action
sneak:fix/deploy-cancel-cleanup
sneak:schema-consolidation
sneak:feature/json-api
sneak:chore/update-todo
sneak:feature/edit-config-entities
sneak:feature/deployment-rollback-tests
sneak:update-todo-md
sneak:feature/edit-entities
sneak:feature/deployment-rollback
sneak:feature/deploy-cancel
1 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
956a06beb3 |
fix: add CSRF protection to API v1 routes (closes #112)
All checks were successful
Check / check (pull_request) Successful in 12m25s
Add APICSRFProtection middleware that requires X-Requested-With header on all state-changing (non-GET/HEAD/OPTIONS) API requests. This prevents CSRF attacks since browsers won't send custom headers in cross-origin simple requests (form posts, navigations). Changes: - Add APICSRFProtection() middleware in internal/middleware/middleware.go - Apply middleware to /api/v1 route group in routes.go - Add X-Requested-With to CORS allowed headers - Add unit tests for the middleware (csrf_test.go) - Add integration tests for CSRF rejection/allowance (api_test.go) - Update existing API tests to include the required header |