-
Notifications
You must be signed in to change notification settings - Fork 8
Add security static analysis rules for C, Java, and Swift #129
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
ganeshpatro321
merged 13 commits into
coderabbitai:main
from
ESS-ENN:drivermanager-insecurebio-sizeofthis-c
Jan 16, 2025
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
bb7b8e1
removed missing-secure-java
308e947
Merge branch 'coderabbitai:main' into main
ESS-ENN 46efd55
Merge branch 'coderabbitai:main' into main
ESS-ENN 3ac0204
Merge branch 'coderabbitai:main' into main
ESS-ENN 7caba92
Merge branch 'coderabbitai:main' into main
ESS-ENN d3a2776
Merge branch 'coderabbitai:main' into main
ESS-ENN 2e86380
Merge branch 'coderabbitai:main' into main
ESS-ENN 1d44bb5
drivermanager-hardcoded-secret-java
ESS-ENN 2494a83
insecure-biometrics-swift
ESS-ENN a4c389e
sizeof-this-c
ESS-ENN 4d28568
Modifications in insecure-biometrics-swift
ESS-ENN 5333f10
Modifications in sizeof-this-c
ESS-ENN dcaad7e
Removing drivermanager-hardcoded-secret
ESS-ENN 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,131 @@ | ||
id: sizeof-this-c | ||
language: c | ||
severity: warning | ||
message: >- | ||
Do not use `sizeof(this)` to get the number of bytes of the object in | ||
memory. It returns the size of the pointer, not the size of the object. | ||
note: >- | ||
[CWE-467]: Use of sizeof() on a Pointer Type | ||
[REFERENCES] | ||
- https://wiki.sei.cmu.edu/confluence/display/c/ARR01-C.+Do+not+apply+the+sizeof+operator+to+a+pointer+when+taking+the+size+of+an+array | ||
|
||
rule: | ||
not: | ||
has: | ||
stopBy: end | ||
any: | ||
- kind: ERROR | ||
- kind: pointer_expression | ||
- kind: sizeof_expression | ||
- kind: expression_statement | ||
any: | ||
- kind: macro_type_specifier | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: identifier | ||
nthChild: 1 | ||
regex: ^sizeof$ | ||
- has: | ||
stopBy: end | ||
kind: type_descriptor | ||
nthChild: 2 | ||
not: | ||
has: | ||
nthChild: 2 | ||
has: | ||
kind: type_identifier | ||
pattern: $THIS | ||
- not: | ||
has: | ||
kind: function_declarator | ||
nthChild: 1 | ||
|
||
- kind: function_declarator | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: field_identifier | ||
regex: ^sizeof$ | ||
nthChild: 1 | ||
- has: | ||
stopBy: end | ||
kind: parameter_list | ||
nthChild: 2 | ||
not: | ||
has: | ||
nthChild: 2 | ||
has: | ||
kind: parameter_declaration | ||
pattern: $THIS | ||
- not: | ||
has: | ||
kind: function_declarator | ||
nthChild: 1 | ||
# - not: | ||
# inside: | ||
# has: | ||
# nthChild: 1 | ||
|
||
- kind: parameter_declaration | ||
all: | ||
- has: | ||
kind: type_identifier | ||
nthChild: 1 | ||
regex: ^sizeof$ | ||
- any: | ||
- has: | ||
kind: abstract_function_declarator | ||
has: | ||
kind: parameter_list | ||
not: | ||
has: | ||
nthChild: 2 | ||
has: | ||
kind: parameter_declaration | ||
pattern: $THIS | ||
- has: | ||
kind: abstract_parenthesized_declarator | ||
not: | ||
has: | ||
stopBy: end | ||
nthChild: 2 | ||
has: | ||
stopBy: end | ||
kind: parameter_list | ||
has: | ||
kind: parameter_declaration | ||
pattern: $THIS | ||
|
||
- kind: sizeof_expression | ||
not: | ||
has: | ||
any: | ||
- nthChild: 2 | ||
- kind: parameter_declaration | ||
has: | ||
stopBy: end | ||
kind: identifier | ||
pattern: $THIS | ||
|
||
- kind: type_descriptor | ||
all: | ||
- has: | ||
kind: type_identifier | ||
regex: ^sizeof$ | ||
- has: | ||
stopBy: end | ||
kind: abstract_function_declarator | ||
has: | ||
kind: parameter_list | ||
not: | ||
has: | ||
stopBy: end | ||
nthChild: 2 | ||
has: | ||
kind: parameter_declaration | ||
pattern: $THIS | ||
|
||
constraints: | ||
THIS: | ||
regex: ^this$ |
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,47 @@ | ||
id: insecure-biometrics-swift | ||
language: swift | ||
severity: info | ||
message: >- | ||
The application was observed to leverage biometrics via Local | ||
Authentication, which returns a simple boolean result for authentication. | ||
This design is subject to bypass with runtime tampering tools such as | ||
Frida, Substrate, and others. Although this is limited to rooted | ||
(jailbroken) devices, consider implementing biometric authentication the | ||
reliable way - via Keychain Services. | ||
note: >- | ||
[CWE-305] Authentication Bypass by Primary Weakness | ||
[REFERENCES] | ||
- https://mobile-security.gitbook.io/mobile-security-testing-guide/ios-testing-guide/0x06f-testing-local-authentication | ||
- https://shirazkhan030.medium.com/biometric-authentication-in-ios-6c53c54f17df | ||
|
||
rule: | ||
any: | ||
- kind: navigation_expression | ||
pattern: $X.evaluatePolicy | ||
not: | ||
has: | ||
stopBy: end | ||
kind: tuple_expression | ||
has: | ||
nthChild: 2 | ||
|
||
- kind: navigation_expression | ||
has: | ||
kind: navigation_suffix | ||
regex: \.evaluatePolicy$ | ||
nthChild: | ||
position: 1 | ||
reverse: true | ||
not: | ||
has: | ||
stopBy: end | ||
kind: tuple_expression | ||
has: | ||
nthChild: 2 | ||
|
||
- pattern: '.evaluatePolicy' | ||
|
||
not: | ||
has: | ||
stopBy: end | ||
kind: ERROR |
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,8 @@ | ||
id: insecure-biometrics-swift | ||
snapshots: | ||
abc.evaluatePolicy(): | ||
labels: | ||
- source: abc.evaluatePolicy | ||
style: primary | ||
start: 0 | ||
end: 18 |
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,2 @@ | ||
id: sizeof-this-c | ||
snapshots: {} |
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 |
---|---|---|
@@ -1,2 +1,13 @@ | ||
id: sizeof-this-cpp | ||
snapshots: {} | ||
snapshots: | ||
? | | ||
return sizeof(this); | ||
: labels: | ||
- source: sizeof(this) | ||
style: primary | ||
start: 7 | ||
end: 19 | ||
- source: this | ||
style: secondary | ||
start: 14 | ||
end: 18 |
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,12 @@ | ||
id: sizeof-this-c | ||
valid: | ||
- | | ||
sizeof(*this); | ||
invalid: | ||
- | | ||
struct Foo { | ||
uint64_t a; | ||
uint8_t b; | ||
size_t get_size() const { | ||
return sizeof(this); | ||
} | ||
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,7 @@ | ||
id: insecure-biometrics-swift | ||
valid: | ||
- | | ||
abc.anyFunc() | ||
invalid: | ||
- | | ||
abc.evaluatePolicy() |
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.