Repository navigation
Imports: refuse a NuGet feed's .nupkg that is not the listed id and version - #843
Merged
Merged
Conversation
…ersion A feed import passed no expected identity to the hosted write path, so a feed whose flat container served another package's file for a listed version stored that other package and, with on_conflict overwrite, replaced a version Forge already held. Every package import now passes the listed id and version, like the npm and apt imports, and the item fails with "the package is ..., not ...". Fixes #813 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012e6DJb9nERqzebpXXBCBRg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #813
Problem
A NuGet feed import (
PackageSource::Feed) leftImportOptions::expectedunset, sopublish_stagednever checked that the downloaded.nupkgwas the id and version the feed listed. A feed could serve another package's file for a listed version. Withskip, the import stored the other package. Withoverwrite, it replaced a version Forge already held. The registration's SHA-512 check didn't help, because the same feed lists that hash.Change
copy_package(crates/server/src/import/mod.rs) now passesexpected: Some((item.name, item.version))for every package source, as the npm and apt imports already do. A mismatched package is refused, and the item fails with "the package is X v, not Y v".publish_stageduses NuGet'slower_idandnormalize_version. The feed's flat container lists versions in lowercase, but normalization lowercases prerelease labels and drops build metadata, so case and version-format differences still compare equal. The only package sources areFeedandNpm. A Nexus or other NuGet v3 source is read through the sameFeed, so it is covered too.docs/changes/2.2.0/813.security.md.Tests
a_feed_cannot_plant_another_package_under_a_listed_version(crates/server/tests/import.rs). It sets up a feed that lists Acme.Foo 1.0.0 and Acme.Bar 1.0.0, with registration SHA-512s that match the files served. Those files are actually other bytes of Acme.Victim 2.0.0 (which Forge holds) and Acme.Fresh 3.0.0 (which Forge lacks). The test runs the import withskipand withoverwrite. In both runs, both items fail with "the package is …, not …", nothing is stored under the listed or the planted ids, and Forge keeps its own Acme.Victim bytes. Without the fix this test fails: Acme.Fresh gets imported.cargo test -p forge-server --test import: all 17 tests pass, including the existing NuGet and npm import tests.cargo clippy -p forge-server --all-targets -- -D warnings,cargo fmt --all --checkandcargo xtask changelog --checkare clean.This change has no admin-API or UI part.
Generated by Claude Code