|
| 1 | +id: cookie-missing-samesite-java |
| 2 | +severity: warning |
| 3 | +language: java |
| 4 | +message: >- |
| 5 | + The application does not appear to verify inbound requests which can |
| 6 | + lead to a Cross-site request forgery (CSRF) vulnerability. If the |
| 7 | + application uses cookie-based authentication, an attacker can trick users |
| 8 | + into sending authenticated HTTP requests without their knowledge from any |
| 9 | + arbitrary domain they visit. To prevent this vulnerability start by |
| 10 | + identifying if the framework or library leveraged has built-in features or |
| 11 | + offers plugins for CSRF protection. CSRF tokens should be unique and |
| 12 | + securely random. The `Synchronizer Token` or `Double Submit Cookie` |
| 13 | + patterns with defense-in-depth mechanisms such as the `sameSite` cookie |
| 14 | + flag can help prevent CSRF. For more information, see: [Cross-site request |
| 15 | + forgery prevention](https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Req\ |
| 16 | + uest_Forgery_Prevention_Cheat_Sheet.html). |
| 17 | +note: >- |
| 18 | + [CWE-352] Cross-Site Request Forgery (CSRF). |
| 19 | + [REFERENCES] |
| 20 | + - https://stackoverflow.com/questions/42717210/samesite-cookie-in-java-application |
| 21 | +rule: |
| 22 | + any: |
| 23 | + - pattern: $RESP.setHeader("Set-Cookie", $T); |
| 24 | + inside: |
| 25 | + stopBy: end |
| 26 | + kind: block |
| 27 | + follows: |
| 28 | + stopBy: end |
| 29 | + kind: formal_parameters |
| 30 | + has: |
| 31 | + stopBy: end |
| 32 | + kind: formal_parameter |
| 33 | + all: |
| 34 | + - has: |
| 35 | + stopBy: end |
| 36 | + kind: type_identifier |
| 37 | + regex: '^HttpServletResponse$' |
| 38 | + - has: |
| 39 | + stopBy: neighbor |
| 40 | + kind: identifier |
| 41 | + - pattern: $RESP.addCookie($$$); |
| 42 | + not: |
| 43 | + follows: |
| 44 | + stopBy: end |
| 45 | + kind: expression_statement |
| 46 | + pattern: $RESP.setHeader("Set-Cookie", $T); |
| 47 | + inside: |
| 48 | + stopBy: end |
| 49 | + kind: block |
| 50 | + follows: |
| 51 | + stopBy: end |
| 52 | + kind: formal_parameters |
| 53 | + has: |
| 54 | + stopBy: end |
| 55 | + kind: formal_parameter |
| 56 | + all: |
| 57 | + - has: |
| 58 | + stopBy: end |
| 59 | + kind: type_identifier |
| 60 | + regex: '^HttpServletResponse$' |
| 61 | + - has: |
| 62 | + stopBy: neighbor |
| 63 | + kind: identifier |
| 64 | + - pattern: $RESP.setHeader("Set-Cookie"); |
| 65 | +constraints: |
| 66 | + T: |
| 67 | + not: |
| 68 | + regex: ".*SameSite=.*" |
0 commit comments