Repository navigation
Use the address width as prefix when banning an IP in TrackingSpamPrevention - #25912
Closed
AltamashShaikh wants to merge 1 commit into
Closed
AltamashShaikh wants to merge 1 commit into
AltamashShaikh wants to merge 1 commit into
Conversation
…vention (AS-896) An IPv6 address written with a dotted quad, such as ::ffff:192.0.2.1, was banned with a /32 prefix because the address contains a dot. The range then covered far more than the banned IP. The prefix now comes from the binary length of the address.
Closed
10 tasks
Contributor
Author
|
Replaced by #25913 (branch renamed). |
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.
Description
Bug: When a visit reaches the "maximum number of actions per visit" limit,
BlockedIpRanges::banIp()bans the visitor's IP. It chose the prefix by looking for a dot in the address:/32with a dot,/128without. An IPv6 address written with a dotted quad (IPv4-mapped::ffff:192.0.2.1, IPv4-compatible::192.0.2.1, or64:ff9b::192.0.2.1) contains a dot but is 128 bits wide, so it was banned as a/32range. That range covers far more than the one IP.In practice the extra blocking is limited:
isExcluded()only checks ranges stored under the same index (the address up to the first dot, eg::ffff:192.), and banned IPs are cleared by the daily task. Still, other visitors who share that index could be blocked for up to a day.Fix (
plugins/TrackingSpamPrevention/BlockedIpRanges.php): the prefix now comes from the binary length of the address (IPUtils::stringToBinaryIP()), so IPv4 addresses still get/32and every IPv6 address gets/128. The stored format, the index and theTrackingSpamPrevention.banIpevent are unchanged; for these addresses the event now receives the/128range. Ranges already stored with the wrong prefix are removed by the dailyupdateBlockedIpRangestask, so no migration is needed.Tests: a new data-provider test in
BlockedIpRangesTestcovers IPv4-mapped, IPv4-compatible and NAT64-style addresses. It checks the stored range is/128, that the banned IP is blocked, and that another IP with the same index is not. It fails without the fix.5.x: matomo-org/plugin-TrackingSpamPrevention#199
Checklist
Review