-
Notifications
You must be signed in to change notification settings - Fork 9
Two Java rules #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Two Java rules #14
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,83 @@ | ||
id: missing-httponly-java | ||
language: java | ||
severity: warning | ||
message: >- | ||
Detected a cookie where the `HttpOnly` flag is either missing or | ||
disabled. The `HttpOnly` cookie flag instructs the browser to forbid | ||
client-side JavaScript to read the cookie. If JavaScript interaction is | ||
required, you can ignore this finding. However, set the `HttpOnly` flag to | ||
true` in all other cases. | ||
note: >- | ||
[CWE-1004]: Sensitive Cookie Without 'HttpOnly' Flag | ||
[OWASP A05:2021]: Security Misconfiguration | ||
[REFERENCES] | ||
- https://owasp.org/Top10/A05_2021-Security_Misconfiguration | ||
utils: | ||
match_without_httponly: | ||
kind: argument_list | ||
has: | ||
kind: object_creation_expression | ||
inside: | ||
stopBy: end | ||
kind: method_invocation | ||
|
||
match_cc2_cookie: | ||
kind: local_variable_declaration | ||
precedes: | ||
kind: expression_statement | ||
has: | ||
kind: method_invocation | ||
has: | ||
kind: method_invocation | ||
has: | ||
kind: argument_list | ||
has: | ||
kind: string_literal | ||
match_nettycookie: | ||
kind: local_variable_declaration | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: variable_declarator | ||
has: | ||
kind: object_creation_expression | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: argument_list | ||
has: | ||
stopBy: end | ||
kind: string_literal | ||
precedes: | ||
stopBy: end | ||
kind: string_literal | ||
- not: | ||
precedes: | ||
stopBy: end | ||
kind: identifier | ||
regex: "http" | ||
- not: | ||
precedes: | ||
stopBy: neighbor | ||
kind: expression_statement | ||
has: | ||
stopBy: end | ||
kind: method_invocation | ||
has: | ||
stopBy: end | ||
kind: argument_list | ||
match_cookie_last: | ||
kind: argument_list | ||
has: | ||
kind: method_invocation | ||
has: | ||
kind: argument_list | ||
has: | ||
kind: string_literal | ||
|
||
rule: | ||
any: | ||
- matches: match_cc2_cookie | ||
- matches: match_without_httponly | ||
- matches: match_nettycookie | ||
- matches: match_cookie_last | ||
ESS-ENN marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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,70 @@ | ||
id: missing-secure-java | ||
language: java | ||
severity: warning | ||
message: >- | ||
Detected a cookie where the `Secure` flag is either missing or | ||
disabled. The `Secure` cookie flag instructs the browser to forbid sending | ||
the cookie over an insecure HTTP request. Set the `Secure` flag to `true` | ||
so the cookie will only be sent over HTTPS. | ||
note: >- | ||
[CWE-614]: Sensitive Cookie in HTTPS Session Without 'Secure' Attribute | ||
[OWASP A05:2021]: Security Misconfiguration | ||
[REFERENCES] | ||
- https://owasp.org/Top10/A05_2021-Security_Misconfiguration | ||
utils: | ||
match_without_httponly: | ||
kind: argument_list | ||
has: | ||
kind: object_creation_expression | ||
inside: | ||
stopBy: end | ||
kind: method_invocation | ||
|
||
match_cookie_last: | ||
kind: argument_list | ||
has: | ||
kind: method_invocation | ||
has: | ||
kind: argument_list | ||
has: | ||
kind: string_literal | ||
|
||
match_instance: | ||
kind: local_variable_declaration | ||
has: | ||
stopBy: end | ||
kind: identifier | ||
follows: | ||
stopBy: end | ||
kind: variable_declarator | ||
|
||
match_identifier_with_simplecookie: | ||
kind: identifier | ||
inside: | ||
stopBy: end | ||
kind: local_variable_declaration | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: type_identifier | ||
regex: "^SimpleCookie$|^Cookie$" | ||
- has: | ||
stopBy: neighbor | ||
kind: variable_declarator | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: identifier | ||
- has: | ||
stopBy: neighbor | ||
kind: object_creation_expression | ||
ESS-ENN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- not: | ||
precedes: | ||
stopBy: neighbor | ||
kind: expression_statement | ||
rule: | ||
any: | ||
- matches: match_instance | ||
- matches: match_without_httponly | ||
- matches: match_cookie_last | ||
- matches: match_identifier_with_simplecookie | ||
ESS-ENN marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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,33 @@ | ||
id: missing-httponly-java | ||
snapshots: | ||
? | | ||
SimpleCookie s = new SimpleCookie("foo", "bar"); | ||
( new NettyCookie( "foo", "bar" ) ) | ||
Cookie cc2 = Cookie.of("zzz", "ddd"); | ||
Cookie z = new NettyCookie("foo", "bar"); | ||
(Cookie.of("zzz", "ddd")) | ||
ESS-ENN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
: labels: | ||
- source: SimpleCookie s = new SimpleCookie("foo", "bar"); | ||
style: primary | ||
start: 0 | ||
end: 48 | ||
- source: '"foo"' | ||
style: secondary | ||
start: 34 | ||
end: 39 | ||
- source: '"foo"' | ||
style: secondary | ||
start: 34 | ||
end: 39 | ||
- source: ("foo", "bar") | ||
style: secondary | ||
start: 33 | ||
end: 47 | ||
- source: new SimpleCookie("foo", "bar") | ||
style: secondary | ||
start: 17 | ||
end: 47 | ||
- source: s = new SimpleCookie("foo", "bar") | ||
style: secondary | ||
start: 13 | ||
end: 47 | ||
ESS-ENN marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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,32 @@ | ||
id: missing-secure-java | ||
snapshots: | ||
? | | ||
SimpleCookie s = new SimpleCookie("foo", "bar"); | ||
.orElse( new NettyCookie( "foo", "bar" ) ); | ||
Cookie z = new NettyCookie("foo", "bar"); | ||
return HttpResponse.ok().cookie(Cookie.of("zzz", "ddd")); | ||
: labels: | ||
- source: s | ||
style: primary | ||
start: 13 | ||
end: 14 | ||
- source: SimpleCookie | ||
style: secondary | ||
start: 0 | ||
end: 12 | ||
- source: s | ||
style: secondary | ||
start: 13 | ||
end: 14 | ||
- source: new SimpleCookie("foo", "bar") | ||
style: secondary | ||
start: 17 | ||
end: 47 | ||
- source: s = new SimpleCookie("foo", "bar") | ||
style: secondary | ||
start: 13 | ||
end: 47 | ||
- source: SimpleCookie s = new SimpleCookie("foo", "bar"); | ||
style: secondary | ||
start: 0 | ||
end: 48 |
This file contains hidden or 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 @@ | ||
id: missing-httponly-java | ||
valid: | ||
- | | ||
Cookie c1 = getCookieSomewhere(); | ||
return HttpResponse.ok().cookie(Cookie.of("foo", "bar").httpOnly(true)); | ||
Cookie cookie = request.getCookies().findCookie( "foobar" ) | ||
Cookie ccc = Cookie.of("zzz", "ddd"); | ||
ccc.httpOnly(true).secure(true); | ||
Cookie c = new NettyCookie("foo", "bar"); | ||
c.httpOnly(true); | ||
NettyCookie r = new NettyCookie("foo", "bar").httpOnly(true); | ||
invalid: | ||
- | | ||
SimpleCookie s = new SimpleCookie("foo", "bar"); | ||
( new NettyCookie( "foo", "bar" ) ) | ||
Cookie cc2 = Cookie.of("zzz", "ddd"); | ||
Cookie z = new NettyCookie("foo", "bar"); | ||
(Cookie.of("zzz", "ddd")) |
This file contains hidden or 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,15 @@ | ||
id: missing-secure-java | ||
valid: | ||
- | | ||
Cookie c1 = getCookieSomewhere(); | ||
return HttpResponse.ok().cookie(Cookie.of("foo", "bar").secure(true)); | ||
Cookie cookie = request.getCookies().findCookie( "foobar" ) | ||
Cookie c = new NettyCookie("foo", "bar"); | ||
c.secure(true); | ||
NettyCookie r = new NettyCookie("foo", "bar").secure(true); | ||
invalid: | ||
- | | ||
SimpleCookie s = new SimpleCookie("foo", "bar"); | ||
.orElse( new NettyCookie( "foo", "bar" ) ); | ||
Cookie z = new NettyCookie("foo", "bar"); | ||
return HttpResponse.ok().cookie(Cookie.of("zzz", "ddd")); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.