Repository navigation
fix(pnpr): reject re-publishing an existing version with 409 Conflict - #12646
Conversation
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]>
📝 WalkthroughWalkthroughThe 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. ChangesRepublish conflict handling
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
PR Summary by QodoReject re-publishing an already-hosted pnpr version with HTTP 409 Conflict Description
Diagram
High-Level Assessment
Files changed (3)
|
There was a problem hiding this comment.
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
📒 Files selected for processing (3)
pnpr/crates/pnpr/src/error.rspnpr/crates/pnpr/src/server.rspnpr/crates/pnpr/tests/auth_publish.rs
Code Review by Qodo
1. Republish race across replicas
|
|
Code review by qodo was updated up to the latest commit fc62efd |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
Integrated-Benchmark Report (Linux)Commit: Each scenario reports direct installs and pnpr installs. Bencher consumes pacquet@HEAD and pnpr@HEAD. Scenario: Isolated linker: fresh restore, cold cache + cold store
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
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
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
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
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
]
}
]
} |
|
| Branch | pr/12646 |
| Testbed | pacquet |
Click to view all benchmark results
| Benchmark | Latency | Benchmark 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%) |
|
| Branch | pr/12646 |
| Testbed | pnpr |
⚠️ 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-thresholdsflag.
Click to view all benchmark results
| Benchmark | Latency | milliseconds (ms) |
|---|---|---|
| isolated-linker.fresh-install.cold-cache.cold-store | 📈 view plot | 3,120.21 ms |
| isolated-linker.fresh-install.cold-cache.hot-store | 📈 view plot | 1,286.62 ms |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot | 1,278.40 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot | 2,715.87 ms |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot | 557.20 ms |
…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]>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pnpr/crates/pnpr/tests/auth_publish.rs (1)
286-286: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winStrengthen the regression assertion to check no partial publish side-effects.
After asserting
409 CONFLICT, also assert storage/packument still does not contain1.0.1(and/or nomypkg-1.0.1.tgzexists). 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
📒 Files selected for processing (2)
pnpr/crates/pnpr/src/server.rspnpr/crates/pnpr/tests/auth_publish.rs
🚧 Files skipped from review as they are similar to previous changes (1)
- pnpr/crates/pnpr/src/server.rs
|
Code review by qodo was updated up to the latest commit 557fdb7 |
| 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(), | ||
| }); | ||
| } |
There was a problem hiding this comment.
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
|
Code review by qodo was updated up to the latest commit 557fdb7 |
|
Thanks @qodo — dispositions:
Written by an agent (Claude Code, claude-opus-4-8). |
Sounds good — thanks for the clear dispositions.
No further action needed on my side. |
|
Thanks! This was really important change. |
#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.
#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.
#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.
#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.
#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.
#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.
…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.
Summary
merge_objectsunconditionally overwrote an existingversions[v]entry, andstage_publishrenamed the new tarball over the old one, so a user with Publish access could re-publish
name@versionwith backdoored bytes and a freshdist.integrity. Clients that pinned the oldhash in their lockfile then hit
EINTEGRITY; clients without a lockfile silently fetched thereplaced bytes. npm and verdaccio treat a published version as immutable and answer a re-publish
with
409 Conflict.stage_publishnow reads the hosted packument once and rejects the publish with a newVersionAlreadyPublishederror (HTTP 409) when any incoming version is already hosted — before anytarball 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
ValidatedPublishvia a namedPreparedAttachmentstruct (replacing the former positional tuple).
Squash Commit Body
Checklist
republishing_an_existing_version_is_rejected_with_conflictasserts the second publish gets 409 and the original tarball bytes are untouched on disk.
(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
name@version, returning a clear409 Conflictresponse.Bug Fixes