Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pfBlockerNG: fix ipv6 regex to match prefix lengths > 99 #1372

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from

Conversation

dairiki
Copy link

@dairiki dairiki commented May 7, 2024

This fixes a regex used to match ipv6 addresses and networks.

The current regular expression used when cleaning ipv6 network prefixes during updates/reloads does not correctly recognize three-digit ipv6 prefix lengths.

I was using a blocklist 1 that includes the network prefix 2602:80d:1003::/112.
As a result of this bug, that was being mangled to 2602:80d:1003::/11, which in turn resulted in the final pf table including the prefix 2600::/11 (thus erroneously blocking a large portion of the internet.)

The current regex uses (\/[0-9][0-9]?|1([01][0-9]|2[0-8]))? to match the prefix length.
This correctly matches a / followed by one or two digits, but the part of the regex meant to match three-digit prefix lengths doesn't work:

  1. The leading slash is only attached to the first alternative. An extra set of parentheses is necessary to fix that.
  2. The first matching alternative wins, so longer alternatives should be listed first.

This patch replaces (\/[0-9][0-9]?|1([01][0-9]|2[0-8]))? with (\/(1(2[0-8]|[01]\d)|[1-9]?\d))?.

Footnotes

  1. The list in question is censys_scanning_ranges.txt, downloadable from Censys’ “Opt Out of Data Collection” page.

@dairiki dairiki marked this pull request as draft May 7, 2024 19:52
@dairiki dairiki changed the title fix: fix ipv6 regex to match prefix lengths > 99 pfBlockerNG: fix ipv6 regex to match prefix lengths > 99 May 7, 2024
@dairiki dairiki marked this pull request as ready for review May 7, 2024 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant