Use &[u8]::get() instead of &[u8]::index() to avoid panic in basic auth#220
Merged
seanmonstar merged 1 commit intohyperium:masterfrom Nov 7, 2025
Merged
Conversation
&[u8]::get instead of &[u8] to avoid panic in basic auth&[u8]::get() instead of &[u8]::index() to avoid panic in basic auth
Member
|
This should probably be fine, but I went to look, and the |
Contributor
Author
|
The code that led to the panic is calling the Based on the code I read in fn extract_auth_values(req: &mut axum::Request) -> Result<(uuid::Uuid, ApiPlainSecret), StatusCode> {
let auth_header = req
.headers()
.get(http::header::AUTHORIZATION)
.ok_or_else(|| {
debug!("Authorization header not found");
StatusCode::UNAUTHORIZED
})?;
let Some(auth) = headers::authorization::Basic::decode(auth_header) else {
debug!("Failed to decode auth headers");
return Err(StatusCode::UNAUTHORIZED);
};
let plain_secret = ApiPlainSecret::new(auth.password().to_owned());
Ok((public_id, plain_secret))
} |
Member
|
Ah very interesting. Yea, I never originally meant for it to be used separately, but I didn't really prepare that or document or anything. Again, seems fine to fix that up. :) |
seanmonstar
approved these changes
Nov 7, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I experienced a panic in production code at
authorization:l159forheadersv 0.4.1.I don't have logs of the actual header yet, but I know that the header value was length 3.
I propose returning a
Noneif the prefix strip doesn't succeed.