Usability issues with `Authorization` parsing
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- rust
- Lĩnh vực
- api, backend-api-design
Hướng nghiên cứu
Start with the Header::decode entry point used by headers::Authorization::headers::authorization::Bearer in the three supplied test cases. Define behavior that distinguishes a missing or wrong scheme from a malformed or potentially suitable Authorization header, including the requested support for multiple schemes; done means callers can reliably produce the expected 401 or 400 outcomes.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Version
headers 0.4.1
Platform
Darwin [snip] 25.5.0 Darwin Kernel Version 25.5.0: Mon Apr 27 20:41:06 PDT 2026; root:xnu-12377.121.6~2/RELEASE_ARM64_T6030 arm64
Summary
It's impossible for a caller to differentiate between the cases needed.
Broadly speaking, I think there are 3 different returns from parsing this header:
- The
Authorizationheader is present, well-formed. (And maybe, of a type we support.) We probably want anOk(…)here, and the caller will translate this to either 200 or 401, depending on the validity of the credentials supplied. - The
Authorizationheader is missing altogether. The caller will likely want to return a 401. (Or otherwise treat the request as unauthenticated.) - The
Authorizationheader is present and malformed. The caller will want to return a 400.
Distinguishing between these cases accurately with the library is tough. Err(Invalid) is returned if the header isn't parsable, so we might think that should be translated to 400. But it's also returned in the absence of the header, or if the header is present and well-formed, but we want Bearer but got Basic, or something similar. In that case, it should be a 401. But there is no means for the caller to distinguish these cases.
I've attached a test case; the assert! statements are not authoritative, since there's not really a good way to write the right asserts here.
Code Sample
#[cfg(test)]
mod tests {
use headers::Header;
#[test]
fn test_no_headers() {
let result = headers::Authorization::<headers::authorization::Bearer>::decode(&mut [].into_iter());
println!("result = {:#?}", result);
// This isn't an error per se — the request isn't malformed. We'll want to return a 401.
assert!(result.is_err());
}
#[test]
fn test_multiple() {
let headers = [
http::HeaderValue::from_static("Bearer 123"),
http::HeaderValue::from_static("Basic dXNlcjpwYXNz"),
];
let result = headers::Authorization::<headers::authorization::Bearer>::decode(
&mut headers.iter(),
);
println!("result = {:#?}", result);
// This should be an error: multiple `Authorization` headers are malformed, but this will
// assert.
assert!(result.is_err());
}
#[test]
fn test_wrong() {
let headers = [
http::HeaderValue::from_static("Basic dXNlcjpwYXNz"),
];
let result = headers::Authorization::<headers::authorization::Bearer>::decode(
&mut headers.iter(),
);
println!("result = {:#?}", result);
// This isn't an error per se — the request isn't malformed, but the expected header isn't
// present. We'll want to return 401.
assert!(result.is_err());
}
}
Expected Behavior
A caller can accurately distinguish "wrong auth", "malformed message", and "potentially suitable auth".
Actual Behavior
There's only 1 error value, so that is impossible.
I wonder if -> Result<Option<Authorization>, _> would suffice, but I don't know if that's possible with the trait.
Additional Context
Obviously, the caller can do some pre-parsing … but what's the point of the library? 😉
I would also want a generic implementation of Authorization that can handle multiple/all types, in the case that one might accept Bearer or Basic. Yes, we can make two passes at parsing the header, but we'd repeat all the work of finding the scheme, which is a bit of a bummer.
- Ngôn ngữ chính
- Rust
- Star
- 200
- Fork
- 108
- Merge trung bình
- 3 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 2
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của hyperium/headers
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
-
Range::bytes and ContentRange::bytes do unchecked u64 arithmetic on boundsCó thể đã có người làm @youdie006 đã nhận 57 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 78/100
-
From<SystemTime> for HttpDate panics on times before 1970 or after year 9999Có thể đã có người làm @SAY-5 đã nhận 76 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
-
Link supportĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
-
Access-Control-Request-Headers should not use a space when combiningCó thể đã có người làm @youdie006 đã nhận 53 ngày trước. Đang mởeasy
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 50/100
Tất cả issue của hyperium/headers
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
objectionary/sodg.rs#301 ·
-
[Bug] Completion info popup (.cm-completionInfo) ignores the configured editor fontCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởbug user-priority/P2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
t8y2/dbx#11718 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
rescript-lang/rescript#8765 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
nautechsystems/nautilus_trader#5287 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
farion1231/cc-switch#8072 ·
Maintainer thường phản hồi trong vòng 1 ngày