Skip to content

cargo publish --index bypasses package.publish restrictions #16231

@AryzXploit

Description

@AryzXploit

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_crate

Cargo.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-run

Bypass via --index:

cargo publish --dry-run --index "https://github.com/rust-lang/crates.io-index" --allow-dirty

Actual 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

No one assigned

    Labels

    A-edition-nextArea: may require a breaking change over an editionC-bugCategory: bugCommand-publishS-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions