-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Description
cargo publish --index <url> bypasses package.publish = [...] restrictions.
When publishing via --index, validate_registry() skips registry name assignment (RegistryOrIndex::Index(_) → None), which causes the publish restriction enforcement block to be skipped entirely.
As a result, crates configured as internal-only can be packaged and processed for publishing to unintended registries.
Steps to Reproduce (Safe: uses --dry-run)
mkdir repro && cd repro
cargo new internal_crate --bin
cd internal_crateCargo.toml:
[package]
name = "internal_crate"
version = "0.1.0"
edition = "2021"
publish = ["internal-only"]git init .
git add .
git commit -m "PoC"Control case (restriction applied):
cargo publish --dry-runBypass via --index:
cargo publish --dry-run --index "https://github.com/rust-lang/crates.io-index" --allow-dirtyActual Behavior
The publish process proceeds through:
Packaging → Verifying → Uploading
(interrupted only due to --dry-run).
Expected Behavior
Publish should be rejected when publish = [...] restrictions are present, regardless of --index.
Root Cause
validate_registry() maps RegistryOrIndex::Index(_) to None:
Some(RegistryOrIndex::Registry(r)) => Some(r.as_str()),
None => Some(CRATES_IO_REGISTRY),
Some(RegistryOrIndex::Index(_)) => None,Restriction enforcement only happens when registry name is Some(_), so using --index suppresses checks.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status