Skip to content

feat(vis): answer vis inspect --only signatures natively - #265

Open
prisis wants to merge 1 commit into
t3/native-inspect-archived-repofrom
t3/native-inspect-signatures
Open

prisis wants to merge 1 commit into
t3/native-inspect-archived-repofrom
t3/native-inspect-signatures

Conversation

@prisis

@prisis prisis commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

What

vis inspect <package> --json --only signatures runs natively. Stacked on #264 (which is stacked on #262): it uses their Services addresses in Context, version_entry and the test stub. Merge in order and retarget each PR to next as its base lands (GitHub does it by itself only when merged branches are deleted). Followed by #266. signatures is not part of the default set (it runs only when asked for with --only signatures), so this PR does not change what a plain vis inspect <package> --json does.

Behaviour

  • Keys: the cached set (~/.vis/cache/registry-keys/npmjs.json, 24 hours) else a request to VIS_NPM_KEYS_URL or https://registry.npmjs.org/-/npm/v1/keys. VIS_NPM_KEYS_URL is a variable the Node side already reads, so both sides honour it and it is also the loopback address of the parity tests; no new override. A fresh answer is cached in the bytes Node writes ({"createdAt","keys","ttlMs"}, keys as JSON.stringify writes them, through the same reader security keys-refresh uses). A status other than 2xx falls back to the old keys, or ends in the fetch-failed warning, as Node does.
  • Findings: no dist.signatures / no dist.integrity (warnings), keyid the registry does not list (error), expired key (warning), in Node's messages and order. A key without expires, with an empty one, or with null (npm's current key has "expires": null) never expires; a date in the form registries write is compared with the clock.
  • Verification: ECDSA P-256 / SHA-256 over name@version:integrity with ring.

Handed to Node before any output or write

A signature that does not verify here (so invalid-signature stays Node's report: createPublicKey and Buffer.from(…, "base64") are lenient where this reader is strict, so "does not verify here" is not evidence Node agrees); a key that is not an uncompressed P-256 SubjectPublicKeyInfo in canonical base64; an expires in any other form; a keys request that fails before an answer; a redirect; a keys answer or cache file that is not what Node reads (not JSON, not an object, no numeric createdAt/ttlMs, no keys array); a VIS_NPM_KEYS_URL that is not text or not a plain URL.

Dependency

ring is now named in native/cli/Cargo.toml (ring = { version = "0.17", default-features = false }). It is already linked: rustls (feature ring) and ureq use 0.17.14, so Cargo.lock gains one line (the dependency edge) and no package, and the features are the ones already unified. cargo deny check: advisories, bans, licenses and sources ok. I chose it over a pure-Rust p256 because it adds nothing to the binary; verification code is the one rustls already trusts for TLS signatures.

Proof

  • cargo test -p vis-cli: unit tests with keys generated at test time (every finding, the exact cache bytes, fresh/stale/refused keys, hand-overs, canonical base64 and SPKI parsing, expiry forms); cargo fmt --all --check, cargo clippy -p vis-cli --all-targets -- -D warnings, cargo deny check clean.
  • __tests__/native/inspect-parity.test.ts: native vs Node on the stub registry and a stub keys endpoint (keys and signatures generated with node:crypto): good, two signatures (one unknown), expired key, key that expires far ahead, null expiry, no signature, no integrity, keys answered 500 and {}, fresh/old/refreshed key cache, with identical stdout, exit status and cache bytes; invalid and malformed signatures and a non-JSON keys answer are handed over (exit 70, nothing touched) and the delegated run matches Node.
  • Live: left-pad@1.3.0 (signed with a now expired key), @types/node, typescript, esbuild@0.19.0, lodash@4.17.21 in a scratch workspace with separate temp homes: identical stdout and identical cached keys, native without a Node fallback (real npm signatures verified by ring).
  • Unverified locally: Linux.

🤖 Generated with Claude Code

The signatures marshall reads npm's signing keys (the cached set in
`~/.vis/cache/registry-keys`, else `VIS_NPM_KEYS_URL` or the registry's keys
address, the variable the Node side already honours) and checks each
`dist.signatures` entry of the inspected version: a missing signature or
integrity is a warning, a keyid the registry does not list an error, an expired
key a warning. A keys request answered with a status other than 2xx falls back
to the old keys or ends in the `fetch-failed` warning, as Node does, and a fresh
answer is cached in the bytes Node writes.

The signature is verified with `ring` (ECDSA P-256 over SHA-256, DER), which
`rustls` already links, so `ring` is now named in the binary's manifest and the
lock file gains no package. The key and signature must be canonical base64 and
an uncompressed P-256 SubjectPublicKeyInfo. A signature that verifies is no
finding; one that does not verify here is handed to Node, whose OpenSSL and
`Buffer.from` read keys and signatures more leniently, so the `invalid-signature`
report is Node's to make. A key whose `expires` is `null` (npm's current key) or
empty never expires; one in the form registries write is compared with the
clock; any other form goes to Node.

Also handed over before any output or write: a keys request that fails before
an answer, a redirect, a keys answer or cache file that is not what Node reads,
and a keys address that is not a plain URL.

The launcher gate accepts `signatures`; a run that executes `expiredDomains`
still stays in Node.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ab57bb79-137a-431f-bbaf-d6bed77c604f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@qodo-code-review

qodo-code-review Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Run explicit vis inspect signature checks natively

✨ Enhancement 🧪 Tests 🕐 40+ Minutes

Grey Divider

AI Description

• Runs vis inspect --json --only signatures natively without changing default inspection behavior.
• Reuses npm signing-key caching and verifies signatures with the already-linked ring library.
• Delegates ambiguous inputs to Node before output or writes, preserving report parity.
Merge Risk 🟡 Medium

Blast radius 🟢 Low 💥 1 capability

  • 1 affected end-to-end capability after fault-specific containment; implementation boundaries do not widen its functional scope.
  • The changed routing, key retrieval, cache use, and ECDSA verification all produce one end-to-end outcome: signature findings and status for a package inspection.
  • The cache is an implementation boundary within that bounded inspection behavior, not an independent user capability.
Behavioral complexity 🔴 High 🧩 Multiple interactions

  • Before: Node alone handled signatures.
  • After: native routing adds key-cache freshness, stale-key fallback, malformed-input handoff, expiry classification, custom base64/SPKI parsing, and ECDSA verification.
  • New correctness conditions are that cache state, registry response shape, key expiry, signature encoding, and Node delegation remain behaviorally equivalent across mixed states; the ECDSA and encoding logic also requires algorithm-specific correctness.
Potential damage 🟡 Medium 🩹 Incorrect results

  • If the native verifier or cache interpretation diverges from Node, users can receive a false signature warning/error, miss a finding, or get a different inspection status.
  • Reverting stops new native mismatches, but cached keys may remain until expiry or deletion; external package state is not modified.
  • Code rollback prevents subsequent native execution, and deleting or allowing the 24-hour registry-key cache to expire restores key retrieval.
  • A previously emitted report must be rerun; no persistent package data or external package effect requires compensation.
Assessed commit b2f2dd2
Diagram

graph TD
  R["CLI router"] --> P["Inspect planner"] --> S["Signatures marshall"] --> C[("Keys cache")]
  S --> K["npm keys endpoint"] --> V["ring verification"] --> O["JSON report"]
  K --> C
  S --> O
  S --> N["Node fallback"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Keep signature inspection in Node
  • ➕ Avoids duplicating signature and key-cache behavior across runtimes.
  • ➖ Does not achieve native execution for explicit signature inspection.
2. Use a pure-Rust P-256 implementation
  • ➕ Avoids depending directly on ring's verification API.
  • ➖ Adds cryptographic dependencies when ring is already linked through rustls.

Recommendation: Use the PR's ring-based native path. Reusing the existing crypto dependency and delegating uncertain cases to Node best balances native coverage with report parity.

Files changed (12) +900 / -19

Enhancement (3) +448 / -9
route.mjsAdmit signatures through the native inspect route +6/-5

Admit signatures through the native inspect route

• Adds 'signatures' to the native marshall gate while leaving 'expiredDomains' in Node. Updates routing comments to describe the new coverage.

packages/tooling/vis/bin/route.mjs

mod.rsIntegrate signatures into native inspect planning +26/-4

Integrate signatures into native inspect planning

• Adds the signing-key service address, permits the signatures marshall, and stages its findings and cache actions. Plain inspection still delegates when it includes unsupported 'expiredDomains'.

packages/tooling/vis/native/cli/src/inspect/mod.rs

signatures.rsImplement native npm signature checks +416/-0

Implement native npm signature checks

• Reads cached or fetched registry keys, checks signature-related findings, and verifies canonical P-256 signatures with ring. Delegates malformed or uncertain cases to Node before committing output or cache writes; includes focused unit tests.

packages/tooling/vis/native/cli/src/inspect/signatures.rs

Refactor (3) +11 / -7
archived_repo.rsShare inspected-version lookup +1/-1

Share inspected-version lookup

• Makes 'version_entry' accessible to the sibling signatures marshall so both use the same version fallback.

packages/tooling/vis/native/cli/src/inspect/archived_repo.rs

marshalls.rsShare finding construction with signatures +1/-1

Share finding construction with signatures

• Exposes 'Target::finding' within inspect for consistent signature finding metadata.

packages/tooling/vis/native/cli/src/inspect/marshalls.rs

keys_refresh.rsReuse Node-compatible key parsing and cache serialization +9/-5

Reuse Node-compatible key parsing and cache serialization

• Exposes the existing fetched-key representation and parser to inspect. Extracts cache-entry formatting so keys-refresh and signature inspection write the same JSON shape.

packages/tooling/vis/native/cli/src/keys_refresh.rs

Tests (4) +436 / -3
inspect-parity.test.tsExercise native signature inspection against Node +108/-2

Exercise native signature inspection against Node

• Adds generated signing keys and registry fixtures covering valid, missing, expired, unknown, and invalid signatures. Compares native output, exit status, and cache behavior with Node, including fallback cases.

packages/tooling/vis/tests/native/inspect-parity.test.ts

tests.rsCover native signature findings, caching, and handoff +325/-0

Cover native signature findings, caching, and handoff

• Adds local-registry tests for verification, finding order and severity, fresh and stale keys, cache bytes, and cases requiring Node delegation. Extends the test service setup with a keys endpoint.

packages/tooling/vis/native/cli/src/inspect/tests.rs

native-routes.snapSnapshot the mixed-marshall inspect route +1/-0

Snapshot the mixed-marshall inspect route

• Adds an inspect case combining 'signatures' with unsupported 'expiredDomains' to the routing snapshot.

packages/tooling/vis/native/cli/tests/fixtures/native-routes.snap

routing.jsonExpect native routing only for supported signatures selections +2/-1

Expect native routing only for supported signatures selections

• Changes explicit signatures inspection to enter the native route and adds a mixed selection that remains in Node.

packages/tooling/vis/native/cli/tests/fixtures/routing.json

Other (2) +5 / -0
Cargo.lockRecord the CLI's direct ring dependency +1/-0

Record the CLI's direct ring dependency

• Adds 'ring' to the CLI package's dependency list without introducing a new locked package.

packages/tooling/vis/native/Cargo.lock

Cargo.tomlDeclare ring for registry signature verification +4/-0

Declare ring for registry signature verification

• Names the already-linked ring 0.17 dependency directly in the CLI manifest for ECDSA verification.

packages/tooling/vis/native/cli/Cargo.toml

@prisis
prisis deployed to benchmarks November 26, 2026 00:25 — with GitHub Actions Active
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for following the naming conventions! 🙏

@github-actions github-actions Bot added package: vis vouch:trusted PR author is a collaborator, a bot or on the VOUCHED list. size:XL Size of the change, tests and generated files excluded. labels Nov 26, 2026
@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (2)

Grey Divider


Remediation recommended

1. Expired signing keys can go unreported 🐞 Bug
Description
signatures::run checks key expiry against context.now_ms, which answer captures before
fetching the packument or signing keys. If a key expires during those requests, native verification
emits no expired-key warning while Node's later clock check does; with --strict, their exit
statuses also differ.
Code

packages/tooling/vis/native/cli/src/inspect/signatures.rs[277]

+        if let Some(at) = expired(key, now_ms as f64)? {
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The native signature check can miss a key that expires while packument or key requests are in progress.

## Fix Focus Areas
- packages/tooling/vis/native/cli/src/inspect/signatures.rs[233-282]
- packages/tooling/vis/native/cli/src/inspect/mod.rs[314-317]

## Recommended Fix
Obtain the expiry-check time after the key request, rather than reusing the timestamp captured before the packument request. Preserve delegation if the clock cannot be read, and test a key that expires during the request.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


View medium (1)
2. New signing keys can appear unrecognized 🐞 Bug
Description
registry_keys tests cache freshness using context.now_ms rather than the time at which it reads
the keys file. If a cached set expires during a slow packument request and the registry has since
added a signing key, native skips the refresh and reports that key as unrecognized, whereas Node
fetches the updated set.
Code

packages/tooling/vis/native/cli/src/inspect/signatures.rs[R175-178]

+    let cached = read_cache(&file, now_ms as f64)?;
+
+    if let Some((keys, false)) = cached {
+        return Ok(Fetched { keys: Some(keys), cache: Vec::new() });
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A signing-key cache that expires during packument retrieval can still be treated as fresh by the native marshall.

## Fix Focus Areas
- packages/tooling/vis/native/cli/src/inspect/signatures.rs[172-183]
- packages/tooling/vis/native/cli/src/inspect/mod.rs[314-317]

## Recommended Fix
Read the current clock when checking signing-key cache freshness instead of passing the pre-request context timestamp. Add a test where the cache expires between the initial clock reading and the keys-file read, and verify that native requests updated keys.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


Grey Divider

Tip of the day
💡 Did you know, you can tweak Display settings with a live preview to see your comment before it ships

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@codspeed

codspeed Bot commented Nov 26, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 3 untouched benchmarks
⏩ 113 skipped benchmarks1


Comparing t3/native-inspect-signatures (b2f2dd2) with t3/native-inspect-archived-repo (f3de88c)

Open in CodSpeed

Footnotes

  1. 113 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

This branch was successfully deployed

1 active deployment
benchmarks — b2f2dd2d Deployed Nov 26, 2026 by prisis via Bench native (vis) #446
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: vis size:XL Size of the change, tests and generated files excluded. vouch:trusted PR author is a collaborator, a bot or on the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant