Skip to content

Update ast-grep CLI & add Java cookie management rules #7

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 3 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 32 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@ast-grep/cli": "^0.20.2"
"@ast-grep/cli": "^0.26.0"
}
}
}
14 changes: 14 additions & 0 deletions rules/java/security/cookie-secure-flag-false-java.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
id: cookie-secure-flag-false-java
language: java
severity: warning
message: >-
A cookie was detected without setting the 'secure' flag. The 'secure'
flag for cookies prevents the client from transmitting the cookie over
insecure channels such as HTTP. Set the 'secure' flag by calling
'$COOKIE.setSecure(true);'.
note: >-
[CWE-614] Sensitive Cookie in HTTPS Session Without 'Secure' Attribute.
[REFERENCES]
- https://owasp.org/www-community/controls/SecureCookieAttribute
rule:
pattern: $COOKIE.setSecure(false);
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
id: documentbuilderfactory-external-general-entities-true-java
language: java
severity: warning
message: >-
External entities are allowed for $DBFACTORY. This is vulnerable to XML
external entity attacks. Disable this by setting the feature
"http://xml.org/sax/features/external-general-entities" to false.
note: >-
[CWE-798]: Use of Hard-coded Credentials
[OWASP A07:2021]: Identification and Authentication Failures
[REFERENCES]
- https://blog.sonarsource.com/secure-xml-processor
rule:
pattern:
$DBFACTORY.setFeature("http://xml.org/sax/features/external-general-entities",
true);
13 changes: 13 additions & 0 deletions rules/java/security/use-of-rc2-java.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
id: use-of-rc2-java
language: java
severity: warning
message: >-
Use of RC2 was detected. RC2 is vulnerable to related-key attacks, and
is therefore considered non-compliant. Instead, use a strong, secure.
note: >-
[CWE-327] Use of a Broken or Risky Cryptographic Algorithm.
[REFERENCES]
- https://owasp.org/Top10/A02_2021-Cryptographic_Failures
- https://googleprojectzero.blogspot.com/2022/10/rc4-is-still-considered-harmful.html
rule:
pattern: $CIPHER.getInstance("RC2")
5 changes: 1 addition & 4 deletions rules/scala/security/xmlinputfactory-dtd-enabled-scala.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,4 @@ rule:
- pattern: new XMLInputFactory($$$)
precedes:
not:
pattern: $XMLFACTORY.setProperty($MODE, false)
constraints:
MODE:
regex: "javax.xml.stream.isSupportingExternalEntities"
pattern: $XMLFACTORY.setProperty(javax.xml.stream.isSupportingExternalEntities, false)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
id: cookie-secure-flag-false-java
snapshots:
? |
cookie.setSecure(false);
: labels:
- source: cookie.setSecure(false);
style: primary
start: 0
end: 24
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
id: documentbuilderfactory-external-general-entities-true-java
snapshots:
? |
dbf.setFeature("http://xml.org/sax/features/external-general-entities" , true);
spf.setFeature("http://xml.org/sax/features/external-general-entities" , true);
: labels:
- source: dbf.setFeature("http://xml.org/sax/features/external-general-entities" , true);
style: primary
start: 0
end: 79
10 changes: 10 additions & 0 deletions tests/__snapshots__/use-of-rc2-java-snapshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
id: use-of-rc2-java
snapshots:
? |
useCipher(Cipher.getInstance("RC2"));
Cipher.getInstance("RC2");
: labels:
- source: Cipher.getInstance("RC2")
style: primary
start: 10
end: 35
10 changes: 10 additions & 0 deletions tests/java/cookie-secure-flag-false-java-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
id: cookie-secure-flag-false-java
valid:
- |
response.addCookie(cookie);
cookie.setSecure(true);
cookie.setHttpOnly(true);
response.addCookie(cookie);
invalid:
- |
cookie.setSecure(false);
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
id: documentbuilderfactory-external-general-entities-true-java
valid:
- |
dbf.setFeature("http://xml.org/sax/features/external-general-entities" , false);
spf.setFeature("http://xml.org/sax/features/external-general-entities" , false);
invalid:
- |
dbf.setFeature("http://xml.org/sax/features/external-general-entities" , true);
spf.setFeature("http://xml.org/sax/features/external-general-entities" , true);
8 changes: 8 additions & 0 deletions tests/java/use-of-rc2-java-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
id: use-of-rc2-java
valid:
- |
Cipher.getInstance("AES/CBC/PKCS7PADDING");
invalid:
- |
useCipher(Cipher.getInstance("RC2"));
Cipher.getInstance("RC2");