[Autofix] Add allow-list for env var in BenchmarkTest01190 to fix cmd injection#5
Open
rafikmojr wants to merge 1 commit into
Open
[Autofix] Add allow-list for env var in BenchmarkTest01190 to fix cmd injection#5rafikmojr wants to merge 1 commit into
rafikmojr wants to merge 1 commit into
Conversation
|
New Issues (2512)Checkmarx found the following issues in this Pull Request
Communicate with Checkmarx by submitting a PR comment with @Checkmarx followed by one of the supported commands. Learn about the supported commands here. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.


Autofix: Fixed 1 of 1 security risk(s)
✅ Fixed
SAST · View in Apiiro
Summary:
Added a strict allow-list check for the user-controlled environment variable value before it is passed to Runtime.exec in BenchmarkTest01190.java, blocking OS command injection via header-controlled env vars (e.g. LD_PRELOAD).
What Changed:
In
src/main/java/org/owasp/benchmark/testcode/BenchmarkTest01190.java, after thebarvariable is populated from theBenchmarkTest01190HTTP header viadoSomething, a new block constructs an immutableSet<String>of permitted environment-variable values ("safe1", "safe2", "safe3") and rejects the request with an error message before reachingRuntime.execwheneverbaris null or not in that set. The subsequentexec(args, argsEnv)call is therefore only reached with an allow-listed value. No imports were added because the new code uses fully-qualifiedjava.util.*classes.Why This Fix:
The overlay's remediation guidance and code example prescribe an allow-list of known-safe values as the correct defense for this CWE-78 pattern, and explicitly warn against sanitization or block-listing. An allow-list is the narrowest, most defensible control here because the env var has no legitimate free-form content — any deviation is malicious. A broader refactor (e.g. removing the env-var pass-through entirely) would alter the benchmark's public test surface; a focused allow-list gate matches the overlay's recommended pattern while keeping the servlet's observable shape intact.
Files Changed:
src/main/java/org/owasp/benchmark/testcode/BenchmarkTest01190.javaReviewer Notes:
expectedresults-1.2.csvmarksBenchmarkTest01190,cmdi,true,78). Adding the allow-list gate changes the intentionally-vulnerable fixture into a safe one, which will cause SAST tools under test to flip this row from a True Positive to a False N…safe1,safe2,safe3) are acceptable; the original code has no legitimate consumers, so no real values exist to preserve.Potential Impact:
Low–medium runtime impact: requests to
/cmdi-01/BenchmarkTest01190whoseBenchmarkTest01190header is not in the three-element allow-list will now receive an error string instead of triggeringRuntime.exec. Because the file is an intentionally-vulnerable benchmark fixture, the main side effect is that SAST/DAST tools scoring against this corpus will see the command-injection sink as guarded, which may shift scorecard metrics for this test case.About Apiiro Autofix
This PR was automatically generated by Apiiro Autofix. Review all changes carefully before merging and run your test suite to verify no regressions.