-
Notifications
You must be signed in to change notification settings - Fork 0
Create new rule detect system() in c and cpp files #18
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
Changes from 2 commits
13ee9cc
77e5a6a
05c3f7d
d923b13
de1c94e
fd20a63
d88c333
fc0cf51
34f0a20
6544900
3fb13ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -624,3 +624,27 @@ rules: | |
| confidence: HIGH | ||
| references: | ||
| - https://kubernetes.io/blog/2025/11/11/ingress-nginx-retirement/ | ||
| - id: codacy.c.security.avoid-std-system | ||
| languages: | ||
| - cpp | ||
| - c | ||
| severity: WARNING | ||
| message: > | ||
| Detected a call to the standard `system()` function. This is dangerous | ||
| as it can lead to Command Injection if untrusted input is passed. | ||
| Ensure you are using safe alternatives or properly validating/sanitizing any input used in system calls. | ||
| patterns: | ||
| # Catch standard system calls, whether global or explicitly in std:: | ||
| - pattern-either: | ||
| - pattern: system(...) | ||
| - pattern: std::system(...) | ||
| - pattern: ::system(...) | ||
| # Explicitly ignore calls to your custom namespace | ||
| - pattern-not: osutility::system(...) | ||
|
Comment on lines
+642
to
+643
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The hardcoded exclusion for
Comment on lines
+642
to
+643
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⚪ LOW RISK Suggestion: The Try running the following prompt in your coding agent:
|
||
| metadata: | ||
| category: security | ||
| description: > | ||
| Detects calls to the standard `system()` function which can lead to Command Injection vulnerabilities. | ||
| Ensure safe alternatives or proper input validation/sanitization is used. | ||
| impact: MEDIUM | ||
| confidence: HIGH | ||
|
DMarinhoCodacy marked this conversation as resolved.
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #include <iostream> | ||
| #include <cstdlib> | ||
| #include <string> | ||
| #include <cstdint> | ||
|
|
||
| namespace newNamespace { | ||
| using String_t = std::string; | ||
| } | ||
|
|
||
| namespace osutility { | ||
| // [SHOULD NOT FLAG]: This is a definition. | ||
| std::int32_t system(const newNamespace::String_t& cmd, newNamespace::String_t& output) { | ||
| output = "Executed safely: " + cmd; | ||
| return 0; // Success | ||
| } | ||
| } | ||
|
|
||
| int main() { | ||
| newNamespace::String_t my_cmd = "ls -la"; | ||
| newNamespace::String_t my_out; | ||
|
|
||
| // [SHOULD NOT FLAG]: Custom system function in osutility namespace | ||
| osutility::system(my_cmd, my_out); | ||
|
|
||
| // [SHOULD FLAG]: Standard global system call | ||
| system("echo 'This is dangerous'"); | ||
|
|
||
| // [SHOULD FLAG]: Explicit standard namespace system call | ||
| std::system("echo 'This is also dangerous'"); | ||
|
|
||
| // [SHOULD FLAG]: Explicit global namespace system call | ||
| ::system("echo 'Still dangerous'"); | ||
|
|
||
| return 0; | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.