Conversation
Member
|
Should we fail the audit when we fail to update the registry for any package? New advisories can arrive at any time so even if it's cached it can be outdated. Maybe we should have a strict mode? |
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.
Summary
mix hex.auditpasses when it can't read a locked package's registry entry. Here is a project that locksmint1.10.1, which has three advisories, run with the registry unreachable and no cache:With the registry reachable, the same project lists the three advisories and exits with 1. Hex 2.5.1 does the same, except it also says "(using cache instead)".
Registry.advisories/3andRegistry.retired/3returnnil, andHex.Audittreatsnilas "nothing found".mix hex.auditgoes green when the registry is down, or when a proxy, a mirror, or missing credentials block it.--format sarifwrites an empty report in the same case.This PR makes
Hex.Audit.run/3check that the registry has an entry for each locked package version before it looks at findings.verify_dep/3inHex.RemoteConvergeralready does the same check formix deps.get:The same run on this branch:
A cached copy still works. With the network cut and a warm cache, the audit says "(using cache instead)", lists the three advisories, and exits with 1.
Testing
mix test --exclude integration: 360 tests pass.test/hex/audit_test.exs, with the registry down. A missing entry raises, a cached entry without the locked version raises, and a cached entry with an advisory reports it. The first two fail without this change.Cause and design
Hex.Registry.Server.write_result/4prints the fetch error and stores nothing. It used toraise "Stopping due to errors"after that when nothing was cached. Butcached? = !!:ets.lookup(...)was always true, so the raise never ran. #1247 fixed the check and dropped the raise, since callers raise when data is missing, for example "No package with name X (from: mix.exs) in registry" during resolution.Hex.Auditdoesn't. It only readsadvisoriesandretired, and both returnnilfor a missing entry.The check is in
Hex.Audit.run/3, somix hex.auditand thepolicy_enforce_lockcheck inmix deps.getboth get it. Inmix deps.getit never fires, becauseverify_lock/1has already raised by then. It usesRegistry.versions/2because that call tells a missing entry (:error) apart from an entry with no advisories. When a fetch fails but a cached copy exists, it returns the cached copy.It also checks the locked version. A stale mirror or cache without that release gives the same silent pass.
Offline mode already raises for an uncached package in
prefetch_offline/2. Now the online path fails the same way.