-
Notifications
You must be signed in to change notification settings - Fork 6
Rules - file-stat-before-action c/cpp #27
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
petrisorcoderabbit
merged 5 commits into
coderabbitai:main
from
ESS-ENN:file-stat-before-action-c/cpp
Oct 21, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
838c1db
changes in file-access-before-action in cpp
ESS-ENN 494c0a6
file-stat-before-action-c/cpp
ESS-ENN 7abb5d5
changes in file-stat-before-action-c/cpp
ESS-ENN 3e059eb
Merge branch 'main' into file-stat-before-action-c/cpp
ESS-ENN 3176e5f
Merge branch 'main' into file-stat-before-action-c/cpp
petrisorcoderabbit 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,82 @@ | ||
id: file-stat-before-action-c | ||
language: c | ||
severity: warning | ||
message: >- | ||
A check is done with `stat` and then the file is used. There is no | ||
guarantee that the status of the file has not changed since the call to | ||
`stat` which may allow attackers to bypass permission checks. | ||
note: >- | ||
[CWE-367]: Time-of-check Time-of-use (TOCTOU) Race Condition | ||
[REFERENCES] | ||
- https://wiki.sei.cmu.edu/confluence/display/c/FIO45-C.+Avoid+TOCTOU+race+conditions+while+accessing+files | ||
utils: | ||
match_fopen_identifier: | ||
kind: identifier | ||
regex: unlink|fopen|freopen|remove|rename|access|open|stat|lstat|unlink|mkdir|rmdir|chdir|folly::readFile|folly::writeFile|folly::writeFileAtomic|folly::writeFileAtomicNoThrow|folly::File | ||
all: | ||
- inside: | ||
kind: call_expression | ||
inside: | ||
stopBy: end | ||
kind: expression_statement | ||
inside: | ||
kind: compound_statement | ||
inside: | ||
kind: if_statement | ||
has: | ||
stopBy: end | ||
kind: call_expression | ||
all: | ||
- has: | ||
kind: identifier | ||
regex: ^(fstatat|_fstatat)$ | ||
- has: | ||
stopBy: neighbor | ||
kind: argument_list | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: identifier | ||
- has: | ||
stopBy: neighbor | ||
kind: call_expression | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: field_expression | ||
- has: | ||
stopBy: neighbor | ||
kind: argument_list | ||
|
||
match_fopen_identifier_2: | ||
kind: identifier | ||
regex: unlink|fopen|freopen|remove|rename|access|open|stat|lstat|unlink|mkdir|rmdir|chdir|folly::readFile|folly::writeFile|folly::writeFileAtomic|folly::writeFileAtomicNoThrow|folly::File | ||
all: | ||
- inside: | ||
kind: call_expression | ||
inside: | ||
stopBy: end | ||
kind: expression_statement | ||
inside: | ||
kind: compound_statement | ||
inside: | ||
kind: if_statement | ||
has: | ||
stopBy: end | ||
kind: call_expression | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: identifier | ||
regex: "^stat|_stat|lstat|_lstat$" | ||
- has: | ||
stopBy: neighbor | ||
kind: argument_list | ||
has: | ||
stopBy: neighbor | ||
kind: call_expression | ||
|
||
rule: | ||
any: | ||
- matches: match_fopen_identifier | ||
- matches: match_fopen_identifier_2 |
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,82 @@ | ||
id: file-stat-before-action-cpp | ||
language: cpp | ||
severity: warning | ||
message: >- | ||
A check is done with `stat` and then the file is used. There is no | ||
guarantee that the status of the file has not changed since the call to | ||
`stat` which may allow attackers to bypass permission checks. | ||
note: >- | ||
[CWE-367]: Time-of-check Time-of-use (TOCTOU) Race Condition | ||
[REFERENCES] | ||
- https://wiki.sei.cmu.edu/confluence/display/c/FIO45-C.+Avoid+TOCTOU+race+conditions+while+accessing+files | ||
utils: | ||
match_fopen_identifier: | ||
kind: identifier | ||
regex: unlink|fopen|freopen|remove|rename|access|open|stat|lstat|unlink|mkdir|rmdir|chdir|folly::readFile|folly::writeFile|folly::writeFileAtomic|folly::writeFileAtomicNoThrow|folly::File | ||
all: | ||
- inside: | ||
kind: call_expression | ||
inside: | ||
stopBy: end | ||
kind: expression_statement | ||
inside: | ||
kind: compound_statement | ||
inside: | ||
kind: if_statement | ||
has: | ||
stopBy: end | ||
kind: call_expression | ||
all: | ||
- has: | ||
kind: identifier | ||
regex: ^(fstatat|_fstatat)$ | ||
- has: | ||
stopBy: neighbor | ||
kind: argument_list | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: identifier | ||
- has: | ||
stopBy: neighbor | ||
kind: call_expression | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: field_expression | ||
- has: | ||
stopBy: neighbor | ||
kind: argument_list | ||
|
||
match_fopen_identifier_2: | ||
kind: identifier | ||
regex: unlink|fopen|freopen|remove|rename|access|open|stat|lstat|unlink|mkdir|rmdir|chdir|folly::readFile|folly::writeFile|folly::writeFileAtomic|folly::writeFileAtomicNoThrow|folly::File | ||
all: | ||
- inside: | ||
kind: call_expression | ||
inside: | ||
stopBy: end | ||
kind: expression_statement | ||
inside: | ||
kind: compound_statement | ||
inside: | ||
kind: if_statement | ||
has: | ||
stopBy: end | ||
kind: call_expression | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: identifier | ||
regex: "^stat|_stat|lstat|_lstat$" | ||
- has: | ||
stopBy: neighbor | ||
kind: argument_list | ||
has: | ||
stopBy: neighbor | ||
kind: call_expression | ||
|
||
rule: | ||
any: | ||
- matches: match_fopen_identifier | ||
- matches: match_fopen_identifier_2 |
Oops, something went wrong.
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.