Repository navigation
Conversation
Reserve value-based redactRegistryError for index fetches and errors that embed registry-published package URLs. Package selection and lock artifact errors strip URL credentials only so short registry query values cannot hide diagnostics. Co-authored-by: Joel Shearon <[email protected]>
zeroshade
left a comment
There was a problem hiding this comment.
Thanks for this. The underlying problem is real: a configured query value shorter than 4 characters (e.g. ?v=1) causes any message that contains it as a substring, such as "version 1.0.0", to be replaced with "details are hidden". URL stripping is the right fix for errors built purely from local data. But this change also drops value-based redaction in places where text published by the registry reaches the message:
fromLockcan now leak secrets.drv.GetPackagecan returninvalid package URL %q: ...(drivers.go:388), which quotes the registry-publishedpkg.URLexactly as published. The PR's own reasoning says that text may echo configured secrets, andresolvesends it throughredactPackageSelectErrorfor that reason, butfromLocknow only callsstripRegistryURLs. A URL that failed to parse often has no scheme, so the URL scanner can't strip it either; only value-based redaction catches a secret there.- Artifact errors also quote registry-published paths.
newLockedArtifact→validateLockedPathproducespath %q contains a forbidden character,must be relativeandis not a valid relative URL path, with a path taken frompkg.Path. URL stripping removes only userinfo, query and fragment, so a secret in the path survives. Both theresolveandfromLockartifact paths now use stripping only. - Detecting the case by error text is fragile.
strings.Contains(msg, "invalid package URL")breaks silently if the wording changes, andcannot resolve package URL ... driver has no registrynever contains a URL, so matching it does nothing. Wrapping the error atdrivers.go:388with an exported sentinel or type and checking it witherrors.Is/errors.Aswould be sturdier. Alternatively, stop quoting the raw URL in that error, so callers don't need to know about it. - The tests only cover
resolve. Please add afromLockcase, and one where the published package URL or path contains the configured token.
Suggested shape: send every error that can quote registry-published text (package URLs and artifact paths, in both resolve and fromLock) through value-based redaction, and use URL stripping only for errors built entirely from local data, such as version constraints and the hash-format checks.
Keep URL-only stripping for locally built package selection and hash diagnostics while routing fromLock completion, drv.GetPackage URL parse failures and lock artifact path errors through value-based redaction. Add plan tests for fromLock completion and registry-published paths. Co-authored-by: Joel Shearon <[email protected]>
|
Thanks for the detailed review. Locally built diagnostics (version constraints, invalid archive hash, etc.) keep URL-only stripping, so short query values like |
zeroshade
left a comment
There was a problem hiding this comment.
Thanks, (1) and (2) look right: fromLock and resolve now treat GetPackage the same way, artifact errors are back on value-based redaction, and passing sourceURL to lockArtifacts also avoids a nil dereference when drv.Registry is unset. The ?v=1 tests cover #572 well.
Two things left:
- Yes, please switch to a sentinel/type. Since the string match decides whether a secret gets redacted, a rewording of
invalid package URLindrivers.gowould silently turn redaction off. An exported error type wrapped atdrivers.go:388and checked witherrors.AsinredactPackageSelectErrorwould make that a compile-time dependency. While you're there, the"cannot resolve package URL"match can go: that message (drivers.go:373) never contains a URL. TestPlanFromLockRedactsRegistryPublishedPackageURLcan't fail. The published URL ishttp://%31.invalid/archive, which doesn't containSUPERSECRET, soNotContains(token)passes even with plain URL stripping. Put the token in the published URL (e.g.http://%31.invalid/SUPERSECRET/archive) so the test actually exercises value-based redaction on thefromLockpath, like the artifact-path test does.
In sync planning, the value-based
redactRegistryErrorhid locally built messages when a registry URL had a short query value (for example?v=1) that also appeared as a substring of a version number.This uses URL stripping only for lock completion, package selection and lock artifact errors. Value-based redaction stays in place for index fetches and for errors that embed registry-published package URLs. New tests in
sync_plan_test.gocover both paths.go build,go vetandgo test ./...all pass.Closes #572