Skip to content

Add YAML security rules for DocumentBuilderFactory external entities #163

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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bb7b8e1
removed missing-secure-java
Dec 16, 2024
308e947
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 6, 2025
46efd55
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 8, 2025
3ac0204
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 8, 2025
7caba92
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 9, 2025
d3a2776
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 10, 2025
2e86380
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 14, 2025
b072db7
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 20, 2025
65dce29
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 22, 2025
12bb3aa
httponly-false-csharp
ESS-ENN Jan 22, 2025
2c5ea88
use-of-md5-digest-utils-java
ESS-ENN Jan 22, 2025
d3067f1
removing use-of-md5-digest-utils and httponly-false-csharp
ESS-ENN Jan 22, 2025
56d4011
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 28, 2025
f7f1d72
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 29, 2025
0d53f8e
Merge branch 'coderabbitai:main' into main
ESS-ENN Feb 4, 2025
b622bca
Merge branch 'coderabbitai:main' into main
ESS-ENN Feb 6, 2025
67459bf
Merge branch 'coderabbitai:main' into main
ESS-ENN Feb 7, 2025
b8b2adb
Merge branch 'coderabbitai:main' into main
ESS-ENN Feb 18, 2025
9b29d0a
Merge branch 'coderabbitai:main' into main
ESS-ENN Mar 3, 2025
24510d4
Merge branch 'coderabbitai:main' into main
ESS-ENN Mar 4, 2025
6c6d229
Merge remote-tracking branch 'upstream/main' into main
ESS-ENN Mar 4, 2025
c5f0d85
Merge branch 'main' of https://github.com/ESS-ENN/ast-grep-essentials…
ESS-ENN Mar 4, 2025
75f81c4
documentbuilderfactory-external-parameter-entities-true-java
ESS-ENN Mar 4, 2025
9493a1a
documentbuilderfactory-external-general-entities-true-java
ESS-ENN Mar 4, 2025
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,288 @@
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

ast-grep-essentials: true

utils:
match_expression_statement:
kind: method_invocation
all:
- has:
stopBy: neighbor
kind: identifier
- has:
stopBy: neighbor
kind: identifier
regex: ^setFeature$
nthChild: 2
- has:
stopBy: end
kind: argument_list
all:
- has:
stopBy: neighbor
kind: string_literal
regex: ^"http://xml.org/sax/features/external-general-entities"$
nthChild:
position: 1
ofRule:
not:
kind: line_comment
- has:
stopBy: neighbor
regex: "^true$"
nthChild:
position: 2
ofRule:
not:
kind: line_comment

match_expression_statement_Boolean_Instance:
kind: expression_statement
has:
stopBy: end
kind: method_invocation
all:
- has:
stopBy: neighbor
kind: identifier
- has:
stopBy: neighbor
kind: identifier
regex: ^setFeature$
nthChild: 2
has:
stopBy: end
kind: argument_list
field: arguments
all:
- has:
stopBy: neighbor
kind: string_literal
regex: ^"http://xml.org/sax/features/external-general-entities"$
nthChild:
position: 1
ofRule:
not:
kind: line_comment
- has:
stopBy: neighbor
pattern: $TRUE
nthChild:
position: 2
ofRule:
not:
kind: line_comment
any:
- inside:
stopBy: end
follows:
stopBy: end
kind: local_variable_declaration
has:
kind: variable_declarator
all:
- has:
kind: identifier
pattern: $TRUE
nthChild: 1
- has:
regex: "^true$"
- follows:
stopBy: end
kind: local_variable_declaration
has:
kind: variable_declarator
all:
- has:
kind: identifier
pattern: $TRUE
nthChild: 1
- has:
regex: "^true$"

match_expression_statement_Link_Instance:
kind: expression_statement
has:
stopBy: end
kind: method_invocation
all:
- has:
stopBy: neighbor
kind: identifier
nthChild: 1
- has:
stopBy: neighbor
kind: identifier
regex: ^setFeature$
nthChild: 2
has:
stopBy: end
kind: argument_list
field: arguments
all:
- has:
stopBy: neighbor
pattern: $URL
nthChild:
position: 1
ofRule:
not:
kind: line_comment
- has:
stopBy: neighbor
regex: "^true$"
nthChild:
position: 2
ofRule:
not:
kind: line_comment
any:
- inside:
stopBy: end
follows:
stopBy: end
kind: local_variable_declaration
has:
kind: variable_declarator
all:
- has:
kind: identifier
pattern: $URL
nthChild: 1
- has:
kind: string_literal
regex: ^"http://xml.org/sax/features/external-general-entities"$
- follows:
stopBy: end
kind: local_variable_declaration
has:
kind: variable_declarator
all:
- has:
kind: identifier
pattern: $URL
nthChild: 1
- has:
kind: string_literal
regex: ^"http://xml.org/sax/features/external-general-entities"$

match_expression_statement_with_both_instance:
kind: expression_statement
has:
stopBy: end
kind: method_invocation
all:
- has:
stopBy: neighbor
kind: identifier
- has:
stopBy: neighbor
kind: identifier
regex: ^setFeature$
nthChild: 2
- has:
kind: argument_list
all:
- not:
has:
nthChild:
position: 3
ofRule:
not:
kind: line_comment
- has:
kind: identifier
pattern: $URL
nthChild:
position: 1
ofRule:
not:
kind: line_comment
- has:
kind: identifier
pattern: $TRUE
nthChild:
position: 2
ofRule:
not:
kind: line_comment
- any:
- follows:
stopBy: end
kind: local_variable_declaration
has:
kind: variable_declarator
all:
- has:
kind: identifier
pattern: $TRUE
nthChild: 1
- has:
regex: "^true$"
- inside:
stopBy: end
follows:
stopBy: end
kind: local_variable_declaration
has:
kind: variable_declarator
all:
- has:
kind: identifier
pattern: $TRUE
nthChild: 1
- has:
regex: "^true$"
- any:
- follows:
stopBy: end
kind: local_variable_declaration
has:
kind: variable_declarator
all:
- has:
kind: identifier
pattern: $URL
nthChild: 1
- has:
regex: ^"http://xml.org/sax/features/external-general-entities"$
- inside:
stopBy: end
follows:
stopBy: end
kind: local_variable_declaration
has:
kind: variable_declarator
all:
- has:
kind: identifier
pattern: $URL
nthChild: 1
- has:
regex: ^"http://xml.org/sax/features/external-general-entities"$

rule:
any:
- matches: match_expression_statement
- matches: match_expression_statement_Boolean_Instance
- matches: match_expression_statement_Link_Instance
- matches: match_expression_statement_with_both_instance
not:
all:
- has:
stopBy: end
kind: ERROR
- inside:
stopBy: end
kind: ERROR
Loading