Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
24 changes: 24 additions & 0 deletions docs/codacy-rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Comment thread
DMarinhoCodacy marked this conversation as resolved.
Outdated
- 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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The hardcoded exclusion for osutility::system(...) appears to be specific to the provided test case. General security rules should avoid including project-specific or arbitrary namespace exclusions in their definition, as this reduces maintainability and portability. If exclusions are necessary, they should be handled through configuration or more generic patterns.

Comment on lines +642 to +643
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚪ LOW RISK

Suggestion: The pattern-not: osutility::system(...) exclusion and its accompanying comment are redundant. The positive patterns defined in the pattern-either block do not match calls qualified with the osutility:: namespace. Removing this simplifies the rule.

Try running the following prompt in your coding agent:

Remove the redundant comment and pattern-not exclusion for osutility::system (lines 642-643) from the rule codacy.c.security.avoid-std-system in docs/codacy-rules.yaml.

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
Comment thread
DMarinhoCodacy marked this conversation as resolved.
5 changes: 5 additions & 0 deletions docs/multiple-tests/codacy-rules/results.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,9 @@
<file name="codacy-shell.sh">
<error source="codacy.bash.security.hard-coded-password" line="1" message="Hardcoded passwords are a security risk." severity="error" />
</file>
<file name="codacy-c-avoid-std-system">
Comment thread
DMarinhoCodacy marked this conversation as resolved.
Outdated
<error source="codacy.c.security.avoid-std-system" line="26" message="Detected a call to the standard `system()` function. This is dangerous as it can lead to Command Injection if untrusted input is passed." severity="warning" />
<error source="codacy.c.security.avoid-std-system" line="29" message="Detected a call to the standard `system()` function. This is dangerous as it can lead to Command Injection if untrusted input is passed." severity="warning" />
<error source="codacy.c.security.avoid-std-system" line="32" message="Detected a call to the standard `system()` function. This is dangerous as it can lead to Command Injection if untrusted input is passed." severity="warning" />
</file>
</checkstyle>
35 changes: 35 additions & 0 deletions docs/multiple-tests/codacy-rules/src/codacy-c-avoid-std-system.c
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;
}