Repository navigation
fix(agent): reject out-of-range ports instead of narrowing them in the capture cache (#1220) - #1231
Merged
Merged
Conversation
…e capture cache (#1220) captureUDPClusters parsed the UDP entry's port with strconv.Atoi and passed uint32(port) to UDPLoadAssignment with no bound (CodeQL alert #4, go/incorrect-integer-conversion). The three entry.sni parses in capture.go now share entryPort, which parses with strconv.ParseUint(s, 10, 16) and rejects 0, so a value outside 1..65535 is skipped rather than wrapped (2^32+80 -> 80). Fixes #1220 Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
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.
Mechanism
CodeQL alert #4 (
go/incorrect-integer-conversion, HIGH) flaggedagent/internal/xds/cache/capture.go:724:Atoiyields a 64-bitint;uint32(port)wraps, so"4294967376"(2^32+80) would address port 80 and a negative value would wrap to a large one. In practice this site was guarded:captureUDPClustersonly reaches it afterudpClusterForLockedaccepted the sameentry.sni(1..65535) under the sameclusterMuread lock, andentry.sniis always rendered bystrconv.Itoafrom auint32port. So it was not exploitable today, but the guard lived in another function and the unchecked conversion was one refactor away from shipping a wrapped port.Fix
The three
entry.sniparses incapture.go(udpClusterForLocked,captureUDPClusters,primaryPortOf) now go through one helper:An out-of-range value is rejected, never narrowed. Each caller keeps how it already handled malformed input:
udpClusterForLockedreturns""and the service is skipped,primaryPortOfreturns 0 ("no alias"), andcaptureUDPClustersskips the service withcontinue, which cannot happen while the guard above holds.ParseUintalso rejects"+80", whichAtoiaccepted. That doesn't matter forItoaoutput.Sibling sweep across
agent/internal/xds/...andcommon/:proxy/cluster.goalready parses at 16 bits.server/odcds.go:286andproxy/egress.go:348only check that the value parses and discard it.common/procschedparses at 64 bits intouint64andintwithout narrowing. None has the same shape, so nothing else changes.Tests (
entryport_test.go)TestEntryPort: max valid (65535), max+1, 0, -1,-4294967216and4294967376(both wrap to 80 throughuint32()), 2^32+65535, empty,+80,80, non-numeric.TestPrimaryPortOf_RejectsOutOfRange: 2^32+8080 must not alias 8080.TestUDPClusterForLocked_OutOfRangePortSkipped: a UDP entry's sni is corrupted to 2^32+5353, and the test asserts noudp:cluster is named.Red: I swapped
entryPort's body for the oldAtoi+uint32()shape. All three tests failed:TestEntryPort/{65536,-1,-4294967216,4294967376,4295032831,+80},TestPrimaryPortOf_RejectsOutOfRangeandTestUDPClusterForLocked_OutOfRangePortSkipped.Green:
bazel test --config=race --runs_per_test=10 //agent/internal/xds/cache:cache_test: 10/10 passed.make format-checkis clean, andbazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //agent/... //prober/... //common/...passes.Fixes #1220
🤖 Generated with Claude Code
https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr