Repository navigation
Hold S3 header-name normalization in the type - #120014
Conversation
`normalizeHeaderNames` was a step the caller had to remember before assigning `extra_headers`. The S3 client sorts headers by the literal prefix `x-amz-`, before signing and again after, so a name that arrives in the operator's spelling is sent unsigned and untranslated. `PocoHTTPClientConfiguration::extra_headers` now holds a `NormalizedHTTPHeaderEntries`, whose `push_back` lower-cases the name. The collection cannot be built any other way, so the step cannot be skipped. Normalizing further upstream is not possible: `HTTPHeaderFilter` matches `<http_forbid_headers>` regexps against the original case for `(?-i)` scopes, and the GCS token refresh finds the header to replace by comparing the name to `Authorization`.
|
Workflow [PR], commit [0264ea9] Summary: ✅
AI ReviewSummaryThis PR moves S3 header-name normalization into Findings
Final VerdictNot ready to merge as-is: the S3 path still weakens existing LLVM Coverage ReportMeasured on commit 0264ea9.
Changed lines: Changed C/C++ lines covered: 43/62 (69.35%) · Uncovered code |
`<http_forbid_headers>` matched a regexp against the original-case header name, so that an inline `(?-i)` scope kept working. That scope is a bypass, not a feature: `(?-i)Authorization` blocks `Authorization` and lets `authorization` through, and both name the same header. The regexps now match the lower-cased name, as the exact set already did, and a pattern that turns case insensitivity off is reported at config load. Nothing on the way to the S3 client needs the original case any more, so `S3AuthSettings::headers` and `access_headers` hold normalized names from the moment the config or the query is read, and `ClientFactory::create` converts nothing. The GCS token refresh looks its header up with `eraseByName`, which normalizes the name it searches for, so the `Authorization` spelling can no longer drift. A new test drives a configured `X-Amz-Meta-Owner` through the real client and the mock GCS server. It fails when the name reaches the wire unchanged, which the helper tests alone did not catch.
An operator may write a forbidden header in upper case. Nothing covered that spelling: the exact-set tests configure `Authorization` and `authorization`, and the regexp tests configure lower case only. Both forms already block every case variant, by different means. The exact set holds the configured name lower-cased. A regexp pattern is left as written, because lower-casing it would corrupt a metacharacter such as `\D` or `[A-Z]`, and takes its case insensitivity from the RE2 option instead.
Several restated the identifier they sat on, described what would happen if the normalization were absent, or duplicated the class doc.
Two patterns were accepted while blocking nothing: one whose inline `(?-i)` scope asks for case-sensitive matching, which a name matched in lower case cannot honour, and one that does not compile, which was skipped with a warning. Both now throw at config load. `setValuesFromConfig` cleared the blocklist and then repopulated it under the lock, so throwing part-way would have left fewer rules in force than the config asks for. It builds both containers first and swaps them at the end, which also keeps config reading off the lock.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes24 object files changed (+7.65 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units148 translation units recompiled, 1099 s compile time in total, 148 of them have a recent master baseline. |
The `NormalizedHTTPHeaderEntries` overload lower-cased every name again after running the check, on the grounds that the check edits names in place. It cannot matter: the check throws on CR/LF, strips control and whitespace characters from the name, and matches a local lower-cased copy, so it never writes case back. Every name entering it is already lower-cased by `push_back`, `append` or the converting constructor, so the loop was a no-op. The overload stays, and stays mutable, because the strip is a real edit of the caller's data. `HTTPHeaderFilter.ChecksNormalizedEntries` already pins the outcome the removed loop pretended to guarantee.
Per review: the filter's case handling is a separate concern from holding normalization in the type, and the `(?-i` substring check that guarded it misses `(?s-i`, `(?m-i)` and partial scopes. `HTTPHeaderFilter` goes back to master except for the overload that accepts `NormalizedHTTPHeaderEntries`, which `diskSettings` needs to pass the new type. The three tests that pinned the rejection go with it. Two characterization tests take their place: an inline `(?-i)` scope and an uncompilable pattern are both accepted and then forbid nothing, and a `(?-i)` rule cannot block an S3 header at all, since that name now arrives lower-cased. Doing this properly needs the parsed pattern rather than a substring check, which is the follow-up.
Restores master's `RegexpInlineCaseSensitiveScopeStillBlocksOriginalCase` verbatim and appends the one assertion this PR adds: a `(?-i)` rule cannot reach an S3 header, because that name arrives lower-cased whatever the caller wrote. Drops the two tests documenting case handling master already has, and the one characterizing an uncompilable pattern. Neither is this PR's business now that the filter itself goes back to master. The test file is additive against master again -- the `isForbiddenForS3` helper, that one assertion, and `ChecksNormalizedEntries` for the new overload -- with nothing renamed or deleted.
`NormalizedHTTPHeaderEntries` exposes no `operator[]`, so three tests copied it into an `HTTPHeaderEntries` just to index it. Two assert a single entry and need only `size()` and `begin()`; the third compares three ordered entries, which now collects names and values into vectors and compares each in one assertion. That also widens what it checks: one of the three values was asserted before, all three are now, so "values are untouched" is tested rather than sampled.
|
|
||
| void setValuesFromConfig(const Poco::Util::AbstractConfiguration & config); | ||
| void checkAndNormalizeHeaders(HTTPHeaderEntries & entries) const; | ||
| void checkAndNormalizeHeaders(NormalizedHTTPHeaderEntries & entries) const; |
There was a problem hiding this comment.
Do we need this? Is it really used in S3 code? (except for gtest here)
There was a problem hiding this comment.
here
headers comes out of S3Settings::auth_settings which I did changed.
…r-entries # Conflicts: # src/IO/S3AuthSettings.cpp
Related: #119042
Follow-up to a review comment on #119042: the normalization should belong to the
collection, not to a function the caller must remember.
NormalizedHTTPHeaderEntrieslower-cases a name inpush_back, andS3AuthSettings::headersand
access_headershold that type, so names are normalized where the config or the query isread rather than at each use.
eraseByNameanswers lookups the same way, which removes thecase-sensitive
h.name == "Authorization"comparison from the GCS token refresh.What it fixes on the wire: a mixed-case
X-Amz-Meta-Foofails thestarts_with("x-amz-")test in
addAdditionalAMZHeadersToCanonicalHeadersList, so it skips the canonical header listand never reaches the GCS
x-goog-translation. Normalized at the source, it does.The
<http_forbid_headers>case handling is no longer part of this PR, per review.HTTPHeaderFilterkeeps only an overload accepting the new type. One assertion is appended toits existing
(?-i)test to record what the split costs: such a rule cannot reach an S3 header,whose name now arrives lower-cased. Detecting that properly needs the parsed pattern rather than
a substring check, which is left to a follow-up.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Custom HTTP headers configured for S3 are now handled case-insensitively by name, so a header spelled
X-Amz-Meta-Fooreaches Google Cloud Storage translated tox-goog-meta-foo, asx-amz-meta-fooalready did.Workflow [PR]
Sync PR [sync-upstream/pr/120014]
Version info
26.10.1.361-master(included in26.10and later)