Skip to content

Add YAML rules for insecure C/C++ hash detection and XML parsing audit #162

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
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
e9c5b1d
insecure-hash-c
ESS-ENN Mar 3, 2025
a166001
libxml2-audit-parser-c
ESS-ENN Mar 3, 2025
f7fb1b1
Added test file for dont-call-system-c
ESS-ENN Mar 3, 2025
f3a3bd7
insecure-hash-cpp
ESS-ENN Mar 3, 2025
020e923
libxml2-audit-parser-cpp
ESS-ENN Mar 3, 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
293 changes: 293 additions & 0 deletions rules/c/security/insecure-hash-c.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,293 @@
id: insecure-hash-c
language: c
severity: warning
message: >-
This hashing algorithm is insecure. If this hash is used in a security
context, such as password hashing, it should be converted to a stronger
hashing algorithm.
note: >-
[CWE-328] Use of Weak Hash.
[REFERENCES]
- https://owasp.org/Top10/A02_2021-Cryptographic_Failures
ast-grep-essentials: true
utils:
MATCH_PATTERN_ONE:
kind: expression_statement
has:
stopBy: neighbor
kind: call_expression
all:
- has:
stopBy: neighbor
kind: identifier
regex: ^(EVP_md2|MD2|MD2_Final|MD2_Init|MD2_Update|MD2_options|EVP_md4|MD4|MD4_Final|MD4_Init|MD4_Transform|MD4_Update|EVP_md5|MD5|MD5_Final|MD5_Init|MD5_Transform|MD5_Update|EVP_sha1|SHA1_Final|SHA1_Init|SHA1_Transform|SHA1_Update)$
- has:
stopBy: neighbor
kind: argument_list

MATCH_PATTERN_TWO_(EVP_MD_fetch):
kind: expression_statement
has:
stopBy: neighbor
kind: call_expression
all:
- has:
stopBy: neighbor
kind: identifier
regex: ^(EVP_MD_fetch)$
- has:
stopBy: neighbor
kind: argument_list
has:
kind: string_literal
all:
- nthChild:
position: 2
ofRule:
not:
kind: comment
- has:
kind: string_content
regex: ^(MD2|MD4|MD5|SHA1|SHA-1)$

MATCH_PATTERN_TWO_with_instance_(EVP_MD_fetch):
kind: expression_statement
all:
- has:
stopBy: neighbor
kind: call_expression
all:
- has:
stopBy: neighbor
kind: identifier
regex: "^(EVP_MD_fetch)$"
- has:
stopBy: neighbor
kind: argument_list
has:
stopBy: neighbor
kind: identifier
pattern: $Q
nthChild:
position: 2
ofRule:
not:
kind: comment
- any:
- follows:
stopBy: end
kind: declaration
has:
stopBy: end
kind: init_declarator
all:
- has:
stopBy: neighbor
kind: pointer_declarator
has:
stopBy: neighbor
kind: identifier
pattern: $Q
- has:
stopBy: neighbor
kind: string_literal
has:
stopBy: neighbor
kind: string_content
regex: ^(MD2|MD4|MD5|SHA1|SHA-1)$
- inside:
stopBy: end
follows:
stopBy: end
kind: declaration
has:
stopBy: end
kind: init_declarator
all:
- has:
stopBy: neighbor
kind: pointer_declarator
has:
stopBy: neighbor
kind: identifier
pattern: $Q
- has:
stopBy: neighbor
kind: string_literal
has:
stopBy: neighbor
kind: string_content
regex: ^(MD2|MD4|MD5|SHA1|SHA-1)$

MATCH_PATTERN_THREE:
kind: expression_statement
has:
stopBy: neighbor
kind: call_expression
all:
- has:
stopBy: neighbor
kind: identifier
regex: ^(gcry_md_open|gcry_md_enable|gcry_md_read|gcry_md_extract)$
- has:
stopBy: neighbor
kind: argument_list
has:
stopBy: end
kind: identifier
regex: ^(GCRY_MD_MD2|GCRY_MD_MD4|GCRY_MD_MD5|GCRY_MD_SHA1)$
nthChild:
position: 2
ofRule:
not:
kind: comment

MATCH_PATTERN_TWO_(EVP_get_digestbyname):
kind: expression_statement
has:
stopBy: neighbor
kind: call_expression
all:
- has:
stopBy: neighbor
kind: identifier
regex: ^(EVP_get_digestbyname)$
- has:
stopBy: neighbor
kind: argument_list
has:
kind: string_literal
all:
- nthChild:
position: 1
ofRule:
not:
kind: comment
- has:
kind: string_content
regex: ^(MD2|MD4|MD5|SHA1|SHA-1)$
not:
has:
nthChild:
position: 2
ofRule:
not:
kind: comment

MATCH_PATTERN_TWO_with_instance_(EVP_get_digestbyname):
kind: expression_statement
all:
- has:
stopBy: neighbor
kind: call_expression
all:
- has:
stopBy: neighbor
kind: identifier
regex: "^(EVP_get_digestbyname)$"
- has:
stopBy: neighbor
kind: argument_list
has:
stopBy: neighbor
kind: identifier
pattern: $Q
nthChild:
position: 1
ofRule:
not:
kind: comment
not:
has:
nthChild:
position: 2
ofRule:
not:
kind: comment
- any:
- follows:
stopBy: end
kind: declaration
has:
stopBy: end
kind: init_declarator
all:
- has:
stopBy: neighbor
kind: pointer_declarator
has:
stopBy: neighbor
kind: identifier
pattern: $Q
- has:
stopBy: neighbor
kind: string_literal
has:
stopBy: neighbor
kind: string_content
regex: ^(MD2|MD4|MD5|SHA1|SHA-1)$
- inside:
stopBy: end
follows:
stopBy: end
kind: declaration
has:
stopBy: end
kind: init_declarator
all:
- has:
stopBy: neighbor
kind: pointer_declarator
has:
stopBy: neighbor
kind: identifier
pattern: $Q
- has:
stopBy: neighbor
kind: string_literal
has:
stopBy: neighbor
kind: string_content
regex: ^(MD2|MD4|MD5|SHA1|SHA-1)$

MATCH_PATTERN_THREE_(gcry_md_hash_buffers):
kind: expression_statement
has:
stopBy: neighbor
kind: call_expression
all:
- has:
stopBy: neighbor
kind: identifier
regex: ^(gcry_md_hash_buffers|gcry_md_hash_buffer)$
- has:
stopBy: neighbor
kind: argument_list
has:
stopBy: end
kind: identifier
regex: ^(GCRY_MD_MD2|GCRY_MD_MD4|GCRY_MD_MD5|GCRY_MD_SHA1)$
nthChild:
position: 1
ofRule:
not:
kind: comment
rule:
any:
- kind: expression_statement
any:
- matches: MATCH_PATTERN_ONE
- matches: MATCH_PATTERN_TWO_(EVP_MD_fetch)
- matches: MATCH_PATTERN_TWO_with_instance_(EVP_MD_fetch)
- matches: MATCH_PATTERN_THREE
- matches: MATCH_PATTERN_TWO_(EVP_get_digestbyname)
- matches: MATCH_PATTERN_TWO_with_instance_(EVP_get_digestbyname)
- matches: MATCH_PATTERN_THREE_(gcry_md_hash_buffers)
not:
all:
- has:
stopBy: end
kind: ERROR
- inside:
stopBy: end
kind: ERROR
Loading