Skip to content

fix: refuse inputs that could delete, wipe or leak, and bound search paging - #147

Merged
tas50 merged 3 commits into
mainfrom
fix/defensive-requests
Nov 27, 2026
Merged

tas50 merged 3 commits into
mainfrom
fix/defensive-requests

Conversation

@tas50

@tas50 tas50 commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Fixes for malformed input from the second pre-1.0 review.

Empty or dot path segments. An empty name built a path with an empty segment, and erchef's router drops an empty trailing segment (dispatch.conf routes [..., "data", data_bag_name] to chef_wm_named_data). So Items(bag).Delete(ctx, "") sent DELETE /data/<bag>/ and deleted the whole bag. A . or .. name names a different object to any proxy that normalizes paths. doRaw now refuses a path with an empty, . or .. segment before sending. This covers every typed service and Do; queries are exempt.

Empty GET bodies. A 200 GET with an empty or null body decoded as an empty object:

  • Groups.AddMembers and ACLs.Grant then PUT back only the new member, dropping every existing one, and returned nil.
  • Users.SetPassword panicked on the nil map.

Every Chef GET returns a JSON document, so an empty one is now an error.

Search paging. A total that promises rows the server never sends kept the iterator paging until the context ended, and WithRows(math.MaxInt) overflowed the next start into a negative number.

Download collisions. Two manifest entries that land on one file raced two writers onto it, and one silently won. Examples: recipes/./x.rb beside recipes/x.rb, or default.rb beside DEFAULT.rb on macOS/Windows default filesystems. Both cases are now refused before anything is written.

Secrets in errors. An S3 SignatureDoesNotMatch body echoes the canonical request, the access key and the signature. Transfer errors now keep only the XML Code and Message. A non-Chef error body (such as a proxy HTML page) is capped at 512 bytes. A transfer body left unread is drained so the connection is reused.

Decrypted values with trailing data after the JSON object are refused.

Test plan

  • New defensive_test.go, one test per case. Before the fix, the empty-body test showed both destructive PUTs and the SetPassword panic; now no write reaches the server.
  • go test ./... -race -count=2; new code at 100% coverage, package coverage 98.3%
  • cd integration && go test ./...: the path guard on every real request
  • golangci-lint

An empty name built a path with an empty segment, and erchef's router
drops an empty trailing one: Items(bag).Delete(ctx, "") sent DELETE
/data/<bag>/, which routes to chef_wm_named_data and deletes the whole
bag. A "." or ".." name names a different object to any proxy that
normalizes the path. doRaw now refuses a path (before any query) with an
empty, "." or ".." segment before anything is sent, for every typed
service and Do.

A 2xx GET with an empty or null body decoded as an empty object.
Groups.AddMembers and ACLs.Grant then wrote that back with only the new
member, dropping every existing one, and Users.SetPassword panicked on the
nil map. Every Chef GET answers with a JSON document, so do now reports
an empty or null GET body as an error.

Signed-off-by: Tim Smith <tsmith84@proton.me>
…ts out of errors

Search: a server whose total promises rows it never returns kept the
iterator paging until the context ended (1e9 requests for total=1e12),
and WithRows(MaxInt) overflowed the next start into a negative number.
Paging still advances by the page size asked for, so one empty page of
deleted objects does not end it, but ten empty pages in a row are now an
error (the results are incomplete), and the offset cannot overflow.

DownloadFiles: two manifest entries landing on one file (recipes/./x.rb
beside recipes/x.rb, or default.rb beside DEFAULT.rb on the
case-insensitive filesystems macOS and Windows use by default) raced two
writers onto it and one silently won. They are now refused before
anything is written.

Errors: an S3 or bookshelf error body can echo the request's credentials
(SignatureDoesNotMatch includes the canonical request, access key and
signature); a transfer error now keeps only the XML Code and Message. A
raw error body that is not a Chef error document is capped at 512 bytes.
A transfer body a handler left unread is drained so the connection is
reused.

Decrypted data bag values with trailing data after the JSON object are
refused rather than read as the first value.

Signed-off-by: Tim Smith <tsmith84@proton.me>
On Linux default.rb and DEFAULT.rb are two files and download normally, so the test fetched them and failed there.

Signed-off-by: Tim Smith <tsmith84@proton.me>
@tas50
tas50 merged commit dc572b2 into main Nov 27, 2026
7 checks passed
@tas50
tas50 deleted the fix/defensive-requests branch November 27, 2026 02:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant