Skip to content

fix(sync): use URL-only redaction for local sync planning errors - #590

Open
hippi345 wants to merge 2 commits into
columnar-tech:mainfrom
hippi345:fix/572-sync-plan-local-redaction
Open

hippi345 wants to merge 2 commits into
columnar-tech:mainfrom
hippi345:fix/572-sync-plan-local-redaction

Conversation

@hippi345

Copy link
Copy Markdown
Contributor

In sync planning, the value-based redactRegistryError hid 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.go cover both paths.

go build, go vet and go test ./... all pass.

Closes #572

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 zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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:

  1. fromLock can now leak secrets. drv.GetPackage can return invalid package URL %q: ... (drivers.go:388), which quotes the registry-published pkg.URL exactly as published. The PR's own reasoning says that text may echo configured secrets, and resolve sends it through redactPackageSelectError for that reason, but fromLock now only calls stripRegistryURLs. 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.
  2. Artifact errors also quote registry-published paths. newLockedArtifact → validateLockedPath produces path %q contains a forbidden character, must be relative and is not a valid relative URL path, with a path taken from pkg.Path. URL stripping removes only userinfo, query and fragment, so a secret in the path survives. Both the resolve and fromLock artifact paths now use stripping only.
  3. Detecting the case by error text is fragile. strings.Contains(msg, "invalid package URL") breaks silently if the wording changes, and cannot resolve package URL ... driver has no registry never contains a URL, so matching it does nothing. Wrapping the error at drivers.go:388 with an exported sentinel or type and checking it with errors.Is/errors.As would be sturdier. Alternatively, stop quoting the raw URL in that error, so callers don't need to know about it.
  4. The tests only cover resolve. Please add a fromLock case, 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]>
@hippi345

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review. Locally built diagnostics (version constraints, invalid archive hash, etc.) keep URL-only stripping, so short query values like ?v=1 can't hide them. For registry-published text I restored value-based redaction on the fromLock completion path (GetPackage / invalid package URL, and artifact recording) and on resolve → lockArtifacts. New tests cover both: local errors stay readable with ?v=1, and fromLock/resolve redact credentials echoed in published package URLs and artifact paths. I left the invalid package URL string match as it was; happy to switch to a sentinel error in drivers.go if you'd prefer.

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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:

  1. Yes, please switch to a sentinel/type. Since the string match decides whether a secret gets redacted, a rewording of invalid package URL in drivers.go would silently turn redaction off. An exported error type wrapped at drivers.go:388 and checked with errors.As in redactPackageSelectError would 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.
  2. TestPlanFromLockRedactsRegistryPublishedPackageURL can't fail. The published URL is http://%31.invalid/archive, which doesn't contain SUPERSECRET, so NotContains(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 the fromLock path, like the artifact-path test does.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sync: avoid value-based redaction for locally constructed errors in sync planning

3 participants