Skip to content

fix: strip CR from cargo:token-from-stdout#17081

Merged
arlosi merged 2 commits into
rust-lang:masterfrom
weihanglo:creds
Jun 8, 2026
Merged

fix: strip CR from cargo:token-from-stdout#17081
arlosi merged 2 commits into
rust-lang:masterfrom
weihanglo:creds

Conversation

@weihanglo

Copy link
Copy Markdown
Member

What does this PR try to resolve?

Helpers on Windows commonly emit a token terminated by \r\n.
The adaptor only strips \n and leaves leaving a trailing \r.
In 1.96 the registry network refactor started using http::HeaderValue,
and it rejects trailing \r when constructing the request.
So, users see a confusing "failed to parse header value" message.
They are stuck and cannot send the request.

This fix simply trims trailing \r after trimming \n.

I have no idea how AWS CodeArtifact works with trailing \r before.
Perhaps it trims those as well.

Fixes #14073
Fixes #17072

How to test and review this PR?

One regression test is added.

Also, before #16745 Cargo constructed request as-is and didn't reject invalid headers (and libcurl doesn't seem to check it?). Since http::HeaderValue started doing a stricter validation, probably we should take the advantage and apply check_token to all alternate registries?

weihanglo added 2 commits June 6, 2026 00:05
Helpers on Windows commonly emit a token terminated by `\r\n`.
The adaptor only strips `\n` and leaves leaving a trailing `\r`.
In 1.96 the registry network refactor started using `http::HeaderValue`,
and it rejects trailing `\r` when constructing the request.
So, users see a confusing "failed to parse header value" message.
They are stuck and cannot send the request.
Helpers on Windows commonly emit a token terminated by `\r\n`.
The adaptor only strips `\n` and leaves leaving a trailing `\r`.
In 1.96 the registry network refactor started using `http::HeaderValue`,
and it rejects trailing `\r` when constructing the request.
So, users see a confusing "failed to parse header value" message.
They are stuck and cannot send the request.

This fix simply trims trailing `\r` after trimming `\n`.

I have no idea how AWS CodeArtifact works with trailing `\r` before.
Perhaps it trims those as well.

Fixes rust-lang#14073
Fixes rust-lang#17072
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 6, 2026
@rustbot

rustbot commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator

r? @epage

rustbot has assigned @epage.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ehuss, @epage, @weihanglo
  • @ehuss, @epage, @weihanglo expanded to ehuss, epage, weihanglo
  • Random selection from ehuss, epage

@weihanglo weihanglo changed the title test: CRLF behavior of cargo:token-from-stdout fix: strip CR from cargo:token-from-stdout Jun 6, 2026
@weihanglo weihanglo changed the title fix: strip CR from cargo:token-from-stdout fix: strip CR from cargo:token-from-stdout Jun 6, 2026

@arlosi arlosi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree that we should be using check_token whenever we're reading in a token.

Newline trimming for cargo login also probably makes sense.

View changes since this review

@weihanglo

Copy link
Copy Markdown
Member Author

I agree that we should be using check_token whenever we're reading in a token.

I hesitate on that because our check_token implementation is stricter than http crate

@arlosi arlosi added this pull request to the merge queue Jun 8, 2026
Merged via the queue into rust-lang:master with commit 0140b9b Jun 8, 2026
29 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 8, 2026
@weihanglo weihanglo deleted the creds branch June 10, 2026 23:41
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Jun 11, 2026
Update cargo submodule

11 commits in 0b1123a48825309b697312b44fdb64b3df00c958..fe63976b245b8a649c3f2949bf89fdc307bfbae4
2026-06-01 21:20:28 +0000 to 2026-06-11 09:17:57 +0000
- refactor: reduce use `Summary::{as_summary,into_summary}` (rust-lang/cargo#17092)
- docs(diag): Provide jumping off points for writing diagnostics and passes (rust-lang/cargo#17090)
- refactor(source): drop `Source::is_yanked` (rust-lang/cargo#17091)
- refactor(resolver): move yank policy to resolver layer  (rust-lang/cargo#17083)
- fix(publish): avoid false deadlock when to_confirm is non-empty (rust-lang/cargo#17071)
- doc(guide): use fresh actions/checkout version in GH actions examples (rust-lang/cargo#17087)
- fix: strip CR from `cargo:token-from-stdout` (rust-lang/cargo#17081)
- test: show some odd `--precise` cases (rust-lang/cargo#17082)
- chore(deps): update rust crate gix to 0.84.0 (rust-lang/cargo#17063)
- refactor: drop `yanked_whitelist` from source loading (rust-lang/cargo#17014)
- chore(deps): update msrv to v1.96 (rust-lang/cargo#17041)
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Jun 11, 2026
Update cargo submodule

11 commits in 0b1123a48825309b697312b44fdb64b3df00c958..fe63976b245b8a649c3f2949bf89fdc307bfbae4
2026-06-01 21:20:28 +0000 to 2026-06-11 09:17:57 +0000
- refactor: reduce use `Summary::{as_summary,into_summary}` (rust-lang/cargo#17092)
- docs(diag): Provide jumping off points for writing diagnostics and passes (rust-lang/cargo#17090)
- refactor(source): drop `Source::is_yanked` (rust-lang/cargo#17091)
- refactor(resolver): move yank policy to resolver layer  (rust-lang/cargo#17083)
- fix(publish): avoid false deadlock when to_confirm is non-empty (rust-lang/cargo#17071)
- doc(guide): use fresh actions/checkout version in GH actions examples (rust-lang/cargo#17087)
- fix: strip CR from `cargo:token-from-stdout` (rust-lang/cargo#17081)
- test: show some odd `--precise` cases (rust-lang/cargo#17082)
- chore(deps): update rust crate gix to 0.84.0 (rust-lang/cargo#17063)
- refactor: drop `yanked_whitelist` from source loading (rust-lang/cargo#17014)
- chore(deps): update msrv to v1.96 (rust-lang/cargo#17041)
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Jun 11, 2026
Update cargo submodule

11 commits in 0b1123a48825309b697312b44fdb64b3df00c958..fe63976b245b8a649c3f2949bf89fdc307bfbae4
2026-06-01 21:20:28 +0000 to 2026-06-11 09:17:57 +0000
- refactor: reduce use `Summary::{as_summary,into_summary}` (rust-lang/cargo#17092)
- docs(diag): Provide jumping off points for writing diagnostics and passes (rust-lang/cargo#17090)
- refactor(source): drop `Source::is_yanked` (rust-lang/cargo#17091)
- refactor(resolver): move yank policy to resolver layer  (rust-lang/cargo#17083)
- fix(publish): avoid false deadlock when to_confirm is non-empty (rust-lang/cargo#17071)
- doc(guide): use fresh actions/checkout version in GH actions examples (rust-lang/cargo#17087)
- fix: strip CR from `cargo:token-from-stdout` (rust-lang/cargo#17081)
- test: show some odd `--precise` cases (rust-lang/cargo#17082)
- chore(deps): update rust crate gix to 0.84.0 (rust-lang/cargo#17063)
- refactor: drop `yanked_whitelist` from source loading (rust-lang/cargo#17014)
- chore(deps): update msrv to v1.96 (rust-lang/cargo#17041)
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Jun 11, 2026
Update cargo submodule

11 commits in 0b1123a48825309b697312b44fdb64b3df00c958..fe63976b245b8a649c3f2949bf89fdc307bfbae4
2026-06-01 21:20:28 +0000 to 2026-06-11 09:17:57 +0000
- refactor: reduce use `Summary::{as_summary,into_summary}` (rust-lang/cargo#17092)
- docs(diag): Provide jumping off points for writing diagnostics and passes (rust-lang/cargo#17090)
- refactor(source): drop `Source::is_yanked` (rust-lang/cargo#17091)
- refactor(resolver): move yank policy to resolver layer  (rust-lang/cargo#17083)
- fix(publish): avoid false deadlock when to_confirm is non-empty (rust-lang/cargo#17071)
- doc(guide): use fresh actions/checkout version in GH actions examples (rust-lang/cargo#17087)
- fix: strip CR from `cargo:token-from-stdout` (rust-lang/cargo#17081)
- test: show some odd `--precise` cases (rust-lang/cargo#17082)
- chore(deps): update rust crate gix to 0.84.0 (rust-lang/cargo#17063)
- refactor: drop `yanked_whitelist` from source loading (rust-lang/cargo#17014)
- chore(deps): update msrv to v1.96 (rust-lang/cargo#17041)
@rustbot rustbot added this to the 1.98.0 milestone Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cargo 1.96.0 fails to fetch updates from AWS CodeArtifact On Windows's are not trimmed from authentication tokens during publish.

4 participants