Skip to content
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

publish: Use description, license and license_file fields from embedded Cargo.toml file #7194

Merged
merged 4 commits into from
Sep 27, 2023

Conversation

Turbo87
Copy link
Member

@Turbo87 Turbo87 commented Sep 27, 2023

This PR changes our handling of the description, license and license_file fields so that they are read from the Cargo.toml file embedded in the crate tarball, instead of the metadata JSON blob.

This is another step forward towards avoiding issues like https://blog.vlt.sh/blog/the-massive-hole-in-the-npm-ecosystem in the Rust ecosystem. Note that, compared to e.g. npm, this is currently not exploitable due to the way cargo works, but it is still confusing to our users if the metadata does not match what is actually in the tarball.

This change required a small reordering of things in the publish endpoint. Specifically, the publish size limit is read from the database earlier than previously, which could potentially cause a race condition, but from what I can tell this race condition should not matter in practice (see commit message for details). Similarly, the tarball analysis step now happens before we run any INSERT queries on the database, since the tarball analysis result is now needed before we can insert anything. Thirdly, the description and license validation now happens after the tarball analysis for obvious reasons.

@Turbo87 Turbo87 added C-internal 🔧 Category: Nonessential work that would make the codebase more consistent or clear A-backend ⚙️ labels Sep 27, 2023
@Turbo87 Turbo87 requested a review from a team September 27, 2023 11:16
@Turbo87 Turbo87 force-pushed the desc-license-from-manifest branch from 767b9c4 to c8fc07f Compare September 27, 2023 12:00
@Turbo87 Turbo87 force-pushed the desc-license-from-manifest branch from c8fc07f to 9c9599e Compare September 27, 2023 12:14
@Rustin170506
Copy link
Member

/cc myself

I will take a look tomorrow.

@bors
Copy link
Contributor

bors commented Sep 27, 2023

☔ The latest upstream changes (presumably c2946d9) made this pull request unmergeable. Please resolve the merge conflicts.

There are a couple of cases to consider here:

- if a krate with the same name exists, `existing_crate` will be `Some(_)` and the `max_upload_size` value is used.
- if no krate with the same name exists yet, `existing_crate` will be `None` and the default size limits are used.
- if no krate with the same name exists yet and there are two concurrent publish requests, the default size limits are used. this should be fine since there is no way to increase the size limits during publish or via the API in general.

tl;dr there is a potential race condition here, but it doesn't matter for this specific case
…SERT` SQL queries

This will allow us to use the data from the `Cargo.toml` file in the tarball instead of the JSON metadata blob.
…file` fields from embedded `Cargo.toml` file

... instead of the metadata JSON blob
…icense_file` fields

These fields are no longer read by our server, so we can skip the deserialization step.
@Turbo87 Turbo87 force-pushed the desc-license-from-manifest branch from 9c9599e to d48b5ad Compare September 27, 2023 12:57
Copy link
Contributor

@LawnGnome LawnGnome left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One trivial question, but no substantive concerns. LGTM! 👍

src/controllers/krate/publish.rs Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-backend ⚙️ C-internal 🔧 Category: Nonessential work that would make the codebase more consistent or clear
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants