Repository navigation
Keep each advisory when merging duplicate alerts - #134
Draft
David Larsen (dc-larsen) wants to merge 3 commits into
Draft
David Larsen (dc-larsen) wants to merge 3 commits into
David Larsen (dc-larsen) wants to merge 3 commits into
Conversation
Dedupe keyed alerts on type, severity, category, file and position. Every advisory of one severity on a package shares an alert type (criticalCVE, cve and so on) and has no file, so they all landed on one key and only the first survived. fullscans.stream() and purl.post() both go through this, so handlebars@4.0.11 came back with one criticalCVE alert instead of six. The merge also kept the first alert's action. When the first advisory of a group was resolved or triaged to monitor or ignore, the Block action on the others was lost with them, and a caller that blocks on action == "error" passed. The alert key now includes the advisory ID (props.ghsaId, then cveId), and a merged alert keeps the most severe action seen (error > warn > monitor > ignore). Alerts without an advisory ID merge as before. Bumps the version to 3.6.3.
Scope the changelog's cross-release merging to purl.post(): fullscans.stream() rows carry no purl, so each release file stays its own artifact there. Note in the changelog and code that a merged alert keeps the first sighting's key while its action can come from another release, and that the extra advisory prop names mirror socket-python-cli's ADVISORY_ID_PROPS. An unknown or missing action keeps ranking below ignore, so it never replaces a known action and can't downgrade a known error. Tests pin that in both orders, along with the first-key behavior, a CVE next to a non-advisory alert on one package, and an empty input. Fix blank-line spacing in the new tests.
3.6.3 was released from main with the settings.integration_events() fix. Keep that changelog entry as is and ship the advisory dedupe fix as 3.6.4.
This branch has not been deployed
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.
Dedupemerges vulnerability alerts that share a type and severity on the same package, even when they are different advisories.fullscans.stream()andpurl.post()both run it, sohandlebars@4.0.11comes back with 1criticalCVEalert instead of 6, andvm2@3.9.11with 1 instead of 35.The Python CLI reads existing alerts for
--strict-blockingthroughfullscans.stream()(added in socket-python-cli #453). Two effects from a customer report:EXISTING blocking issuescount list one CVE per package and severity. A scan with 8 Block-action CVEs on unchanged packages reported 3.action. If that advisory is resolved or triaged to monitor/ignore, the Block action on the other advisories is lost and the CLI exits 0. Reproduced below: 34 Block CVEs present, stock CLI passes.Root Cause
Dedupe.consolidate_and_merge_alertskeys alerts on(type, severity, category, file, start, end). CVE alerts have no file or position, so every advisory of one severity on a package gets the same key and only the first is kept, along with itsaction.Fix
Dedupe.alert_keyadds the advisory ID (props.ghsaId, thencveId, upper-cased; same lookup order as the CLI'sIssue.advisory_id()), and the merge uses it. Different advisories stay separate. Socket's CVE alerts carry onlyghsaIdandcveId; the other names inADVISORY_ID_PROPS(ghsa_id,cve_id,cve) mirror the CLI's list, and a code comment says so.purl.post()only:fullscans.stream()rows have nopurl/inputPurl, so each release file stays its own artifact there.error>warn>monitor>ignore) instead of the first one. Only the action moves: the merged alert keeps the first sighting'skeyandprops, so in apurl.post()result thekeycan belong to a release whose own action was less severe than the one shown.ignore. It yields to any known action (ignoreincluded) and never replaces one, so an unexpected value can't downgrade a knownerror, in either order. Today the API only returnserror,warn,monitorandignore, so this has no current effect.main(Document the API token scopes each SDK method needs #130, Fixsettings.integration_events()to request the events path #131) while this PR was open, somainis merged in and this ships as 3.6.4; the 3.6.3 changelog entry is unchanged.socket-python-cli needs a pin bump to pick this up: SocketDev/socket-python-cli#459, which pins
socketdev==3.6.4and depends on 3.6.4 being published.Tests
Unit: 10 new tests in
tests/unit/test_dedupe.pyandtests/unit/test_full_scan_cached_polling_http.py: same-severity advisories stay separate; a triaged-first advisory doesn't hide a later Block one; same advisory across releases merges with the strictest action in any order; action ranking; CVE-only and case handling; non-advisory alerts still merge across releases; unknown actions never replace a known one; the merged alert keeps the firstkey; a CVE and a non-advisory alert on one package stay separate; empty input. Againstmain'sdedupe.pythe advisory and action tests fail (16 failures counting subtests); the empty-input and mixed-alert tests are regression guards and pass on both. All pass here.python -m pytest tests/unit(what CI runs), after mergingmain: 204 passed, 1 skipped (mainbefore 3.6.3: 193 passed).python -m pytest: same 14 failures and 19 errors intests/integrationas onmain(they need live credentials); no new failures.hatch buildandtwine check dist/*pass.End to end: stock
socketsecurity2.13.0 +socketdev3.6.2 vs the same CLI with this SDK, against a test org. Each project has a default-branch baseline and a PR branch with no dependency change, run with--strict-blocking --ignore-commit-files --integration api --scm api. "Raw" is counted fromGET /orgs/{org}/full-scans/{id}for the same scan: distinct (package, alert type, advisory) with actionerror. Patched runs were repeated twice with identical results.urlStringsalerts with different URL props and no file, all with actionignore. Their key is unchanged by this PR.purl.post(..., alerts=True)against the live API: handlebars 1 → 6 Critical, Django 2.2 1 → 6, Pillow 6.2.0 1 → 12 (26 release files still merge into one row with no duplicate alerts), vm2 1 → 35.Not changed in this PR
key,type,severity,category,file,start,end,props,action, plusreleases).actionSource,alertPolicyRule,fixandreachabilityare dropped from every alert that goes throughfullscans.stream()orpurl.post(). That predates this PR and is unchanged by it. Keeping them would mean deciding which sighting'sactionSource/alertPolicyRulegoes with the winning action and would change thepurl.post()output shape, so it's left for a follow-up. The CLI's typedstream(use_types=True)path has no fields for them either.Public Changelog
fullscans.stream()andpurl.post()keep every advisory on a package instead of one alert per type and severity, and a merged alert keeps its most severe action.