fix(config): expired package override shadows a later active override for the same package
Summary
An expired [[PackageOverrides]] entry shadows a later, still-active entry that matches the same package, so the active override is silently not applied.
Config.filterPackageVersionEntries (internal/config/config.go) picks the first entry that matches the package and the condition, then checks its effectiveUntil. If that first entry has expired, it returns false without looking at the remaining entries. The docs describe effectiveUntil as the date "after which the override will no longer apply", so an expired entry should behave as if it were absent.
This affects ShouldIgnorePackage, ShouldIgnorePackageVulnerabilities and ShouldOverridePackageLicense.
Real-world scenario
A team first adds a time-boxed override for one version, then later adds a permanent override for the whole package:
[[PackageOverrides]]
name = "lib1"
version = "1.0.0"
ignore = true
effectiveUntil = 2026-01-01
reason = "temporary, while we upgrade"
[[PackageOverrides]]
name = "lib1"
ignore = true
reason = "vendored and patched, never report"
After 2026-01-01, [email protected] is reported again, even though the second entry still says to ignore it. Other versions of lib1 are still ignored.
Reproduction
c := Config{PackageOverrides: []PackageOverrideEntry{
{Name: "lib1", Version: "1.0.0", Ignore: true, EffectiveUntil: time.Now().Add(-24 * time.Hour)},
{Name: "lib1", Ignore: true},
}}
ok, _ := c.ShouldIgnorePackage(&extractor.Package{Name: "lib1", Version: "1.0.0"})
// ok == false, expected true
Run as an internal test in internal/config on main (Go 1.27.3): ignored=false.
Expected behavior
Expired entries are skipped when looking for a matching override, so the first active matching entry is used.
Proposed fix
Include the expiry check in the IndexFunc predicate of filterPackageVersionEntries (e.matches(pkg) && condition(e) && shouldIgnoreTimestamp(e.EffectiveUntil)), plus a table test case covering an expired entry followed by an active one. IgnoredVulns is left unchanged, since duplicate IDs there are already documented as "only the first will be used".
I'd be happy to send a PR if this gets assigned to me. (Found and reproduced with the help of an AI coding assistant; I verified the reproduction myself.)
Reproduced this on current main (0c8f9eb4) with table tests in internal/config: an expired [email protected] entry followed by a package-wide lib1 entry makes ShouldIgnorePackage return (false, <expired entry>), so the active entry never applies. Same shadowing shows up for ShouldIgnorePackageVulnerabilities and ShouldOverridePackageLicense since they share filterPackageVersionEntries.
The proposed direction looks right to me: fold shouldIgnoreTimestamp(e.EffectiveUntil) into the IndexFunc predicate so expired entries are skipped during the scan instead of terminating it, and return the first still-active match. On the second return value: all three call sites only read the returned entry when the bool is true (internal/scalibrannotator/filter/filter.go:143, pkg/osvscanner/vulnerability_result.go:80 and :95), so returning a zero entry when nothing active matches is safe.
I have the one-function change ready with table tests for all three affected methods (expired-only, expired-then-active, and the existing single-entry shapes). Happy to open the PR if this gets assigned to me.
Thanks for confirming. As the reporter I already have the fix and table tests committed on a branch (expired-only and expired-then-active cases in TestConfig_ShouldIgnorePackage; both fail on main and pass with the change). Maintainers, I'm happy to open the PR as soon as this is assigned.
Sounds good — standing back and letting you carry it.
For reference in case it saves you any time: my repro branch is at choksi2212/osv-scanner@6a184863 with the same table cases (expired-only, expired-then-active, plus an active-then-expired control) wired into TestConfig_ShouldIgnorePackage, all failing on main (0c8f9eb4) and passing with the expired-entry skip. Happy to review/test your PR when it's up.
Thanks @choksi2212, appreciated, and I'll add your active-then-expired control case too. Maintainers, could you assign this to me when you get a chance? I'll open the PR right after, per CONTRIBUTING.
I'm not sure what's being proposed is a good idea. I can see the current version being correct, as in the more precise match should be prioritised over a less precise entry. Though I can also see the other option of the later entry in the config being higher priority.
Maybe it's more of a documentation / communication problem here, perhaps emitting a warning if two config entries cover the same package. @G-Rath I think you are working on the config in https://github.com/google/osv-scanner/pull/2534, any thoughts for this?
I agree @another-rex re the current behaviour, because it should also give the most visibility: if I've got an override with an expiration, then chances are
- there is something that would be reported without the override (because I added it in the first place)
- I expect to deal with the override sometime in the future (because I've set an expiration)
so regardless of what other overrides exist, if that expiration is hit, not applying "other overrides" should mean 1. comes up again making 2. a lot more obvious; and alternatively if 1. doesn't happen (e.g. the advisory was withdrawn), it'll be a worse outcome to be applying a more general override.
I think though we should look at improving our messaging: it doesn't seem like we output anything if there's an expired override entry, which I think we should do; and also as you've said trying to put a message if there's two equally matching overrides could be a good idea (assuming it's not too complex)
Turns out "expired" entries are considered as "unused", so the "fix" I've ended up doing in #3173 is mirroring our "unused vuln ignore" logic for package overrides