-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(java): split insecure cookie rule
- Loading branch information
Showing
5 changed files
with
89 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
imports: | ||
- java_shared_lang_instance | ||
patterns: | ||
- pattern: $<COOKIE>.setHttpOnly($<FALSE>) | ||
filters: | ||
- variable: COOKIE | ||
detection: java_shared_lang_instance | ||
scope: cursor | ||
filters: | ||
- variable: JAVA_SHARED_LANG_INSTANCE_TYPE | ||
regex: \A(javax\.servlet\.http\.)?Cookie\z | ||
- variable: "FALSE" | ||
detection: java_lang_cookie_with_http_only_false_false | ||
scope: cursor | ||
auxiliary: | ||
- id: java_lang_cookie_with_http_only_false_false | ||
patterns: | ||
- "false;" | ||
languages: | ||
- java | ||
metadata: | ||
description: "Missing secure options for cookie detected." | ||
remediation_message: | | ||
## Description | ||
To make sure cookies don't open your application up to exploits or unauthorized access, make sure to set security options appropriately. | ||
## Remediations | ||
✅ Set `HttpOnly` to `true` to protect the cookie value from being accessed by client side JavaScript | ||
```java | ||
cookie.setHttpOnly(true); | ||
``` | ||
cwe_id: | ||
- 1004 | ||
id: java_lang_cookie_with_http_only_false | ||
documentation_url: https://docs.bearer.com/reference/rules/java_lang_cookie_with_http_only_false | ||
cloud_code_suggestions: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const { | ||
createNewInvoker, | ||
getEnvironment, | ||
} = require("../../../helper.js") | ||
const { ruleId, ruleFile, testBase } = getEnvironment(__dirname) | ||
|
||
describe(ruleId, () => { | ||
const invoke = createNewInvoker(ruleId, ruleFile, testBase) | ||
|
||
test("cookie_with_http_only_false", () => { | ||
const testCase = "main.java" | ||
|
||
const results = invoke(testCase) | ||
|
||
expect(results.Missing).toEqual([]) | ||
expect(results.Extra).toEqual([]) | ||
}) | ||
}) |
29 changes: 29 additions & 0 deletions
29
tests/java/lang/cookie_with_http_only_false/testdata/main.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import javax.servlet.http.Cookie; | ||
|
||
public class Foo | ||
{ | ||
public void cookie() | ||
{ | ||
Cookie c1 = new Cookie("c1", "foo"); | ||
// bearer:expected java_lang_cookie_with_http_only_false | ||
c1.setHttpOnly(false); | ||
|
||
boolean f = false; | ||
javax.servlet.http.Cookie c2 = new javax.servlet.http.Cookie("c2", "bar"); | ||
// bearer:expected java_lang_cookie_with_http_only_false | ||
c2.setHttpOnly(f); | ||
} | ||
} | ||
|
||
public class Bar | ||
{ | ||
public void cookie() | ||
{ | ||
Cookie c1 = new Cookie("c1", "foo"); | ||
c1.setSecure(true); | ||
c1.setHttpOnly(true); | ||
|
||
Cookie c2 = new Cookie("c2", "bar"); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters