Skip to content
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

Fix CPE target software filtering + improve logging #2494

Merged
merged 10 commits into from
Mar 5, 2025

Conversation

wagoodman
Copy link
Contributor

@wagoodman wagoodman commented Feb 28, 2025

This changes the target software processing for CPEs such that, when we don't have a known package type (or is a binary type) we use the original CPEs on the package and vulnerability to understand if there is an overlap or not of target softwares -- this enables us to allow broad CPE matching (when a TWS of python should match with a TWS of *). Additionally for packages with known types we also do the same intersection but instead of checking for broad CPE matching we fallback to the existing logic that is there today (looking at package attributes).

In terms of the logging improvements, now refuted entries always come with a reason. The old logs look like so:

[0000] TRACE fetched affected CPE record cpe=cpe:2.3:a:snowflake:snowflake_connector:2.0.0:*:*:*:*:*:*:* duration=387.166µs records=10
[0000] TRACE dropped vulnerability affectedCPE=affectedCPE(cves=CVE-2023-34232, cpe=57950, vuln=226776) cpe=cpe:2.3:a:snowflake:snowflake_connector:2.0.0:*:*:*:*:*:*:* reason=package version not within vulnerability version constraints vulnerability=CVE-2023-34232
[0000] TRACE dropped vulnerability affectedCPE=affectedCPE(cves=CVE-2023-51662, cpe=57948, vuln=239682) cpe=cpe:2.3:a:snowflake:snowflake_connector:2.0.0:*:*:*:*:*:*:* reason=package version not within vulnerability version constraints vulnerability=CVE-2023-51662
[0000] TRACE dropped vulnerability affectedCPE=affectedCPE(cves=CVE-2025-24788, cpe=57948, vuln=281759) cpe=cpe:2.3:a:snowflake:snowflake_connector:2.0.0:*:*:*:*:*:*:* reason=package version not within vulnerability version constraints vulnerability=CVE-2025-24788
[0000] TRACE dropped vulnerability affectedCPE=affectedCPE(cves=CVE-2025-24793, cpe=57951, vuln=281764) cpe=cpe:2.3:a:snowflake:snowflake_connector:2.0.0:*:*:*:*:*:*:* reason=package version not within vulnerability version constraints vulnerability=CVE-2025-24793
[0000] TRACE dropped vulnerability affectedCPE=affectedCPE(cves=CVE-2025-24794, cpe=57951, vuln=281765) cpe=cpe:2.3:a:snowflake:snowflake_connector:2.0.0:*:*:*:*:*:*:* reason=package version not within vulnerability version constraints vulnerability=CVE-2025-24794
[0000] TRACE dropped vulnerability affectedCPE=affectedCPE(cves=CVE-2025-24795, cpe=57951, vuln=281766) cpe=cpe:2.3:a:snowflake:snowflake_connector:2.0.0:*:*:*:*:*:*:* reason=package version not within vulnerability version constraints vulnerability=CVE-2025-24795
[0000] TRACE dropped vulnerability criteria={fn:0x10193a7b0} reason=<nil> vulnerability=CVE-2023-34230
[0000] TRACE dropped vulnerability criteria={fn:0x10193a7b0} reason=<nil> vulnerability=CVE-2023-34233
[0000] TRACE dropped vulnerability criteria={fn:0x10193a7b0} reason=<nil> vulnerability=CVE-2024-49750
[0000] TRACE dropped vulnerability criteria={fn:0x10193a7b0} reason=<nil> vulnerability=CVE-2025-24791

The new logs have less addresses and more info:

[0000] TRACE fetched affected CPE record cpe=cpe:2.3:a:snowflake:snowflake_connector:2.0.0:*:*:*:*:*:*:* duration=387.166µs records=10
[0000] TRACE dropped vulnerability cpe=cpe:2.3:a:snowflake:snowflake_connector:2.0.0:*:*:*:*:*:*:* reason=not within vulnerability version constraints: "< 1.6.21" vulnerability=CVE-2023-34232
[0000] TRACE dropped vulnerability cpe=cpe:2.3:a:snowflake:snowflake_connector:2.0.0:*:*:*:*:*:*:* reason=not within vulnerability version constraints: ">= 2.0.25, < 2.1.5" vulnerability=CVE-2023-51662
[0000] TRACE dropped vulnerability cpe=cpe:2.3:a:snowflake:snowflake_connector:2.0.0:*:*:*:*:*:*:* reason=not within vulnerability version constraints: ">= 2.0.12, < 4.3.0" vulnerability=CVE-2025-24788
[0000] TRACE dropped vulnerability cpe=cpe:2.3:a:snowflake:snowflake_connector:2.0.0:*:*:*:*:*:*:* reason=not within vulnerability version constraints: ">= 2.2.5, < 3.13.1" vulnerability=CVE-2025-24793
[0000] TRACE dropped vulnerability cpe=cpe:2.3:a:snowflake:snowflake_connector:2.0.0:*:*:*:*:*:*:* reason=not within vulnerability version constraints: ">= 2.7.12, < 3.13.1" vulnerability=CVE-2025-24794
[0000] TRACE dropped vulnerability cpe=cpe:2.3:a:snowflake:snowflake_connector:2.0.0:*:*:*:*:*:*:* reason=not within vulnerability version constraints: ">= 2.3.7, < 3.13.1" vulnerability=CVE-2025-24795
[0000] TRACE dropped vulnerability reason=vulnerability target software(s) (".net") do not align with pkg(snowflake_connector@2.0.0 type="?" language="?" targets="python") vulnerability=CVE-2023-34230
[0000] TRACE dropped vulnerability reason=vulnerability target software(s) ("node.js") do not align with pkg(snowflake_connector@2.0.0 type="?" language="?" targets="python") vulnerability=CVE-2025-24791```

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
@wagoodman wagoodman marked this pull request as ready for review March 3, 2025 20:13
@wagoodman wagoodman self-assigned this Mar 3, 2025
@wagoodman wagoodman added the changelog-ignore Don't include this issue in the release changelog label Mar 3, 2025
Copy link
Contributor

@kzantow kzantow left a comment

Choose a reason for hiding this comment

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

We discussed the reason for returning, well, a "reason" from the criteria. Something about it doesn't sit well for me, though I can't really put my finger on exactly why. I understand there are some strings formatted with some appropriate context this way, but I wonder if the Criteria interface required fmt.Stringer to provide "enough" information for logs, or there's a different thing that would sit better. Regardless, this isn't something I want to hold up this PR for. I'll add a 1.0 issue to revisit this.

wagoodman added a commit to anchore/vulnerability-match-labels that referenced this pull request Mar 3, 2025
wagoodman added a commit to anchore/vulnerability-match-labels that referenced this pull request Mar 3, 2025
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
@wagoodman
Copy link
Contributor Author

but I wonder if the Criteria interface required fmt.Stringer to provide "enough" information for logs

I tried that initially but wasn't able to cover all cases. Always up for reevaluating that approach for grype 1.0

@wagoodman
Copy link
Contributor Author

Added label updates to support this PR: anchore/vulnerability-match-labels#141

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
westonsteimel pushed a commit to anchore/vulnerability-match-labels that referenced this pull request Mar 4, 2025
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
@wagoodman
Copy link
Contributor Author

wagoodman commented Mar 4, 2025

I've verified that the QG matching is doing the right thing even though in some cases this is performing a little worse in the examples we have. I'll adad ignore rules for the QG for these exceptions such that we can safely merge this PR.

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
@wagoodman wagoodman merged commit 947749e into main Mar 5, 2025
10 checks passed
@wagoodman wagoodman deleted the improve-dropped-vuln-logging branch March 5, 2025 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog-ignore Don't include this issue in the release changelog
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants