fix(pilot-ca): validate beacon hostname to prevent path traversal#3
Merged
Merged
Conversation
issueBeacon previously accepted any non-empty hostname and built the output paths via filepath.Join(outDir, hostname+".crt"). A hostname like "evil/../host" or "../escape" would write the leaf cert + key outside outDir, silently, while still printing success. The leaf cert itself was also malformed (invalid SAN/DNSName). Add a strict DNS-name allowlist regex (lowercase letters, digits, hyphen, dot only — labels <=63 chars, total <=253) and apply it at the very top of issueBeacon, before any filepath.Join touches outDir. Tests: - TestIssueBeacon_HostnameWithSlash_Rejected (renamed from the CurrentBehavior pin) now asserts rejection + that outDir stays empty. - TestIssueBeacon_HostnameWithParentDir_Rejected covers bare "..", "../escape", "foo/../bar", and a Windows-style "evil\\..\\host". - TestIssueBeacon_ValidHostname_Succeeds pins the happy path on a normal multi-label DNS name. All existing tests still pass under -race.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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
issueBeaconaccepted any non-empty hostname and used it directly infilepath.Join(outDir, hostname+".crt"). A hostname likeevil/../hostor../escapewrote the leaf cert + key OUTSIDEoutDirwhile still printing success — a HIGH-severity path-traversal bug.^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?(\.[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$) + 253-char cap, applied at the very top ofissueBeaconbefore anyfilepath.JointouchesoutDir.TestIssueBeacon_HostnameWithSlash_CurrentBehavior(which only logged buggy behavior) toTestIssueBeacon_HostnameWithSlash_Rejectedand flip it to assert rejection + an emptyoutDir. AddTestIssueBeacon_HostnameWithParentDir_Rejected(covers bare..,../escape,foo/../bar,evil\\..\\host) andTestIssueBeacon_ValidHostname_Succeeds(pins the happy path).Test plan
go test -race -count=1 -timeout 120s ./...— passesgo vet ./...— cleangofmt -l .— cleanTestIssueBeacon_*tests pass, including the 3 new/renamed onesTestIssueBeacon_RejectsEmptyHostnamestill passes (the validator preserves the "hostname required" error message for the empty case)