Skip to content

fix(pnpr): reject re-publishing an existing version with 409 Conflict - #12646

Merged
zkochan merged 2 commits into
pnpm:mainfrom
YESHYUNGSEOK:fix/pnpr-reject-republish
Jun 25, 2026
Merged

zkochan merged 2 commits into
pnpm:mainfrom
YESHYUNGSEOK:fix/pnpr-reject-republish

Conversation

@YESHYUNGSEOK

@YESHYUNGSEOK YESHYUNGSEOK commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

merge_objects unconditionally overwrote an existing versions[v] entry, and stage_publish
renamed the new tarball over the old one, so a user with Publish access could re-publish
name@version with backdoored bytes and a fresh dist.integrity. Clients that pinned the old
hash in their lockfile then hit EINTEGRITY; clients without a lockfile silently fetched the
replaced bytes. npm and verdaccio treat a published version as immutable and answer a re-publish
with 409 Conflict.

stage_publish now reads the hosted packument once and rejects the publish with a new
VersionAlreadyPublished error (HTTP 409) when any incoming version is already hosted — before any
tarball is written. The check looks only at the locally hosted packument, not the upstream-seeded
merge, so a version that exists only upstream can still be published locally for the first time.
The attachment's version is threaded through ValidatedPublish via a named PreparedAttachment
struct (replacing the former positional tuple).

Squash Commit Body

merge_objects unconditionally overwrote an existing versions[v] entry, and stage_publish wrote
the new tarball over the old one, so a Publish-permissioned user could re-publish name@version
with backdoored bytes and a new dist.integrity. Clients with the old hash in their lockfile then
hit EINTEGRITY; clients without a lockfile silently fetched the replaced bytes. npm and verdaccio
treat published versions as immutable and answer a re-publish with 409.

stage_publish now reads the hosted packument once and rejects the publish with the new
VersionAlreadyPublished error (HTTP 409) when any incoming version is already hosted, before any
tarball is written. The check looks only at the locally hosted packument, not the upstream-seeded
merge, so a version that exists only upstream can still be published locally for the first time.

Checklist

  • Added or updated tests — republishing_an_existing_version_is_rejected_with_conflict
    asserts the second publish gets 409 and the original tarball bytes are untouched on disk.
  • Updated the documentation if needed — n/a.

(No changeset: pnpr is not a published npm package. No pnpm-side port: pnpr-only endpoint;
pacquet has not ported publish.)


Written by an agent (Claude Code, claude-opus-4-8).

Summary by CodeRabbit

  • New Features

    • Publishing now rejects attempts to publish an already-hosted name@version, returning a clear 409 Conflict response.
    • Re-publishing is blocked even when the incoming payload differs (including cases using manipulated version metadata without matching attachment data).
  • Bug Fixes

    • Improved publish validation to detect existing hosted versions earlier in the workflow.
    • Added tests to ensure rejected re-publishes do not overwrite the originally published package tarball bytes.

merge_objects unconditionally overwrote an existing versions[v] entry, and stage_publish wrote
the new tarball over the old one, so a Publish-permissioned user could re-publish name@version
with backdoored bytes and a new dist.integrity. Clients with the old hash in their lockfile then
hit EINTEGRITY; clients without a lockfile silently fetched the replaced bytes. npm and verdaccio
treat published versions as immutable and answer a re-publish with 409.

stage_publish now reads the hosted packument once and rejects the publish with the new
VersionAlreadyPublished error (HTTP 409) when any incoming version is already hosted, before any
tarball is written. The check looks only at the locally hosted packument, not the upstream-seeded
merge, so a version that exists only upstream can still be published locally for the first time.
The attachment version is threaded through ValidatedPublish via a named PreparedAttachment.

Co-authored-by: Claude <[email protected]>
@YESHYUNGSEOK
YESHYUNGSEOK requested a review from zkochan as a code owner June 25, 2026 05:00
@coderabbitai

coderabbitai Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The registry now rejects publishing a version that already exists in the hosted packument. The error type, publish staging flow, and integration tests were updated to surface and verify the conflict response.

Changes

Republish conflict handling

Layer / File(s) Summary
Error variant and status mapping
pnpr/crates/pnpr/src/error.rs
Adds VersionAlreadyPublished with package and version fields, a specific log kind, and HTTP 409 Conflict.
Prepared attachments and republish check
pnpr/crates/pnpr/src/server.rs
ValidatedPublish now carries PreparedAttachment records, and stage_publish rejects versions already present in the hosted packument before staging tarballs.
Republish conflict tests
pnpr/crates/pnpr/tests/auth_publish.rs
The new integration tests publish [email protected], retry with conflicting data, expect 409, and verify the stored tarball bytes stay unchanged.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

product: pnpr

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Reject re-publishing an already-hosted pnpr version with HTTP 409 Conflict
🐞 Bug fix 🧪 Tests 🕐 20-40 Minutes

Grey Divider

Description

• Reject publishes that target an already-hosted version, returning HTTP 409 Conflict.
• Detect version clashes before writing any tarball bytes to hosted storage.
• Add regression test ensuring republish is refused and original tarball bytes remain unchanged.
Diagram

graph TD
  A([Client publish]) --> B["PUT /:pkg (publish_package)"] --> C["validate_publish_doc"] --> D["stage_publish"] --> E{Version already hosted?}
  E -- "yes" --> F["Error: VersionAlreadyPublished (409)"]
  E -- "no" --> G["merge_manifest + stage tarballs"] --> H[(Hosted storage)]
  subgraph Legend
    direction LR
    _req([Request]) ~~~ _step["Handler/step"] ~~~ _dec{Decision} ~~~ _db[(Storage)]
  end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Enforce immutability at storage layer (atomic create / conditional put)
  • ➕ Protects against cross-instance races when multiple servers share the same hosted backend
  • ➕ Guarantees tarballs/packuments can’t be overwritten even if an application-layer check is bypassed
  • ➖ More backend-specific complexity (FS create_new vs S3 conditional writes, error mapping)
  • ➖ May require changes to journal/commit semantics if conflicts occur late in the pipeline
2. Allow republish only if bytes/integrity match existing artifact
  • ➕ Could be more forgiving for retries where the client resends identical content
  • ➕ Still prevents backdoored overwrites
  • ➖ Diverges from npm/verdaccio behavior (generally immutable, return 409)
  • ➖ Requires reading/comparing existing tarball and/or integrity, adding I/O and complexity

Recommendation: The PR’s approach (early 409 based on the locally hosted packument, before any tarball write) matches npm/verdaccio semantics and minimizes risk of partial writes. If pnpr is expected to run multiple instances against shared storage, consider a follow-up to add a storage-level ‘no overwrite’ guarantee as defense-in-depth against cross-node publish races.

Files changed (3) +79 / -8

Bug fix (2) +51 / -8
error.rsAdd VersionAlreadyPublished error mapped to HTTP 409 Conflict +14/-0

Add VersionAlreadyPublished error mapped to HTTP 409 Conflict

• Introduces a new RegistryError variant for attempts to publish over an already-hosted version. Wires the new error into log_kind classification and maps it to StatusCode::CONFLICT (409).

pnpr/crates/pnpr/src/error.rs

server.rsDetect hosted version clashes before staging tarballs; refactor prepared attachments +37/-8

Detect hosted version clashes before staging tarballs; refactor prepared attachments

• Refactors publish attachment staging metadata from a positional tuple into a named PreparedAttachment struct that includes the target version. stage_publish now reads the hosted packument once and rejects any incoming attachment whose version is already present locally, returning VersionAlreadyPublished before reserving/writing tarballs.

pnpr/crates/pnpr/src/server.rs

Tests (1) +28 / -0
auth_publish.rsRegression test: republishing an existing version returns 409 and preserves bytes +28/-0

Regression test: republishing an existing version returns 409 and preserves bytes

• Adds a tokio test that publishes [email protected] twice with different tarball bytes. Asserts the second publish returns 409 Conflict and verifies the originally published tarball remains unchanged on disk.

pnpr/crates/pnpr/tests/auth_publish.rs

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pnpr/crates/pnpr/src/server.rs`:
- Around line 1580-1588: The overlap check in server.rs only inspects versions
recovered from hosted_bytes/_attachments, but merge_manifest(existing.as_ref(),
&incoming, now_iso) later merges every key from the full incoming["versions"]
map. Update the validation in the request handling path around hosted_bytes,
prepared, and merge_manifest so it rejects any incoming versions entry that
collides with an already-published version, not just attachment-backed ones. Use
the parsed incoming manifest and the existing registry metadata together to
detect overlaps before calling merge_manifest, and return
RegistryError::VersionAlreadyPublished for any conflicting version.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 114f4f19-2cb1-42dc-81df-6fe67ca2530c

📥 Commits

Reviewing files that changed from the base of the PR and between 54c5c0e and fc62efd.

📒 Files selected for processing (3)
  • pnpr/crates/pnpr/src/error.rs
  • pnpr/crates/pnpr/src/server.rs
  • pnpr/crates/pnpr/tests/auth_publish.rs

Comment thread pnpr/crates/pnpr/src/server.rs Resolved
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Jun 25, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Republish race across replicas 🐞 Bug ⛨ Security
Description
stage_publish rejects already-hosted versions based on a single pre-read of the hosted packument,
but publishes are only serialized “on this instance”, so two replicas can both pass the check and
later finalize to the same tarball/packument paths. Because hosted tarball finalization overwrites
(fs::rename on FS; put on S3), the second writer can still replace previously published
bytes/metadata despite the new 409 check.
Code

pnpr/crates/pnpr/src/server.rs[R1571-1590]

+    let hosted_bytes = state.inner.storage.read_hosted_packument(&name).await?;
+
+    // Reject a re-publish of an already-hosted version: published versions
+    // are immutable, and npm/verdaccio answer a re-publish with 409. Check
+    // every version in the incoming body — not just the ones backed by an
+    // attachment, since merge_manifest below consumes the whole `versions`
+    // map — against the locally hosted packument only (a version that exists
+    // only upstream may still be published here for the first time).
+    if let Some(bytes) = hosted_bytes.as_deref() {
+        let hosted: Value = serde_json::from_slice(bytes).map_err(RegistryError::Json)?;
+        if let Some(hosted_versions) = hosted.get("versions").and_then(Value::as_object)
+            && let Some(incoming_versions) = incoming.get("versions").and_then(Value::as_object)
+            && let Some(clash) =
+                incoming_versions.keys().find(|version| hosted_versions.contains_key(*version))
+        {
+            return Err(RegistryError::VersionAlreadyPublished {
+                package: name.as_str().to_string(),
+                version: clash.clone(),
+            });
+        }
Evidence
The publish path only serializes writers per-process, so multiple pnpr replicas can concurrently
enter stage_publish and pass the pre-flight hosted-packument conflict check. The storage backends
then promote tarballs using overwrite-capable primitives (fs::rename for FS; put for S3), so a
losing racer can still replace already-published bytes/metadata.

pnpr/crates/pnpr/src/server.rs[1390-1394]
pnpr/crates/pnpr/src/server.rs[1571-1590]
pnpr/crates/pnpr/src/storage.rs[614-633]
pnpr/crates/pnpr/src/s3.rs[2-8]
pnpr/crates/pnpr/src/s3.rs[186-194]

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 new `VersionAlreadyPublished` check in `stage_publish` is a TOCTOU pre-flight guard: it reads the hosted packument once and decides to proceed, but there is no cluster-wide serialization. In multi-replica deployments (explicitly supported by the S3 hosted store), another replica can publish the same `name@version` after this check but before finalization, and the current finalization code overwrites existing tarballs/objects.
## Issue Context
- The publish handler’s lock is explicitly per-instance.
- FS tarball promotion uses `fs::rename`, which can overwrite an existing destination on POSIX.
- S3 tarball promotion uses `ObjectStore::put`, which overwrites existing objects.
## Fix Focus Areas
- pnpr/crates/pnpr/src/server.rs[1569-1591]
- pnpr/crates/pnpr/src/server.rs[1389-1395]
- pnpr/crates/pnpr/src/storage.rs[611-633]
- pnpr/crates/pnpr/src/s3.rs[186-194]
## Implementation direction
1. Enforce **non-overwrite** semantics at the hosted-store layer for tarball finalization (and treat “already exists” as a 409).
 - FS backend: replace `rename(tmp, final)` with an operation that fails if `final` exists (e.g., `hard_link(tmp, final)` then delete tmp; or a platform-specific `rename_noreplace`).
 - S3 backend: use a conditional write (e.g., `If-None-Match: *` / “create only”) if the object-store API supports it; otherwise implement an atomic-ish reservation object/lock pattern and fail when already present.
2. Plumb the “already exists” error back up to `stage_publish`/`commit_publishes` and map it to `RegistryError::VersionAlreadyPublished` (409) so the client sees the correct conflict.
3. (Optional but helpful) thread the parsed `version` through `PreparedAttachment` so the 409 can name the exact `version` even when detected during tarball finalization.

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


2. 409 bypass via no attachments ✓ Resolved 🐞 Bug ⛨ Security
Description
stage_publish only checks already-hosted versions by scanning prepared (derived from
_attachments), so a publish body that omits _attachments can still include versions[version]
for an already-hosted version and overwrite that version’s stored packument metadata. This breaks
the intended immutability guarantee because the server will later serve client-visible
dist.tarball URLs based on the overwritten metadata, potentially pointing a version at different
hosted tarball bytes.
Code

pnpr/crates/pnpr/src/server.rs[R1573-1589]

+    let hosted_bytes = state.inner.storage.read_hosted_packument(&name).await?;
+
+    // Reject a re-publish of an already-hosted version: published versions
+    // are immutable, and npm/verdaccio answer a re-publish with 409. Check
+    // only the locally hosted packument, not the upstream-seeded merge
+    // below — a version that exists only upstream may still be published
+    // here for the first time.
+    if let Some(bytes) = hosted_bytes.as_deref() {
+        let hosted: Value = serde_json::from_slice(bytes).map_err(RegistryError::Json)?;
+        if let Some(versions) = hosted.get("versions").and_then(Value::as_object)
+            && let Some(clash) = prepared.iter().find(|entry| versions.contains_key(&entry.version))
+        {
+            return Err(RegistryError::VersionAlreadyPublished {
+                package: name.as_str().to_string(),
+                version: clash.version.clone(),
+            });
+        }
Evidence
The 409 check only consults prepared (attachments), while _attachments can be absent (yielding
empty prepared) and merge_manifest overwrites versions keys on collision; since dist.tarball
rewriting preserves the basename, changing stored dist.tarball changes the tarball URL clients
receive, and the tarball endpoint will serve any hosted tarball bytes for that filename.

pnpr/crates/pnpr/src/server.rs[1526-1550]
pnpr/crates/pnpr/src/server.rs[1566-1617]
pnpr/crates/pnpr/src/publish.rs[46-76]
pnpr/crates/pnpr/src/publish.rs[204-294]
pnpr/crates/pnpr/src/upstream.rs[360-415]
pnpr/crates/pnpr/src/server.rs[828-865]

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 new 409 guard in `stage_publish` only checks conflicts against versions derived from `_attachments` (`prepared`). Since `_attachments` is optional today (missing `_attachments` yields an empty `prepared`), an attacker can submit a publish body that includes `versions["<already hosted>"]` without any attachments; the conflict check is skipped and `merge_manifest` still overwrites the hosted packument’s `versions[version]` entry.
### Issue Context
- `extract_attachments` returns an empty list when `_attachments` is absent.
- `merge_manifest` merges `versions` with “incoming wins on key collision”, so a colliding `versions[v]` overwrites the hosted metadata.
- `rewrite_tarball_urls` uses the stored `dist.tarball` basename when building the URL served to clients; and `serve_tarball` serves any hosted tarball bytes for the requested filename without consulting packument integrity, so changing `dist.tarball` metadata can change the bytes a client fetches for a version.
### Fix Focus Areas
- pnpr/crates/pnpr/src/server.rs[1566-1652]
- pnpr/crates/pnpr/src/publish.rs[46-76]
- pnpr/crates/pnpr/src/publish.rs[220-294]
- pnpr/crates/pnpr/src/upstream.rs[360-415]
### Suggested fix approach
1. In `validate_publish_doc` or `stage_publish`, compute the set of **incoming version keys** from `incoming["versions"]` (require it to be an object, and likely non-empty for publish).
2. When `hosted_bytes` exists, reject with `VersionAlreadyPublished` if **any** incoming version key already exists in the hosted packument’s `versions` map (not just attachment-derived versions).
3. Additionally (recommended), enforce that `_attachments` is present and non-empty for publish, and that every attachment’s parsed version has a matching `versions[version]` entry (you already enforce the `dist` match later during tarball streaming).
4. Add a regression test:
- First publish `[email protected]` normally.
- Second publish sends a body with `versions["1.0.0"]` modified but omits `_attachments`.
- Assert 409 (or 400 if you choose to require attachments) and assert the on-disk packument remains unchanged for `versions["1.0.0"]`.

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



Remediation recommended

3. Hosted packument parsed twice 🐞 Bug ➹ Performance
Description
stage_publish parses the hosted packument JSON once for the conflict check and then parses the
same bytes again to seed the merge, adding avoidable CPU and allocations on every publish when a
hosted packument exists. This can be eliminated by parsing hosted_bytes once and reusing the
parsed Value for both the conflict check and the merge seed.
Code

pnpr/crates/pnpr/src/server.rs[R1573-1602]

+    let hosted_bytes = state.inner.storage.read_hosted_packument(&name).await?;
+
+    // Reject a re-publish of an already-hosted version: published versions
+    // are immutable, and npm/verdaccio answer a re-publish with 409. Check
+    // only the locally hosted packument, not the upstream-seeded merge
+    // below — a version that exists only upstream may still be published
+    // here for the first time.
+    if let Some(bytes) = hosted_bytes.as_deref() {
+        let hosted: Value = serde_json::from_slice(bytes).map_err(RegistryError::Json)?;
+        if let Some(versions) = hosted.get("versions").and_then(Value::as_object)
+            && let Some(clash) = prepared.iter().find(|entry| versions.contains_key(&entry.version))
+        {
+            return Err(RegistryError::VersionAlreadyPublished {
+                package: name.as_str().to_string(),
+                version: clash.version.clone(),
+            });
+        }
+    }
+
// Seed the merge from whatever the upstream knows about the
// package, not just from a cold cache. Without this, a publish
// of a brand-new version of an upstream-only package would
// start from `None` and the newly-written local packument
// would mask every upstream version + dist-tag on subsequent
// reads. `update_dist_tag` already does the same fallback —
// we just mirror it here.
-    let existing_bytes = match state.inner.storage.read_hosted_packument(&name).await? {
+    let existing_bytes = match hosted_bytes {
   Some(bytes) => Some(bytes),
   None => match load_packument_bytes(state, &name).await {
       PackumentLoad::Ok(bytes) => Some(bytes),
Evidence
The code deserializes hosted_bytes into hosted for the conflict check, then later deserializes
existing_bytes (which is hosted_bytes when present) again into existing.

pnpr/crates/pnpr/src/server.rs[1573-1611]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`stage_publish` deserializes the hosted packument twice when it exists: once into `hosted` for the 409 check, and again into `existing` for the merge seed.
### Issue Context
On large packuments, a second full `serde_json::from_slice` is non-trivial (CPU + allocs). This is on the publish path, and the code already has the bytes in memory (`hosted_bytes`).
### Fix Focus Areas
- pnpr/crates/pnpr/src/server.rs[1573-1613]
### Suggested fix approach
- Parse `hosted_bytes` at most once, e.g.:
- `let hosted_value: Option<Value> = hosted_bytes.as_deref().map(serde_json::from_slice).transpose()?;`
- Use `hosted_value.as_ref()` for the conflict check.
- Use `hosted_value` as the `existing` seed when `hosted_bytes` was `Some`, instead of reparsing.
- Keep the behavior the same for the upstream fallback path (when `hosted_bytes` is `None`).

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


Grey Divider

Qodo Logo

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit fc62efd

@codecov-commenter

codecov-commenter commented Jun 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.59%. Comparing base (8fec992) to head (557fdb7).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   pnpm/pnpm#12646      +/-   ##
==========================================
- Coverage   88.59%   88.59%   -0.01%     
==========================================
  Files         338      339       +1     
  Lines       49065    49185     +120     
==========================================
+ Hits        43468    43573     +105     
- Misses       5597     5612      +15     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Integrated-Benchmark Report (Linux)

Commit: 557fdb7d4468

Each scenario reports direct installs and pnpr installs. Bencher consumes pacquet@HEAD and pnpr@HEAD.

Scenario: Isolated linker: fresh restore, cold cache + cold store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.326 ± 0.131 4.177 4.560 1.62 ± 0.07
pacquet@main 4.334 ± 0.127 4.199 4.515 1.62 ± 0.06
pnpr@HEAD 2.716 ± 0.142 2.614 3.022 1.01 ± 0.06
pnpr@main 2.678 ± 0.072 2.609 2.817 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.3264304064,
      "stddev": 0.1312576961366856,
      "median": 4.3123959864,
      "user": 4.030626979999999,
      "system": 2.14744808,
      "min": 4.177281808899999,
      "max": 4.5602084799,
      "times": [
        4.177281808899999,
        4.3653647669,
        4.1794978898999995,
        4.4004332589,
        4.4833765789,
        4.2594272059,
        4.5602084799,
        4.2560357399,
        4.2105971299,
        4.3720812049
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 4.3342097198000005,
      "stddev": 0.12672181404579144,
      "median": 4.2968321479,
      "user": 4.030740079999999,
      "system": 2.1688676800000004,
      "min": 4.1992902919,
      "max": 4.5153654218999995,
      "times": [
        4.504080827899999,
        4.4702253969,
        4.2081632279,
        4.2367149639,
        4.2994819329,
        4.5153654218999995,
        4.3981227479,
        4.2941823629,
        4.2164700238999995,
        4.1992902919
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 2.7158667650000003,
      "stddev": 0.14224537142859708,
      "median": 2.6697211019,
      "user": 3.0404701799999994,
      "system": 1.87540548,
      "min": 2.6141132309,
      "max": 3.0223843249,
      "times": [
        3.0223843249,
        2.6643745569,
        2.9268168649,
        2.6158556089,
        2.6274837089000003,
        2.6141132309,
        2.6154473739,
        2.6750676469,
        2.7141218349000003,
        2.6830024989
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 2.6775603432,
      "stddev": 0.07178414146744966,
      "median": 2.6540549994,
      "user": 3.03698068,
      "system": 1.8828940799999998,
      "min": 2.6086327539000003,
      "max": 2.8174366309,
      "times": [
        2.6317359389,
        2.6763740599,
        2.6216645619,
        2.6142437439,
        2.6892729019000003,
        2.6086327539000003,
        2.7714500149,
        2.7160992619,
        2.6286935639,
        2.8174366309
      ]
    }
  ]
}

Scenario: Isolated linker: fresh restore, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 483.7 ± 8.8 472.9 498.5 1.02 ± 0.03
pacquet@main 475.1 ± 8.0 464.5 492.0 1.00
pnpr@HEAD 557.2 ± 81.3 500.0 730.9 1.17 ± 0.17
pnpr@main 515.6 ± 14.5 502.2 548.3 1.09 ± 0.04
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.48367594632,
      "stddev": 0.008849278246159779,
      "median": 0.48343598772,
      "user": 0.3829475399999999,
      "system": 0.8001028,
      "min": 0.47287393522000004,
      "max": 0.49845879622,
      "times": [
        0.49845879622,
        0.47731261522,
        0.47324862922,
        0.48409383122,
        0.48825111122000003,
        0.48277814422000004,
        0.47287393522000004,
        0.47691653722,
        0.48734930022,
        0.49547656322
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.4751017300200001,
      "stddev": 0.008015011673093627,
      "median": 0.47382587922,
      "user": 0.37806774,
      "system": 0.7904448000000001,
      "min": 0.46446821622,
      "max": 0.49202382422,
      "times": [
        0.47786573322000003,
        0.49202382422,
        0.47583097322,
        0.46854835522,
        0.47380314622,
        0.48390916422,
        0.47131205322,
        0.46446821622,
        0.46940722222000003,
        0.47384861222
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.5571968843199999,
      "stddev": 0.08126641090998783,
      "median": 0.5165937192200001,
      "user": 0.40353043999999993,
      "system": 0.8066941999999999,
      "min": 0.50004896722,
      "max": 0.7308888942200001,
      "times": [
        0.50800101322,
        0.5055227412200001,
        0.50504256822,
        0.50004896722,
        0.50869231522,
        0.5891253202200001,
        0.7308888942200001,
        0.6710477462200001,
        0.5291041542200001,
        0.52449512322
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.51555826102,
      "stddev": 0.014483368904038856,
      "median": 0.51055364022,
      "user": 0.39124644,
      "system": 0.809638,
      "min": 0.5022299832200001,
      "max": 0.5482817832200001,
      "times": [
        0.5115949392200001,
        0.5123819742200001,
        0.5482817832200001,
        0.5022299832200001,
        0.50837840022,
        0.5101314932200001,
        0.5089513922200001,
        0.51097578722,
        0.5354953532200001,
        0.5071615042200001
      ]
    }
  ]
}

Scenario: Isolated linker: fresh install, cold cache + cold store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.628 ± 0.026 4.584 4.682 1.49 ± 0.05
pacquet@main 4.615 ± 0.039 4.538 4.677 1.49 ± 0.05
pnpr@HEAD 3.120 ± 0.103 2.895 3.240 1.01 ± 0.05
pnpr@main 3.099 ± 0.110 2.950 3.231 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.62815405746,
      "stddev": 0.026181000623145108,
      "median": 4.62879430486,
      "user": 4.200150239999999,
      "system": 2.14356454,
      "min": 4.58398131836,
      "max": 4.68181543636,
      "times": [
        4.6229709233600005,
        4.58398131836,
        4.63152567036,
        4.6436872433600005,
        4.63636708936,
        4.68181543636,
        4.63588810436,
        4.620578114360001,
        4.598663735360001,
        4.626062939360001
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 4.61469364326,
      "stddev": 0.03914381238551363,
      "median": 4.62812065236,
      "user": 4.180623239999998,
      "system": 2.15063264,
      "min": 4.537728411360001,
      "max": 4.677417456360001,
      "times": [
        4.63201486136,
        4.59483954736,
        4.537728411360001,
        4.63690305336,
        4.677417456360001,
        4.57778822936,
        4.62855452736,
        4.63948667836,
        4.62768677736,
        4.59451689036
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 3.1202085525600003,
      "stddev": 0.10259566589373105,
      "median": 3.12725592686,
      "user": 3.13406584,
      "system": 2.0222719400000004,
      "min": 2.89494235136,
      "max": 3.23963372436,
      "times": [
        3.21962720736,
        3.15181440836,
        3.23963372436,
        3.09143487436,
        3.15363623336,
        3.09465624136,
        2.89494235136,
        3.10269744536,
        3.03779835636,
        3.21584468336
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 3.09863271916,
      "stddev": 0.11011152021193796,
      "median": 3.1276457988599997,
      "user": 3.12303394,
      "system": 2.0262523400000005,
      "min": 2.94996295436,
      "max": 3.23134660536,
      "times": [
        3.1662780003599997,
        3.22477028836,
        3.07964214336,
        3.15598533036,
        3.23134660536,
        2.96088475236,
        2.94996295436,
        2.9514552643600003,
        3.16669558536,
        3.09930626736
      ]
    }
  ]
}

Scenario: Isolated linker: fresh install, hot cache + hot store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.203 ± 0.010 1.191 1.222 1.02 ± 0.01
pacquet@main 1.178 ± 0.014 1.163 1.200 1.00
pnpr@HEAD 1.278 ± 0.013 1.256 1.296 1.09 ± 0.02
pnpr@main 1.283 ± 0.035 1.241 1.370 1.09 ± 0.03
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.2029873152000001,
      "stddev": 0.009707476993847733,
      "median": 1.2012261013,
      "user": 1.36011948,
      "system": 1.0644886599999999,
      "min": 1.1908779263,
      "max": 1.2219045683,
      "times": [
        1.2219045683,
        1.2065831923,
        1.1996852643,
        1.1919308613,
        1.2007848993,
        1.2101462323,
        1.1908779263,
        1.1947905153,
        1.2115023893,
        1.2016673033
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 1.1779898528,
      "stddev": 0.014285616330603103,
      "median": 1.1724720773000001,
      "user": 1.3448679799999999,
      "system": 1.0198138600000002,
      "min": 1.1631481903,
      "max": 1.2003049673,
      "times": [
        1.1636205443,
        1.1738551013,
        1.1710890533,
        1.1656875623,
        1.2003049673,
        1.1929612053,
        1.1631481903,
        1.1843777993,
        1.1684341093,
        1.1964199953
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.2784014090000002,
      "stddev": 0.012644097794772293,
      "median": 1.2823349843,
      "user": 0.5768421799999999,
      "system": 0.9306733599999998,
      "min": 1.2562782193,
      "max": 1.2957665033,
      "times": [
        1.2821700613,
        1.2879443703,
        1.2824999073,
        1.2811155303000001,
        1.2873875962999999,
        1.2957665033,
        1.2829255072999999,
        1.2562782193,
        1.2643498003,
        1.2635765943
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.2825407366000001,
      "stddev": 0.03478553604297173,
      "median": 1.2764664788000002,
      "user": 0.5773856800000001,
      "system": 0.94482576,
      "min": 1.2413222293000001,
      "max": 1.3702873553,
      "times": [
        1.2639750163,
        1.2413222293000001,
        1.2763030573,
        1.2603243873,
        1.2660154383,
        1.3702873553,
        1.2992680893,
        1.2836844143000001,
        1.2766299003000001,
        1.2875974783
      ]
    }
  ]
}

Scenario: Isolated linker: fresh install, cold cache + hot store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.894 ± 0.018 2.863 2.927 2.27 ± 0.04
pacquet@main 2.905 ± 0.025 2.862 2.944 2.27 ± 0.05
pnpr@HEAD 1.287 ± 0.017 1.267 1.309 1.01 ± 0.02
pnpr@main 1.278 ± 0.023 1.252 1.321 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.8944896572800003,
      "stddev": 0.017897426556065875,
      "median": 2.8918813950800004,
      "user": 1.8377168799999999,
      "system": 1.2511437799999998,
      "min": 2.86345704408,
      "max": 2.9266457220800004,
      "times": [
        2.88453125308,
        2.89042487108,
        2.8982117030800003,
        2.9266457220800004,
        2.86345704408,
        2.8933379190800004,
        2.8903089430800004,
        2.8813516490800004,
        2.89875713808,
        2.9178703300800004
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.90506921468,
      "stddev": 0.025410944507230547,
      "median": 2.8968767820800005,
      "user": 1.8734730799999997,
      "system": 1.22294478,
      "min": 2.8615152250800002,
      "max": 2.94374341508,
      "times": [
        2.8924671820800003,
        2.8964109380800003,
        2.92757073308,
        2.8916011360800002,
        2.91038136908,
        2.8615152250800002,
        2.8973426260800004,
        2.8901431150800003,
        2.94374341508,
        2.93951640708
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.28661527918,
      "stddev": 0.016638655308865744,
      "median": 1.28799973808,
      "user": 0.5741207799999999,
      "system": 0.9602331800000001,
      "min": 1.26690416508,
      "max": 1.30906296508,
      "times": [
        1.29163120108,
        1.29498932808,
        1.30906296508,
        1.30788991708,
        1.27350904908,
        1.26983928708,
        1.26690416508,
        1.3009959070800001,
        1.28436827508,
        1.26696269708
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.2777911017799999,
      "stddev": 0.023289785850452868,
      "median": 1.27273215658,
      "user": 0.5748798799999999,
      "system": 0.9330075800000002,
      "min": 1.25176327308,
      "max": 1.32114795708,
      "times": [
        1.25176327308,
        1.2748224370799999,
        1.31240296808,
        1.26461589308,
        1.25282563308,
        1.28072529708,
        1.26354672608,
        1.32114795708,
        1.27064187608,
        1.2854189570799999
      ]
    }
  ]
}

@github-actions

github-actions Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Branchpr/12646
Testbedpacquet
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
milliseconds (ms)
(Result Δ%)
Upper Boundary
milliseconds (ms)
(Limit %)
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
🚷 view threshold
4,628.15 ms
(-2.92%)Baseline: 4,767.28 ms
5,720.74 ms
(80.90%)
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
🚷 view threshold
2,894.49 ms
(-4.82%)Baseline: 3,041.08 ms
3,649.30 ms
(79.32%)
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
🚷 view threshold
1,202.99 ms
(-10.82%)Baseline: 1,348.95 ms
1,618.74 ms
(74.32%)
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
🚷 view threshold
4,326.43 ms
(-7.41%)Baseline: 4,672.86 ms
5,607.43 ms
(77.16%)
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
🚷 view threshold
483.68 ms
(-22.93%)Baseline: 627.61 ms
753.14 ms
(64.22%)
🐰 View full continuous benchmarking report in Bencher

@github-actions

github-actions Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Branchpr/12646
Testbedpnpr

⚠️ WARNING: No Threshold found!

Without a Threshold, no Alerts will ever be generated.

Click here to create a new Threshold
For more information, see the Threshold documentation.
To only post results if a Threshold exists, set the --ci-only-thresholds flag.

Click to view all benchmark results
BenchmarkLatencymilliseconds (ms)
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
3,120.21 ms
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
1,286.62 ms
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
1,278.40 ms
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
2,715.87 ms
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
557.20 ms
🐰 View full continuous benchmarking report in Bencher

…chment-backed ones

The 409 guard only iterated attachment-backed versions, but merge_manifest consumes the entire
incoming `versions` map. A client could smuggle a modified entry for an already-hosted version
(e.g. 1.0.0) alongside a real attachment for 1.0.1, slip past the guard, and overwrite the hosted
metadata. Check every version in the incoming body against the hosted packument instead.
PreparedAttachment no longer needs to carry the version. Addresses the review.

Co-authored-by: Claude <[email protected]>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
pnpr/crates/pnpr/tests/auth_publish.rs (1)

286-286: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Strengthen the regression assertion to check no partial publish side-effects.

After asserting 409 CONFLICT, also assert storage/packument still does not contain 1.0.1 (and/or no mypkg-1.0.1.tgz exists). This makes the test prove rollback/immutability, not just status code.

As per path instructions, “Ensure tests prove the behavior change (regression test that fails without the fix, meaningful assertions)”.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pnpr/crates/pnpr/tests/auth_publish.rs` at line 286, The regression test in
auth_publish should do more than assert StatusCode::CONFLICT from
app.oneshot(smuggle); after the conflict response, add assertions using the
existing storage/packument checks to verify that version 1.0.1 was not written
and that no mypkg-1.0.1.tgz artifact exists. Update the test near the publish
flow in auth_publish.rs so it proves rollback/immutability via the same helpers
and package state used elsewhere in the test suite.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@pnpr/crates/pnpr/tests/auth_publish.rs`:
- Line 286: The regression test in auth_publish should do more than assert
StatusCode::CONFLICT from app.oneshot(smuggle); after the conflict response, add
assertions using the existing storage/packument checks to verify that version
1.0.1 was not written and that no mypkg-1.0.1.tgz artifact exists. Update the
test near the publish flow in auth_publish.rs so it proves rollback/immutability
via the same helpers and package state used elsewhere in the test suite.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 2646f999-0ee1-4875-a0f3-cccae7ab7d19

📥 Commits

Reviewing files that changed from the base of the PR and between fc62efd and 557fdb7.

📒 Files selected for processing (2)
  • pnpr/crates/pnpr/src/server.rs
  • pnpr/crates/pnpr/tests/auth_publish.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • pnpr/crates/pnpr/src/server.rs

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Jun 25, 2026
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 557fdb7

Comment on lines +1571 to +1590
let hosted_bytes = state.inner.storage.read_hosted_packument(&name).await?;

// Reject a re-publish of an already-hosted version: published versions
// are immutable, and npm/verdaccio answer a re-publish with 409. Check
// every version in the incoming body — not just the ones backed by an
// attachment, since merge_manifest below consumes the whole `versions`
// map — against the locally hosted packument only (a version that exists
// only upstream may still be published here for the first time).
if let Some(bytes) = hosted_bytes.as_deref() {
let hosted: Value = serde_json::from_slice(bytes).map_err(RegistryError::Json)?;
if let Some(hosted_versions) = hosted.get("versions").and_then(Value::as_object)
&& let Some(incoming_versions) = incoming.get("versions").and_then(Value::as_object)
&& let Some(clash) =
incoming_versions.keys().find(|version| hosted_versions.contains_key(*version))
{
return Err(RegistryError::VersionAlreadyPublished {
package: name.as_str().to_string(),
version: clash.clone(),
});
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

1. Republish race across replicas 🐞 Bug ⛨ Security

stage_publish rejects already-hosted versions based on a single pre-read of the hosted packument,
but publishes are only serialized “on this instance”, so two replicas can both pass the check and
later finalize to the same tarball/packument paths. Because hosted tarball finalization overwrites
(fs::rename on FS; put on S3), the second writer can still replace previously published
bytes/metadata despite the new 409 check.
Agent Prompt
## Issue description
The new `VersionAlreadyPublished` check in `stage_publish` is a TOCTOU pre-flight guard: it reads the hosted packument once and decides to proceed, but there is no cluster-wide serialization. In multi-replica deployments (explicitly supported by the S3 hosted store), another replica can publish the same `name@version` after this check but before finalization, and the current finalization code overwrites existing tarballs/objects.

## Issue Context
- The publish handler’s lock is explicitly per-instance.
- FS tarball promotion uses `fs::rename`, which can overwrite an existing destination on POSIX.
- S3 tarball promotion uses `ObjectStore::put`, which overwrites existing objects.

## Fix Focus Areas
- pnpr/crates/pnpr/src/server.rs[1569-1591]
- pnpr/crates/pnpr/src/server.rs[1389-1395]
- pnpr/crates/pnpr/src/storage.rs[611-633]
- pnpr/crates/pnpr/src/s3.rs[186-194]

## Implementation direction
1. Enforce **non-overwrite** semantics at the hosted-store layer for tarball finalization (and treat “already exists” as a 409).
   - FS backend: replace `rename(tmp, final)` with an operation that fails if `final` exists (e.g., `hard_link(tmp, final)` then delete tmp; or a platform-specific `rename_noreplace`).
   - S3 backend: use a conditional write (e.g., `If-None-Match: *` / “create only”) if the object-store API supports it; otherwise implement an atomic-ish reservation object/lock pattern and fail when already present.
2. Plumb the “already exists” error back up to `stage_publish`/`commit_publishes` and map it to `RegistryError::VersionAlreadyPublished` (409) so the client sees the correct conflict.
3. (Optional but helpful) thread the parsed `version` through `PreparedAttachment` so the 409 can name the exact `version` even when detected during tarball finalization.

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

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 557fdb7

@YESHYUNGSEOK

Copy link
Copy Markdown
Contributor Author

Thanks @qodo — dispositions:

  • 409 bypass via no attachments ✅ Fixed in 557fdb7 — the guard now checks every version in the incoming versions map against the hosted packument, not just attachment-backed ones, with a regression test for the smuggled-version case.
  • Hosted packument parsed twice: minor — stage_publish reads the hosted bytes once but parses them once for the conflict check and again as the merge seed. Low cost on the (non-hot) publish path; can be collapsed to a single parse in a follow-up.
  • Republish race across replicas: architectural — the per-instance package lock can't span replicas; this is the same multi-replica lost-update class tracked in pnpr: make remaining local state pluggable for stateless / serverless deployment tasks#21 and is out of scope for this single-instance 409 guard.

Written by an agent (Claude Code, claude-opus-4-8).

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Thanks @qodo — dispositions:

  • 409 bypass via no attachments ✅ Fixed in 557fdb7 — the guard now checks every version in the incoming versions map against the hosted packument, not just attachment-backed ones, with a regression test for the smuggled-version case.
  • Hosted packument parsed twice: minor — stage_publish reads the hosted bytes once but parses them once for the conflict check and again as the merge seed. Low cost on the (non-hot) publish path; can be collapsed to a single parse in a follow-up.
  • Republish race across replicas: architectural — the per-instance package lock can't span replicas; this is the same multi-replica lost-update class tracked in pnpr: make remaining local state pluggable for stateless / serverless deployment tasks#21 and is out of scope for this single-instance 409 guard.

Written by an agent (Claude Code, claude-opus-4-8).

Sounds good — thanks for the clear dispositions.

  • 409 bypass via no attachments: resolved in 557fdb7d.
  • Hosted packument parsed twice: acknowledged as a low-cost follow-up.
  • Republish race across replicas: agreed, architectural and out of scope for this guard.

No further action needed on my side.

@zkochan

zkochan commented Jun 25, 2026

Copy link
Copy Markdown
Member

Thanks! This was really important change.

@zkochan
zkochan added this pull request to the merge queue Jun 25, 2026
Merged via the queue into pnpm:main with commit deb6d8e Jun 25, 2026
34 checks passed
zkochan added a commit that referenced this pull request Jun 25, 2026
#12646 rejects any re-PUT of an already-hosted version with 409 to
keep published content immutable. But `pnpm deprecate`/`undeprecate` work by
GET-ing the packument, flipping the `deprecated` flag, and re-PUT-ting it
with no attachments and the hosted `dist` unchanged. That metadata-only
update tripped the 409 guard, breaking `test/deprecate.ts` across the e2e
suite (on every PR, via the merge commit).

Narrow the guard to reject only a *content* re-publish of a clashing
version: one that carries a new tarball (an attachment) or changes
`dist.integrity`. Integrity is the content anchor clients verify against;
the `tarball` URL is rewritten on read, so a faithful deprecate re-PUT
carries a different URL but the same integrity and must be allowed. A
metadata-only clash now passes, and `merge_manifest` preserves the hosted
version's `dist`, so a metadata update can never repoint a version's
integrity or tarball.

Adds pnpr integration tests: a deprecate-style update is allowed and keeps
the hosted `dist`; the attachment re-publish and the no-attachment
integrity smuggle stay 409.
zkochan added a commit that referenced this pull request Jun 25, 2026
#12646 rejects any re-PUT of an already-hosted version with 409 to
keep published content immutable. But `pnpm deprecate`/`undeprecate` work by
GET-ing the packument, flipping the `deprecated` flag, and re-PUT-ting it
with no attachments and the hosted `dist` unchanged. That metadata-only
update tripped the 409 guard, breaking `test/deprecate.ts` across the e2e
suite (on every PR, via the merge commit).

Narrow the guard to reject only a *content* re-publish of a clashing
version: one that carries a new tarball (an attachment) or changes
`dist.integrity`. Integrity is the content anchor clients verify against;
the `tarball` URL is rewritten on read, so a faithful deprecate re-PUT
carries a different URL but the same integrity and must be allowed.

A metadata-only clash now passes, but `merge_versions` keeps the hosted
version's manifest and applies only the mutable `deprecated` flag (set it,
or remove it for undeprecate). So a metadata re-PUT can't alter `dist` or
any resolution-relevant field (`dependencies`/`bin`/`engines`/...) of an
already-published version — immutability holds for everything clients
resolve from, not just the tarball. A malformed incoming version entry is
ignored, leaving the hosted manifest untouched.

Adds pnpr integration tests: a deprecate-style update is allowed and keeps
the hosted `dist`; a metadata re-PUT cannot mutate `dependencies`; the
attachment re-publish and the no-attachment integrity smuggle stay 409.
zkochan added a commit that referenced this pull request Jun 25, 2026
#12646 rejects any re-PUT of an already-hosted version with 409 to
keep published content immutable. But `pnpm deprecate`/`undeprecate` work by
GET-ing the packument, flipping the `deprecated` flag, and re-PUT-ting it
with no attachments and the hosted `dist` unchanged. That metadata-only
update tripped the 409 guard, breaking `test/deprecate.ts` across the e2e
suite (on every PR, via the merge commit).

Narrow the guard to reject only a *content* re-publish of a clashing
version: one that carries a new tarball (an attachment) or changes
`dist.integrity`. Integrity is the content anchor clients verify against;
the `tarball` URL is rewritten on read, so a faithful deprecate re-PUT
carries a different URL but the same integrity and must be allowed.

A metadata-only clash now passes, but `merge_versions` keeps the hosted
version's manifest and applies only the mutable `deprecated` flag (set it,
or remove it for undeprecate). So a metadata re-PUT can't alter `dist` or
any resolution-relevant field (`dependencies`/`bin`/`engines`/...) of an
already-published version — immutability holds for everything clients
resolve from, not just the tarball. A malformed incoming version entry is
ignored, leaving the hosted manifest untouched.

Adds pnpr integration tests: a deprecate-style update is allowed and keeps
the hosted `dist`; a metadata re-PUT cannot mutate `dependencies`; the
attachment re-publish and the no-attachment integrity smuggle stay 409.
zkochan added a commit that referenced this pull request Jun 25, 2026
#12646 rejects any re-PUT of an already-hosted version with 409 to
keep published content immutable. But `pnpm deprecate`/`undeprecate` work by
GET-ing the packument, flipping the `deprecated` flag, and re-PUT-ting it
with no attachments and the hosted `dist` unchanged. That metadata-only
update tripped the 409 guard, breaking `test/deprecate.ts` across the e2e
suite (on every PR, via the merge commit).

Narrow the guard to reject only a *content* re-publish of a clashing
version: one that carries a new tarball (an attachment) or changes
`dist.integrity`. Integrity is the content anchor clients verify against;
the `tarball` URL is rewritten on read, so a faithful deprecate re-PUT
carries a different URL but the same integrity and must be allowed.

A metadata-only clash now passes, but `merge_versions` keeps the hosted
version's manifest and applies only the mutable `deprecated` flag (set it,
or remove it for undeprecate). So a metadata re-PUT can't alter `dist` or
any resolution-relevant field (`dependencies`/`bin`/`engines`/...) of an
already-published version — immutability holds for everything clients
resolve from, not just the tarball. A malformed incoming version entry is
ignored, leaving the hosted manifest untouched.

Adds pnpr integration tests: a deprecate-style update is allowed and keeps
the hosted `dist`; a metadata re-PUT cannot mutate `dependencies`; the
attachment re-publish and the no-attachment integrity smuggle stay 409.
zkochan added a commit that referenced this pull request Jun 25, 2026
#12646 rejects any re-PUT of an already-hosted version with 409 to
keep published content immutable. But `pnpm deprecate`/`undeprecate` work by
GET-ing the packument, flipping the `deprecated` flag, and re-PUT-ting it
with no attachments and the hosted `dist` unchanged. That metadata-only
update tripped the 409 guard, breaking `test/deprecate.ts` across the e2e
suite (on every PR, via the merge commit).

Narrow the guard to reject only a *content* re-publish of a clashing
version: one that carries a new tarball (an attachment) or changes
`dist.integrity`. Integrity is the content anchor clients verify against;
the `tarball` URL is rewritten on read, so a faithful deprecate re-PUT
carries a different URL but the same integrity and must be allowed.

A metadata-only clash now passes, but `merge_versions` keeps the hosted
version's manifest and applies only the mutable `deprecated` flag (set it,
or remove it for undeprecate). So a metadata re-PUT can't alter `dist` or
any resolution-relevant field (`dependencies`/`bin`/`engines`/...) of an
already-published version — immutability holds for everything clients
resolve from, not just the tarball. Immutability keys off the locally
hosted packument, not the merge seed (which may be the upstream packument),
so a first local publish of an upstream-only version still takes the
incoming manifest and stays consistent with the uploaded tarball. A
malformed incoming version entry is ignored, leaving the hosted manifest
untouched.

Adds pnpr integration tests: a deprecate-style update is allowed and keeps
the hosted `dist`; a metadata re-PUT cannot mutate `dependencies`; the
attachment re-publish and the no-attachment integrity smuggle stay 409.
zkochan added a commit that referenced this pull request Jun 25, 2026
#12646 rejects any re-PUT of an already-hosted version with 409 to
keep published content immutable. But `pnpm deprecate`/`undeprecate` work by
GET-ing the packument, flipping the `deprecated` flag, and re-PUT-ting it
with no attachments and the hosted `dist` unchanged. That metadata-only
update tripped the 409 guard, breaking `test/deprecate.ts` across the e2e
suite (on every PR, via the merge commit).

Narrow the guard to reject only a *content* re-publish of a clashing
version: one that carries a new tarball (an attachment) or changes
`dist.integrity`. Integrity is the content anchor clients verify against;
the `tarball` URL is rewritten on read, so a faithful deprecate re-PUT
carries a different URL but the same integrity and must be allowed.

A metadata-only clash now passes, but `merge_versions` keeps the hosted
version's manifest and applies only the mutable `deprecated` flag (set it,
or remove it for undeprecate). So a metadata re-PUT can't alter `dist` or
any resolution-relevant field (`dependencies`/`bin`/`engines`/...) of an
already-published version — immutability holds for everything clients
resolve from, not just the tarball. Immutability keys off the locally
hosted packument, not the merge seed (which may be the upstream packument),
so a first local publish of an upstream-only version still takes the
incoming manifest and stays consistent with the uploaded tarball. A
malformed incoming version entry is ignored, leaving the hosted manifest
untouched.

The guard also rejects (400) an incoming version that is not already hosted
and ships no attachment: a metadata-only PUT must not inject a tarball-less
version entry, which would advertise a version with no hosted tarball
(installs 404) and block a later real publish of it (409). A hosted
packument is served as-is, so anything absent from it is genuinely new here
even if it exists upstream.

Adds pnpr integration tests: a deprecate-style update is allowed and keeps
the hosted `dist`; a metadata re-PUT cannot mutate `dependencies`, corrupt a
hosted version with a malformed entry, or inject a tarball-less version; the
attachment re-publish and the no-attachment integrity smuggle stay 409.
zkochan added a commit that referenced this pull request Jun 25, 2026
…12659)

#12646 rejects any re-PUT of an already-hosted version with 409 to
keep published content immutable. But `pnpm deprecate`/`undeprecate` work by
GET-ing the packument, flipping the `deprecated` flag, and re-PUT-ting it
with no attachments and the hosted `dist` unchanged. That metadata-only
update tripped the 409 guard, breaking test/deprecate.ts across the e2e
suite (on every PR, via the merge commit).

Narrow the guard to reject only a content re-publish of a clashing version:
one that carries a new tarball (an attachment) or changes `dist.integrity`.
Integrity is the content anchor clients verify against; the `tarball` URL is
rewritten on read, so a faithful deprecate re-PUT carries a different URL but
the same integrity and must be allowed. A metadata-only clash now passes, and
merge_manifest preserves the hosted version's `dist`, so a metadata update can
never repoint a version's integrity or tarball.

Adds pnpr integration tests: a deprecate-style update is allowed and keeps the
hosted `dist`; the attachment re-publish and the no-attachment integrity
smuggle stay 409.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product: pnpr reviewed: coderabbit CodeRabbit submitted an approving review state: automerge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants