Commit 48e612f
security: add Origin header validation for CSRF protection (#413)
* security: add Origin header validation for CSRF protection
Validate Origin header on state-changing requests (POST, PUT, DELETE)
to provide additional CSRF protection beyond SameSite cookies.
- Add isOriginAllowed() function to validate request origins
- Reject requests with invalid/disallowed Origin headers on POST/PUT/DELETE
- Allow localhost origins in development mode
- Log rejected requests for security monitoring
- Dynamic CORS header based on request origin
This complements SameSite=Lax cookies for comprehensive CSRF protection.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Add Vary: Origin header to prevent caching issues
Addresses review feedback to add the Vary header when responses
differ based on the Origin header. This prevents browsers and
CDNs from incorrectly caching CORS responses.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>1 parent 39e595c commit 48e612f
1 file changed
Lines changed: 40 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
155 | 156 | | |
156 | 157 | | |
157 | 158 | | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
158 | 178 | | |
159 | 179 | | |
160 | 180 | | |
161 | | - | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
162 | 199 | | |
163 | 200 | | |
164 | 201 | | |
| 202 | + | |
| 203 | + | |
165 | 204 | | |
166 | 205 | | |
167 | 206 | | |
| |||
0 commit comments