-
Notifications
You must be signed in to change notification settings - Fork 196
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
Fix aws-sigv4 canonical request formatting fallibility #1656
Fix aws-sigv4 canonical request formatting fallibility #1656
Conversation
This commit addresses panic in the case of formatting a CanonicalRequest containing invalid UTF-8 in the header value. The commit aims for the least disturbance to the codebase in order to pass a given failing test in the PR. We want to quickly determine if this low-cost approach addresses the problem before we commit ourselves to start refactoring CanonicalRequest to have a special format function. Fixes smithy-lang#711
this looks great! do you mind making a few small improvements:
|
This commit converts test_signing_utf8_headers to a proptest. The original test only specified hardcoded non-UTF8 bytes in a request header. To ensure that `crate::http_request::sign` does not panic no matter what valid byte sequence for HeaderValue is, the proptest covers a wider range of inputs. For consistency, the test has been moved from `canonical_request.rs` to `sign.rs`.
This commit introduces an error type InvalidHeaderError to indicate that we ran into a problem in handling a HeaderValue within CanonicalRequest. The error type contains a source error such as Utf8Error so a diagnostic message can be printed if needed.
Thanks @rcoh ! I took a stab at incorporating the feedback.
I converted
I have added an error type
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good! I think can merge it as is, although it would be nice to improve the overall error situation in this crate.
aws/rust-runtime/aws-sigv4/src/http_request/canonical_request.rs
Outdated
Show resolved
Hide resolved
This commit effectively reverts 739b32c. Knowing that we will be cleaning up error types, having InvalidHeaderError is too narrow a solution and does not add value to the codebase.
This PR attempts to address issue 711 where signing a request can cause
panic!
if aCanonicalRequest
contains invalid UTF-8 in the header value.The PR intentionally starts with a simple solution that makes a given test pass before we commit ourselves to start refactoring
CanonicalRequest
to support a special formatting function, which will probably be more expensive to do so. If the solution described in this PR works, that is great but if not, we can certainly switch to the refactoring ideas mentioned in the open issue.The rationale behind the code changes is to make validating UTF-8 in the header value be part of an invariant of
CanonicalRequest
. That is, by the timeCanonicalRequest
has been successfully constructed byCanonicalRequest::from
, we can guarantee that the type always contains valid UTF-8 in the header value. That way, we don't need to wait to catch invalid UTF-8 in the header value until we callto_string
onCanonicalRequest
(here).That being said, the proposed approach may be inefficient because of eager checking of valid UTF-8 in the header value within
normalize_header_value
, especially when aCanonicalRequest
does not need to be signed (in which case I assumeto_string
on theCanonicalRequest
does not need to be called in the execution path).This PR comes with a test provided in the open issue as well as a small test for
normalize_header_value
to exercise the part that has been updated.I would appreciate if the reviewers with more background knowledge could assess the code changes from different perspectives.