Skip to content

fix(server): record at request time whether a lookup sent credentials - #177

Merged
sweepies merged 5 commits into
mainfrom
fix/credentialed-at-request-time
Nov 4, 2026
Merged

sweepies merged 5 commits into
mainfrom
fix/credentialed-at-request-time

Conversation

@sweepies

@sweepies sweepies commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner

Follow-up to #163 (closed): which lookups the public repository API withholds.

The problem

The server withheld a dependency's updates from the public API when credentialed(id) predicted that its lookup read a registry with operator credentials. The prediction built one URL per source and matched it against the registries. That missed:

  • Sources: crates, Go, NuGet, RubyGems, Packagist, Terraform and others got no URL at all. A mirror with credentials in front of crates.io or the Go proxy was never counted.
  • Later requests: a lookup's second and later requests, such as PyPI's simple index after its JSON API, or Go's .info documents.

It's the shadow-implementation pattern again: guessing what the lookup will request instead of recording what it did.

Request-time record

  • HTTP: patchula_http::tracked(work) runs work in a task-local record. A request records that it sent credentials when it carries:

    • an operator entry's credentials, directly or through a mirror;
    • a registry account's token;
    • token-realm credentials.

    Cached answers record too, since cache entries are kept per credential, so a hit is one those credentials read.

  • Engine: each catalog lookup runs inside tracked, including GitHub release batches. The flag is stored with the engine's saved catalogs, so a reused catalog keeps it, and written into the dependency's metadata as credentialed.

  • Server: withheld drops exactly the dependencies whose metadata says credentialed. Engine::credentialed, Client::credentialed and the URL helpers only they used are deleted.

  • Image checks: they read the same registry as the image's tag lookup, so its flag covers them.

  • GitHub token: requests with the GitHub token still don't count, as before. Otherwise every Actions and GitHub-release lookup would be withheld.

Also covered after review

  • Coalesced reads: a read served from the HTTP client's in-flight memo records what the original request sent.
  • Digest, image digest and SBOM reads: recorded per package, kept apart from catalog lookups. A digest-only image rule with no catalog is covered.
  • Docker accounts: only an entry that sends credentials makes a token an account's.
  • Saved catalogs: moved to age-catalog-v4, with no default for the new field. A catalog saved before the record existed can't be reused as uncredentialed.
  • Withheld report: also drops the resolved current.version, resolution and advisories, plus warnings and lookup failures naming the dependency. A private repository's stored run uses them.
  • Merged entries: merging two report entries keeps credentialed if either had it.

Tests

  • An HTTP unit test for nested and outer records.
  • The npm, mirrored-npm and PyPI datasource tests check what each lookup recorded.
  • The server tests use the metadata flag, and check that warnings are withheld.
  • Removed: the predicted-URL table test.

Follow-ups

  • No test drives the coalesced memo or the digest and SBOM records end to end.

  • A saved catalog fetched with credentials stays flagged until it expires, even if the credential is removed. That only over-withholds.

  • A private repository's stored run keeps the Count's own PR titles, bodies and branch messages, which name versions a credentialed lookup found. They're the bot's own text on GitHub, visible there once the repository is public.

Which lookups the public repository API withholds was decided by
predicting one URL per source and matching it against the operator's
registries. That covered npm, PyPI, container registries, Helm, Maven and
forge tags only, and only the first URL a lookup reads; crates, Go,
NuGet, RubyGems, Packagist, Terraform and the rest never counted, nor did
a second request a lookup made through a mirror.

Now the HTTP client records, as each request is made, whether it carried
an operator entry's credentials (directly or through a mirror, from the
network or the cache, whose entries are kept per credential) or a
registry account's token, in a task-local record. The engine runs each
catalog lookup inside one, keeps the result with its saved catalogs, and
writes it into the dependency's metadata as credentialed; the server
withholds exactly those. The predicting credentialed() functions and the
URL helpers only they used are gone.

The mirrors example now mirrors the Go proxy, since PyPI is read through
its JSON API first and a simple-only mirror does not replace it (from
#163).
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
count-patchula 976eea5 Commit Preview URL

Branch Preview URL
Nov 04 2026, 06:04 AM

…alogs

From review:

- A read served from the HTTP client's in-flight memo records the
  credentials its original request carried, so two lookups of the same
  URL both count.
- Digest, image digest and SBOM reads run inside the record too; a
  dependency whose package any of them read with credentials is
  credentialed, which covers a digest-only image rule with no catalog.
- Docker counts a token as an account's only when its entry sends
  credentials, not for a withheld entry.
- Saved catalogs move to age-catalog-v4 without a default, so none
  saved before the record existed is reused as uncredentialed.
- A withheld dependency also loses the version its range resolved to and
  its resolution, which came from the lookup.
From the second review:

- A withheld dependency also loses its advisories: an image's come from
  SBOMs read with the same credentials.
- Warnings and lookup failures naming a dependency found with
  credentials are dropped from the withheld report, and a private
  repository's stored run takes its warnings and lookup failures from
  it, since they can quote what the registry answered.
- Merging two report entries keeps credentialed if either was.
- Digest reads and image reads are recorded apart (git: and image:), so
  a credentialed image named like an npm package does not withhold it.
- Cached::read_credential, which only the removed prediction used, is
  gone; the report reference documents credentialed.
An entry without metadata now takes the merged one's, so its
credentialed flag is not lost.
Wrapping lookups and reads in a credential record grew the run's future
past a debug build's test stack; boxing them keeps it on the heap.
@sweepies
sweepies merged commit cb6b046 into main Nov 4, 2026
11 checks passed
@sweepies
sweepies deleted the fix/credentialed-at-request-time branch November 4, 2026 06:26
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.

1 participant