fix: preserve fields the public batch consumer needs through the policy reshape#670
Merged
John-David Dalton (jdalton) merged 2 commits intoJul 26, 2026
Merged
Conversation
reshapeArtifactForPublicPolicy stripped inputPurl from every artifact when a public API token was used, breaking request->response correlation for batchPackageFetch and batchPackageStream consumers. inputPurl is the caller's own echoed-back request PURL, not sensitive data, so carry it through the reshaped artifact. Scoped to inputPurl only; alert reshaping/low-severity filtering behavior is unchanged.
…shape The public policy reshape rebuilt each artifact from a fixed key allowlist that omitted several fields the public batch consumer (the web extension popover) needs to render: - namespace: completes the coordinate for scoped/grouped packages (npm @scope, Maven groupId) used in the display title and socket.dev link; without it namespaced packages render wrong. - score: the SocketScore subscore object the popover reduces to drive the score bar; distinct from scorecards (already kept). Without it the bar always shows the default. - artifactId/classifier/ext/params/path/platform/section: optional deep-link routing qualifiers packageLink() reads to build correct socket.dev URLs for non-npm ecosystems (Maven classifier/ext, PyPI artifactId, RubyGems platform, Go path). Copied only when present. Alert reshaping is unchanged: the {action,key,severity,type} shape and the mandated public policy (low-severity + action filtering) stay exactly as-is. This only widens the per-artifact field allowlist.
John-David Dalton (jdalton)
deleted the
fix/preserve-inputpurl-public-reshape
branch
July 26, 2026 04:12
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.
What
reshapeArtifactForPublicPolicy(insrc/http-client.mts) rebuilds each artifact from a fixed key allowlist when the caller uses a public API token. That allowlist dropped several fields the public batch consumer (the web extension popover) actually needs. This PR widens the allowlist to preserve those fields. It does not change alert reshaping or the public policy.Why
When a public token is in use (
SOCKET_PUBLIC_API_TOKEN === SOCKET_PUBLIC_API_KEY),batchPackageFetch/batchPackageStreamrun every artifact throughreshapeArtifactForPublicPolicy, which rebuilt each artifact as{ name, version, size, author, type, supplyChainRisk, scorecards, topLevelAncestors, alerts }. A field audit of socket-webext (background.tsbatch handling +content/rendering) found these fields are read but were being stripped:inputPurl— the request→response correlation keybackground.tsuses to map each batch reply back to the purl it asked for. Not sensitive (the caller supplied it). Error rows already kept it (they have noalertsfield, so they fell through the reshape unchanged), so success rows were asymmetric.namespace— completes the coordinate for scoped/grouped packages (npm@scope, Maven groupId, Go module path); used in the popover display title and the socket.dev link. Missing → namespaced packages render wrong.score— theSocketScoresubscore object the popover reduces (Object.values(score)→ min) to drive the score bar. Distinct fromscorecards(which was already kept). Missing → the bar always shows the default 100%.artifactId,classifier,ext,params,path,platform,section— optional deep-link routing qualifiers the sharedpackageLink()reads to build correct socket.dev URLs for non-npm ecosystems (Maven classifier/ext, PyPI artifactId, RubyGems platform, Go path). Copied only when present. npm unaffected.All of these are non-sensitive package identity / health / routing data. None is an alert.
Change detail
src/http-client.mts:reshapeArtifactclosure (used by both thedata.artifactsarray path and the single-artifactdata.alertspath, so both batch code paths are covered) now also emitsinputPurl,namespace,score, and...pickPresentDeepLinkFields(artifact).ArtifactDeepLinkQualifiers(all-optional local interface — these 7 fields aren't in the generated OpenAPISocketArtifactschema) andpickPresentDeepLinkFields(), which copies each qualifier only when defined so the reshaped shape stays minimal. Typed with no casts;SocketArtifactWithExtrasstays assignable to the intersection because every qualifier is optional.test/repo/unit/reshape-artifact-public-policy.test.mts:inputPurl correlation key preservationblock plus cases assertingnamespace+scoresurvive, the 7 qualifier fields survive when present, and are omitted when absent, and that error rows still carryinputPurl(symmetry).Pure data changes, no node deps — the browser bundle (
dist/index.browser.js) still packs, is node-builtin-free, and emits the widened reshape.Verified green:
tsgo --noEmit, lint, reshape + batch unit tests (89 across the staged set), full build.Explicitly out of scope
Alert reshaping is unchanged. Each alert stays
{ action, key, severity, type }, and the mandated public policy — droppingseverity: 'low'alerts and applying theactionspolicy filter — stays exactly as-is (this matches the extension'sApiAlertshape, so no alert-level change is needed). This PR only widens the per-artifact field allowlist; it does not touch the alert set or its filtering.