-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Check token validity when loading registry config #15127
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ use cargo_credential::{ | |
Action, CacheControl, Credential, CredentialResponse, LoginOptions, Operation, RegistryInfo, | ||
Secret, | ||
}; | ||
use crates_io::check_token; | ||
|
||
use core::fmt; | ||
use serde::Deserialize; | ||
|
@@ -239,6 +240,17 @@ pub fn registry_credential_config_raw( | |
return Ok(cfg.clone()); | ||
} | ||
let cfg = registry_credential_config_raw_uncached(gctx, sid)?; | ||
if let Some(RegistryConfig { | ||
token: Some(token), .. | ||
}) = &cfg | ||
{ | ||
check_token(&token.val.as_deref().expose()).with_context(|| { | ||
format!( | ||
"Token for {sid} is invalid (defined in {})", | ||
token.definition | ||
) | ||
})?; | ||
} | ||
Comment on lines
+243
to
+253
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is moving the check from
To
I'd want to better understand if its a good idea to be running this check in all of those other situations CC @arlosi There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Construction of Paseto uses This field is only read by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @arlo I'd be interested in your thoughts on this |
||
cache.insert(*sid, cfg.clone()); | ||
return Ok(cfg); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,7 +95,7 @@ fn credential_provider_auth_failure() { | |
.auth_required() | ||
.alternative() | ||
.no_configure_token() | ||
.credential_provider(&["cargo:token-from-stdout", "true"]) | ||
.credential_provider(&["cargo:token-from-stdout", "echo", "incorrect token"]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this test being changed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes the test more precise, because it requires the token to be accepted syntactically, and rejected only by the server. |
||
.build(); | ||
|
||
cargo_process("install libc --registry=alternative") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -390,6 +390,34 @@ Caused by: | |
.run(); | ||
} | ||
|
||
#[cargo_test] | ||
fn syntactically_invalid_token() { | ||
Comment on lines
+393
to
+394
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a reminder, we generally prefer tests to be added in their own commit, showing the current behavior. |
||
let _registry = RegistryBuilder::new() | ||
.alternative() | ||
.auth_required() | ||
.no_configure_token() | ||
.http_index() | ||
.build(); | ||
|
||
let p = make_project(); | ||
cargo(&p, "build") | ||
.env("CARGO_REGISTRIES_ALTERNATIVE_TOKEN", "\t\n悪") | ||
.with_status(101) | ||
.with_stderr_data(str![[r#" | ||
[UPDATING] `alternative` index | ||
[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([ROOT]/foo)` | ||
|
||
Caused by: | ||
Token for registry `alternative` is invalid (defined in environment variable `CARGO_REGISTRIES_ALTERNATIVE_TOKEN`) | ||
|
||
Caused by: | ||
token contains invalid characters. | ||
Only printable ASCII characters are allowed as it is sent in a HTTPS header. | ||
|
||
"#]]) | ||
.run(); | ||
} | ||
|
||
#[cargo_test] | ||
fn incorrect_token_git() { | ||
let _registry = RegistryBuilder::new() | ||
|
Uh oh!
There was an error while loading. Please reload this page.