-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Open
Description
Under section 1.1 of https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html#how-to-treat-fetch-metadata-headers-on-the-server-side there is a rendering issue with the code blocks. Three successive code blocks are merged into one, and the headings between them are rendered as code.
Source file:
CheatSheetSeries/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.md
Lines 192 to 239 in 7a75595
| 1. If `Sec-Fetch-Site` is present | |
| 1.1. Treat cross-site as untrusted for state-changing actions. By default, reject non-safe methods (POST / PUT / PATCH / DELETE) when `Sec-Fetch-Site: cross-site`. | |
| ```JavaScript | |
| const SAFE_METHODS = new Set(['GET','HEAD','OPTIONS']); | |
| const site = req.get('Sec-Fetch-Site'); // e.g. 'cross-site','same-site','same-origin','none' | |
| if (site === 'cross-site' && !SAFE_METHODS.has(req.method)) { | |
| return false; // forbid this request | |
| } | |
| ``` | |
| 1.2 If your application relies on [safe HTTP methods](https://developer.mozilla.org/en-US/docs/Glossary/Safe/HTTP) (GET, HEAD, or OPTIONS) for state‑changing actions, you should explicitly reflect that in your policy – e.g., by requiring a Fetch‑Metadata header review for requests to those endpoints. This can be enforced with a policy rule like: | |
| ```JavaScript | |
| const SAFE_METHODS = new Set(['GET','HEAD','OPTIONS']); | |
| const SENSITIVE_ENDPOINTS = new Set([ | |
| '/user/profile', | |
| '/account/details', | |
| ]); | |
| const site = req.get('Sec-Fetch-Site'); | |
| const path = req.path; | |
| // Block if cross-site + unsafe method OR cross-site + sensitive endpoint | |
| if (site === 'cross-site' && (!SAFE_METHODS.has(req.method) || SENSITIVE_ENDPOINTS.has(path))) { | |
| return false; // forbid this request | |
| } | |
| ``` | |
| 1.3. Allow `same-origin`. Treat `same-site` as allowed only if your threat model trusts sibling subdomains; otherwise handle `same-site` conservatively (for example, require additional validation). | |
| ```JavaScript | |
| const trustSameSite = false; // set true only if you trust sibling subdomains | |
| if (site === 'same-origin') { | |
| return true; | |
| } else if (site === 'same-site') { | |
| // handle same-site separately so the subcondition is clearly scoped to same-site | |
| if (!trustSameSite && !SAFE_METHODS.has(req.method)) { | |
| return false; // treat same-site as untrusted for state-changing methods | |
| } | |
| return true; | |
| } | |
| ``` | |
| 1.4. Allow none for user-driven top-level navigations (bookmarks, typed URLs, explicit form submits) where appropriate. |
Screenshot

Metadata
Metadata
Assignees
Labels
No labels