-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecate non-authoritative information in the registry Publish API #14492
Comments
Might be good for us to also provide conversion functions in a low level crate between the relevant types. This would require pulling our |
I'd change the documentation to tell registry implementers to skip over the JSON blob entirely, and not even bother decoding it. After some deprecation time and/or some future edition Cargo could send 0-length field there. |
Sorry, I meant conversion from |
edit: nevermind, registry URLs are in |
I agree that we should maintain a library for converting from a crate file to the index row. Certainly by the time we've done that, if not before, the documentation should recommend reading the crate file directly. If your registry is not written in Rust, then the official crate doesn't do you much good. Similarly, if militias upload is not part of your threat model, then the metadata blob can be trusted. Not including this in your threat model is reasonable for private registries, if the attacker can publish malicious code to the registry there is much worse they can do. If both apply, the metadata is a reasonable choice over trying to reimplement the |
Problem
The registry protocol takes a JSON with metadata when publishing crates: https://doc.rust-lang.org/cargo/reference/registry-web-api.html#publish
This metadata is meant to contain a summary of
Cargo.toml
metadata. The problem is that nothing stops rogue clients from sending different metadata that doesn't match theCargo.toml
. If the registry uses this JSON, and doesn't validateCargo.toml
in the tarball, this can be used to bypass policy checks done at publishing time, e.g. sneak in dependencies from other registries that wouldn't be allowed otherwise.Fortunately, crates.io has already fixed this vulnerability: rust-lang/crates.io#7238
The only potentially useful not-entirely-redundant field in this metadata was the
readme
, but that has been fixed in Cargo: #5911Since a robust implementation of a registry has to extract the
Cargo.toml
and validate it anyway, the redundant metadata in the publish call is just a footgun. It's not an authoritative source of data. Validating that it matchesCargo.toml
is just an unnecessary work for a registry, since doing that requires obtaining the authoritative data fromCargo.toml
anyway, and at that point it's easiest to just ignore the uploaded JSON. Generating and sending redundant data that should be ignored is also wasteful for the clients. The data is also in a different format thanCargo.toml
with bug-prone quirks likeexplicit_name_in_toml
that has its logic backwards compared to thepackage
field in the manifest.Possible Solution(s)
For backwards compatibility with other registries Cargo will probably have to continue sending this JSON for a while, but at least the documentation can be updated to instruct registry implementers to ignore the submitted JSON and read the
Cargo.toml
from the tarball instead (there are crates for this, so it's easy).https://doc.rust-lang.org/cargo/reference/registry-web-api.html#publish
The text was updated successfully, but these errors were encountered: