Skip to content

fix(dockerfile): flag unpinned dnf packages followed by a flag#8064

Open
arpitjain099 wants to merge 1 commit into
Checkmarx:masterfrom
arpitjain099:fix/dnf-verbose-flag-version-fn
Open

fix(dockerfile): flag unpinned dnf packages followed by a flag#8064
arpitjain099 wants to merge 1 commit into
Checkmarx:masterfrom
arpitjain099:fix/dnf-verbose-flag-version-fn

Conversation

@arpitjain099

Copy link
Copy Markdown

Closes #7306

Reason for Proposed Changes

  • The missing_version_specification_in_dnf_install query has a package-parsing rule that special-cases the token -v. The second analyzePackages clause requires packages[plus(j, 1)] != "-v", which treats a package as version-pinned whenever the next token happens to be -v. In dnf, -v is the verbose flag, not a version marker, so this is a false negative: an unpinned package followed by -v silently passes the check.
  • Reproduced on current master. RUN dnf install zip -v is not flagged even though zip has no pinned version, because zip is followed by -v and the clause skips it. RUN dnf install -y zip -v has the same problem.

Proposed Changes

  • Removed the -v special case from analyzePackages. A package is now decided solely on whether it carries a version (dockerLib.withVersion), regardless of the next token. The two former clauses (j == length - 1 and j != length - 1) collapse into one, since the only difference between them was the bogus -v check.
  • Added a positive case RUN dnf install zip -v (the unpinned-package-before-a-flag form the old rule missed) to test/positive.dockerfile and its expected finding to test/positive_expected_result.json.
  • Added a negative case RUN dnf install -v zip-3.0 to test/negative.dockerfile to confirm a genuinely pinned package followed by -v still passes, so the fix does not introduce a false positive.
  • Verified with the query test harness: go test ./test/ -run 'TestQueries$/dockerfile/missing_version_specification_in_dnf_install' passes for both positive and negative, and the content/metadata tests stay green (Rego coverage is now 100% for this query since the dead branch is gone).

I submit this contribution under the Apache-2.0 license.

The missing_version_specification_in_dnf_install query treated a package
token as version-pinned whenever the next token was '-v', via the clause
packages[plus(j, 1)] != "-v". In dnf, '-v' means verbose, not a version,
so 'RUN dnf install zip -v' (zip is not pinned) wrongly passed the check,
a false negative.

Drop the '-v' special case and decide solely on whether the package itself
carries a version (dockerLib.withVersion). Pinned packages such as
'dnf install zip-3.0 -v' still pass, so no new false positive is introduced.

Adds positive and negative test cases covering a flag that follows the
package name.

Closes Checkmarx#7306

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(dockerfile): unexpected pass for dnf -v option

1 participant