Skip to content

Use the address width as prefix when banning an IP in TrackingSpamPrevention - #25912

Closed
AltamashShaikh wants to merge 1 commit into
6.x-devfrom
as-896-ban-ip-cidr-suffix
Closed

AltamashShaikh wants to merge 1 commit into
6.x-devfrom
as-896-ban-ip-cidr-suffix

Conversation

@AltamashShaikh

@AltamashShaikh AltamashShaikh commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

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: /32 with a dot, /128 without. An IPv6 address written with a dotted quad (IPv4-mapped ::ffff:192.0.2.1, IPv4-compatible ::192.0.2.1, or 64:ff9b::192.0.2.1) contains a dot but is 128 bits wide, so it was banned as a /32 range. 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 /32 and every IPv6 address gets /128. The stored format, the index and the TrackingSpamPrevention.banIp event are unchanged; for these addresses the event now receives the /128 range. Ranges already stored with the wrong prefix are removed by the daily updateBlockedIpRanges task, so no migration is needed.

Tests: a new data-provider test in BlockedIpRangesTest covers 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

  • [✔] I have understood, reviewed, and tested all AI outputs before use
  • [✔] All AI instructions respect security, IP, and privacy rules

Review

…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.
@AltamashShaikh

Copy link
Copy Markdown
Contributor Author

Replaced by #25913 (branch renamed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant