Repository navigation
Fix private IPv4 address detection in UnintendedExposedUrlDetector - #16
Open
maharshi-coding wants to merge 1 commit into
Open
maharshi-coding wants to merge 1 commit into
maharshi-coding wants to merge 1 commit into
Conversation
UnintendedPrivateIpAddress reported public addresses and stayed silent on private ones. handlePrivateIpReporting treated the RFC 1918 first octets (10, 172, 192) as a PUBLIC_IP_PREFIXES set and reported an incident only when the address did not start with one of them, inverting the rule. The first-octet-only check also classified all of 172.x and 192.x as private. Report an address only when it is a well-formed IPv4 address inside an RFC 1918 range (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16). Octets are validated to be 0..255 so malformed values such as 10.0.0.256 are not treated as private, and the IPv4 regex now ignores partial matches such as 1.2.3.4.5. Update the detector tests, which encoded the inverted behavior, to assert warnings on real private addresses and silence on public ones, and add coverage for the RFC 1918 boundaries, a mixed public/private config, and malformed inputs. Fixes google#15
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
UnintendedPrivateIpAddressis inverted: it reports public IPv4 addresses and stays silent on private ones (#15).handlePrivateIpReportingtreated the RFC 1918 first octets {10, 172, 192} as aPUBLIC_IP_PREFIXESset and reported only when an address did not match, so8.8.8.8was flagged while10.0.0.5/192.168.1.10were missed. Matching on the first octet alone also mis-classified all of172.xand192.x.Changes
PUBLIC_IP_PREFIXEScheck withisPrivateIpAddress(), reporting only RFC 1918 ranges:10.0.0.0/8,172.16.0.0/12,192.168.0.0/16.10.0.0.256are not treated as private.IPV4_REGEXso a dotted-quad is matched only when it is not part of a longer run (1.2.3.4.5), while still matching IPs inside URLs.Testing
./gradlew :checks:test --tests "*UnintendedExposedUrlDetectorTest"— 10/10 pass. The updated assertions fail against the pre-fix detector, confirming they capture the bug; the URL-detection tests are unchanged.Scope
Limited to RFC 1918 per the rule's stated purpose. Loopback (
127.0.0.0/8) / link-local (169.254.0.0/16) and the separateappliesTo/res/valuesgap noted in the issue are left as potential follow-ups.Fixes #15