Repository navigation
fix(awsname): reject control characters by category, not by enumeration - #571
Conversation
Two validators accepted control characters and let the refusal happen
somewhere less informative. Both were found by fuzz targets that exist in
this repository and that CI has never run with a budget.
ValidateBucketName forbade control bytes by listing six of them in
bucketNameForbiddenBytes -- \t \n \r \v \f \x00 -- under a comment that
claimed "whitespace and control bytes", a category. The other twenty-seven
C0 bytes and DEL passed. FuzzValidateBucketName found "00\x06" in under one
second, failing on its own stated property: the accepted name produces
`parse "https://00\x06.s3...": invalid control character in URL`.
ValidateKMSKeyID had no control-character check at all. The ARN arm only
required the region and account fields to contain no colon, so
`arn:0:kms:0:\r\n:key/<uuid>` validated clean. FuzzValidateKMSKeyID found
\x1e in six seconds.
Control bytes are now rejected by category, in one isControlByte helper both
call, and the enumerated list keeps only characters whose problem is their
meaning in a URL. The comment on that list records what enumerating cost,
because the gap between a comment claiming a category and a string listing
members is invisible from either side.
This is not a header-injection fix. net/http rejects all three of \r\n,
\x1e and \x06 at send time with `invalid header field value` -- verified by
executing it against an httptest server, not reasoned about -- so the outer
layer already failed closed and nothing was injectable. What was wrong is
where the refusal happened: an opaque transport error on the first encrypted
PUT from a mount that started successfully, rather than a named config error
at load. That is the reason ValidateBucketName's doc comment gives for the
function existing, and the trailing-whitespace check just above the new loop
in sse.go is the same idea applied to a neighboring cause.
Verified by mutation, each fix separately, confirming the mutant still
compiles:
- drop the bucket loop -> TestValidateBucketName/a_NUL_byte and
FuzzValidateBucketName/d7b7b3c229446a73 both fail
- drop the KMS loop -> FuzzValidateKMSKeyID/ac5bbbe9a6c8ead3 fails, and it
is the only test that does, which is why the counterexample is committed
Both counterexamples are committed as seed corpus, so they run as ordinary
unit tests from here on.
Neither target is in ci.yml's fuzz-smoke matrix. Twelve of twenty-two are
not, including the one deciding whether whole-object checksums are verified;
filed as #565.
Refs #565
The one red check is not this diff — #573 unblocks it
An unauthenticated It is a required status check, though, so it does block this PR. Fixed in #573: Nothing to do on this branch. Once #573 merges, re-running this PR's checks should clear it — and if |
…k guard covers all 39 (#573) The `install-script (opensuse/leap:15.6, ...)` row failed on PR #571 with curl: (22) The requested URL returned error: 403 objectfs-install: error: could not reach the GitHub API to find the latest release against a diff that touched two Go files in `internal/awsname`. It is one of thirty-nine required status checks on `main`, so it blocks the pull request. `resolve_latest` in `scripts/install.sh` already has the fix, and has had it since the commit that added it. Its comment names the caller it was written for: "Unauthenticated API calls are rate limited by IP, which is fine for a person and not fine for CI on a shared runner." The job on the far side of that sentence never passed a token. The capability existed, was documented as being for this job, and was unreachable from it. Retrying is not the alternative, and the script says so at two call sites: `--retry 3` has been on that curl all along, curl does not retry a 403, and `wget_retry_flags` excludes 403 deliberately because it is an authorization answer rather than a transient one. Nor would retrying help — the primary rate limit resets up to an hour out, against this job's 15-minute timeout. Authenticated is 5,000 requests an hour against 60 for the shared runner IP. Three further defects found while diagnosing it: **The idempotency step passed vacuously on total failure.** Both installs are silenced to /dev/null and the step compares digests; when the install fails there is no binary, `sha256sum` prints nothing, and `a` and `b` are both empty — which are equal, so it echoed SAME and passed. That assertion was green for every possible failure of the thing it exists to test, including the 403 that took the step beside it down. The digests are now checked for being digests before they are compared. **`requiredChecks` transcribed twenty of the thirty-nine configured names.** Nothing in it had gone stale; it was written when there were twenty and never grew, so nineteen required contexts had no guard against the local rename that orphans them — `build-tags (s3compat)`, `deploy-manifests`, `docs-site`, all ten `fuzz-smoke` cells, all three `install-script` rows, `labels`, `sdk-metrics` and `systemd-unit`. A half-populated list is worse than an empty one, because the test passing reads as the whole set being covered. **`ci.yml`'s header said "Twenty check names are required on `main`"** and enumerated that same subset, in a comment block whose own opening paragraph owns up to having said "four" while listing five. Replaced with a pointer to the transcription, for the reason the version constant lives in one place. Two tests, because the job cannot catch this itself — an unauthenticated run passes whenever the quota happens not to be exhausted, which is most of the time: - `TestInstallScriptJobAuthenticatesEveryRunThatDownloads` keys on the success assertions rather than on step names, and asserts a floor so a rewording cannot leave it checking nothing. - `TestWorkflowsNeverForwardAnUnsetEnvironmentVariableToAContainer` walks every workflow. `docker run -e FOO` with no `=` forwards FOO from the caller's environment and forwards nothing when it is unset there, with no error — so the `-e` and the step's `env:` are one change in two places, and the missing half reproduces the original symptom with the fix apparently applied. `jobSteps` is added to `workflow_test.go` rather than as a fifth hand-rolled `map[any]any` walk, per #504. One residual gap is recorded rather than fixed: the guard strips the ` (...)` suffix, so it cannot see a matrix *cell* rename, and `install-script`'s three contexts embed a container image tag and a zypper command line. Bumping Leap to 16 would silently orphan all three. `modulefiles` already solved this for itself with an explicit `name:`; doing the same here means renaming a required check, which is a branch-protection change and not this repository's to make from code.
…ist's second hole (#565) The first CI run of FuzzValidateBucketName, added to the fuzz-smoke matrix in this PR, found a counterexample in 0.07s: ValidateBucketName("00`") accepted a name that makes an unparseable endpoint: invalid character "`" in host name The validator refused bucketNameForbiddenBytes (/\:@?#[]%& and space) and, after #571, control bytes, and accepted everything else. That is a deny-list, and its second hole: "<>^{|}!$'()*+,;=~ and the backtick all passed. Replace it with isBucketNameChar, an allow-list of ASCII letters of either case, digits, '.', '-' and '_'. That is the legacy us-east-1 set, the widest S3 has ever permitted, so no bucket that exists is refused; the existing MyBucket and my_bucket acceptance cases still pass. The control-character and non-ASCII checks keep their own messages, because both describe something invisible. The counterexample is committed as seed corpus (7e8429f5c2bfe6da), with table cases for a backtick, a pipe and a tilde. Mutations: removing the allow-list check, dropping '_', and dropping A-Z each fail named tests; the last two also fail TestParseStorageURI. Both FuzzValidateBucketName and FuzzParseStorageURI then ran clean for 120s through fuzz-smoke.sh.
…x complete (#591) * fix(ci): fuzz-smoke fuzzes all 22 targets, and a test keeps the matrix complete (#565) ci.yml's fuzz-smoke matrix named 10 of the tree's 22 fuzz targets. The other 12 ran only their seed corpus as unit tests and were never fuzzed, including FuzzWholeObjectResponse, which decides whether the SHA-256 verification runs at all. A 180s campaign over the twelve found two real defects in 1s and 7s (ValidateBucketName and ValidateKMSKeyID accepting control characters, fixed in #571), so at the existing 60s budget CI would have failed on the commit that introduced each. Add the twelve rows. TestFuzzSmokeCoversEveryFuzzTarget walks the tree for ^func Fuzz, including build-tagged files, and compares against the matrix in both directions: a target with no row, and a row naming a target that no longer exists. Floor of 20 targets. The shared workflow parser gains a typed strategy.matrix.include field for it. Mutations: a throwaway FuzzThrowaway565 is named with its file; deleting the FuzzWholeObjectResponse row names that target; a misspelled target reports both the missing target and the stale row. Renaming pkg: in every row first reported all 22 targets as missing, the right failure for the wrong reason; a row missing either key is now reported as malformed, and the empty-matrix check fires. * test(config): spelling in fuzz_coverage_test.go * fix(awsname): ValidateBucketName is an allow-list, closing the deny-list's second hole (#565) The first CI run of FuzzValidateBucketName, added to the fuzz-smoke matrix in this PR, found a counterexample in 0.07s: ValidateBucketName("00`") accepted a name that makes an unparseable endpoint: invalid character "`" in host name The validator refused bucketNameForbiddenBytes (/\:@?#[]%& and space) and, after #571, control bytes, and accepted everything else. That is a deny-list, and its second hole: "<>^{|}!$'()*+,;=~ and the backtick all passed. Replace it with isBucketNameChar, an allow-list of ASCII letters of either case, digits, '.', '-' and '_'. That is the legacy us-east-1 set, the widest S3 has ever permitted, so no bucket that exists is refused; the existing MyBucket and my_bucket acceptance cases still pass. The control-character and non-ASCII checks keep their own messages, because both describe something invisible. The counterexample is committed as seed corpus (7e8429f5c2bfe6da), with table cases for a backtick, a pipe and a tilde. Mutations: removing the allow-list check, dropping '_', and dropping A-Z each fail named tests; the last two also fail TestParseStorageURI. Both FuzzValidateBucketName and FuzzParseStorageURI then ran clean for 120s through fuzz-smoke.sh.
What this fixes
Two validators in
internal/awsnameaccepted control characters. Both defects were found by fuzztargets that already exist in this repository, in 1 second and 6 seconds respectively, the first
time either was run with a fuzzing budget instead of just its seed corpus.
ValidateBucketNamebucketNameForbiddenBytesenumerated six control bytes —\t \n \r \v \f \x00— under a commentclaiming "whitespace and control bytes". The other twenty-seven C0 bytes and DEL passed. The accepted
name then fails its own documented property:
This is the enumerated-gate shape: a comment claiming a category over a string listing members, and the
gap invisible from either side because every name anyone types by hand is accepted under both readings.
ValidateKMSKeyIDNo control-character check at all. The ARN arm only required the region and account fields to contain
no colon, so a raw CRLF validated clean:
Worth noting because it nearly misled me: an ARN with CRLF placed in a different field is rejected
— but for the wrong reason, as a resource-shape failure, not a control character. A rejection table that
only checks "was it rejected" would have looked fine here.
strings.TrimSpaceten lines above does not cover it: it inspects only the ends, and only Unicode space.What this is not
Not a header-injection fix, and I'd rather not let it be read as one.
net/httprejects all threeof
\r\n,\x1eand\x06at send time withinvalid header field value— verified by executing itagainst an
httptestserver, all three refused before a byte left the process. The outer layer alreadyfailed closed; nothing was injectable.
What was actually wrong is where the refusal happened: an opaque transport error on the first
encrypted PUT, from a mount that had already started successfully, instead of a named error naming the
field at config load. That is precisely the reason
ValidateBucketName's doc comment gives for thefunction existing.
The fix
One
isControlBytehelper, by category, that both validators call. The enumerated list keeps onlycharacters whose problem is their meaning in a URL (
/ \ : @ ? # [ ] % &and space) rather than theirbeing unprintable. The comment on that constant records what enumerating cost, so the next reader sees
the history rather than a tidy list.
Verification
Mutation-verified, each fix separately, confirming the mutant still compiles — a
FAIL [build failed]would prove nothing:TestValidateBucketName/a_NUL_byteandFuzzValidateBucketName/d7b7b3c229446a73failFuzzValidateKMSKeyID/ac5bbbe9a6c8ead3fails — and is the only test that doesThat second row is why both counterexamples are committed as seed corpus: without the new file, nothing
in the repository catches the KMS case.
make test— exit 0, 37 packages ok, no failures. Reported as the exit code, not as a tail of thelog, since
| tail -Nyields tail's status.GOOS=linux golangci-lint run ./internal/awsname/— 0 issues. Local binary is v2.14.0 against CI'spinned v2.12.2, so the required check is the authority.
go test ./internal/config/ -run TestChangelog— passes with the newUnreleasedsection.Related
Neither target is in
ci.yml'sfuzz-smokematrix. Twelve of the repository's twenty-two fuzztargets are not, including
FuzzWholeObjectResponse, which decides whether whole-object checksums getverified at all. Filed as #565 — this PR is the argument for it: two real defects, found in seven seconds
of combined runtime, sitting in targets someone had already written.
The other ten of the twelve were also run at 180s each in the same campaign and are clean.
Refs #565