Skip to content

Commit 9bfafe9

Browse files
committed
fix bug in regex matching in IP matching
1 parent e549bec commit 9bfafe9

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

python/philologic/runtime/access_control.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import netaddr
1212
import regex as re
1313
from netaddr import IPSet
14+
1415
from philologic.runtime.DB import DB
1516
from philologic.utils import load_module
1617

@@ -98,6 +99,9 @@ def load_or_compile_ip_whitelist(access_file):
9899
# Exact IP address
99100
exact_ips.add(ip)
100101

102+
# Match prefixes of exact IPs as well (e.g., "192.168.1.12" should match "192.168.1.123")
103+
regex_patterns.add(re.compile(f"^{re.escape(ip)}.*$"))
104+
101105
except (ValueError, netaddr.AddrFormatError) as e:
102106
# Fallback to regex for any formats netaddr can't handle
103107
print(f"Warning: Could not parse IP '{ip}': {str(e)}", file=sys.stderr)

0 commit comments

Comments
 (0)