fix(api): validate tenant id at route boundary#3
Merged
Conversation
Before this change, /v1/tenants/{id}/... handed the raw id from the
URL straight to RequireIdentity and then into filepath.Join. The mux
already normalises `..` so true path traversal was blocked, but every
other malformed id (uppercase, leading dash, dot, control char,
oversized, …) flowed past auth and hit the filesystem before being
rejected — an unnecessary attack surface.
Now handleTenantRoute runs tenant.New(base, id) before auth. Any id
that fails the validID regex returns 400 immediately, no filesystem
access, no auth probe.
Same regex as the on-disk tenant constructor, so the contract is
"the only ids that reach handlers are the ones the on-disk store
would accept" — no second validation layer to drift out of sync.
Coverage gate: api 84.9% (target 83), global 88.0% (target 87).
tzone85
added a commit
that referenced
this pull request
Jun 11, 2026
Adds an Unreleased section to CHANGELOG.md covering the five sequential PRs that landed today: - #2 chore(security): bump x/sys for GO-2026-5024 - #3 fix(api): validate tenant id at route boundary - #4 fix(ingest): reject option-shaped --base-ref - #5 fix(mempalace): validate Kind/Tenant/Key against path traversal - #6 chore(supply-chain): pin govulncheck + base images by digest Updates README Status to mention the hardening pass and replaces a stale `§9` design-spec cross-reference with the section's actual name (per the project's doc-style rule against the § symbol). No code changes, no behaviour changes — pure documentation refresh for the audit story.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
handleTenantRoutenow runstenant.New(base, id)on the URL-supplied id BEFORE the auth check or any filesystem access. Malformed ids return400 Bad Requestimmediately...so true path traversal was already blocked, but every other shape of invalid id (uppercase, leading dash, dot, underscore, space, control char, oversized) flowed past the gate and hit the FS before being rejected.validIDregex as the on-disk tenant constructor — single source of truth, no second validation layer to drift out of sync.TDD
RED first:
TestAPI_TenantRoute_RejectsMalformedIDtable test for 6 invalid-id shapes (uppercase, leading dash, dot, underscore, space, 64-byte control-char string). Without the fix all six returned 401 (auth ran first). With the fix all six return 400.Test plan
go test -race ./...— all packages greenbash scripts/cover_check.sh— PASS, api 84.9% (target 83), global 88.0% (target 87)golangci-lint run— 0 issuesgovulncheck ./...— 0 vulnerabilities