-
Notifications
You must be signed in to change notification settings - Fork 21
fix: block direct IP address HTTPS connections to prevent domain filtering bypass #142
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
Changes from 3 commits
14abf1e
2e64bd8
1af07c8
80c1369
93f380a
1f20811
00653e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -596,9 +596,10 @@ describe('generateSquidConfig', () => { | |||||
| }; | ||||||
| const result = generateSquidConfig(config); | ||||||
| expect(result).toContain('acl allowed_domains dstdomain'); | ||||||
| expect(result).not.toContain('dstdom_regex'); | ||||||
| expect(result).toContain('http_access deny !allowed_domains'); | ||||||
| // Should not have domain pattern regex (allowed_domains_regex) for plain domains | ||||||
| // Note: IP blocking ACLs (ip_dst_ipv4, ip_dst_ipv6) use dstdom_regex but are separate | ||||||
| expect(result).not.toContain('allowed_domains_regex'); | ||||||
| expect(result).toContain('http_access deny !allowed_domains'); | ||||||
| }); | ||||||
|
|
||||||
| it('should handle only pattern domains', () => { | ||||||
|
|
@@ -692,4 +693,52 @@ describe('generateSquidConfig', () => { | |||||
| expect(result).toContain('# ACL definitions for allowed domain patterns'); | ||||||
| }); | ||||||
| }); | ||||||
|
|
||||||
| describe('Direct IP Address Blocking (Security)', () => { | ||||||
| it('should include ACL to block direct IPv4 address connections', () => { | ||||||
| const config: SquidConfig = { | ||||||
| domains: ['example.com'], | ||||||
| port: defaultPort, | ||||||
| }; | ||||||
| const result = generateSquidConfig(config); | ||||||
| // Should contain IPv4 address blocking ACL | ||||||
| expect(result).toContain('acl ip_dst_ipv4 dstdom_regex'); | ||||||
| expect(result).toMatch(/\^\\?\[0-9\]\+/); // Should match IP pattern | ||||||
|
||||||
| expect(result).toMatch(/\^\\?\[0-9\]\+/); // Should match IP pattern | |
| expect(result).toMatch(/\^\[0-9]\+\\\.\[0-9]\+\\\.\[0-9]\+\\\.\[0-9]\+\$/); // Should match full IPv4 regex pattern |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -110,8 +110,20 @@ acl Safe_ports port 80 | |||||
| acl Safe_ports port 443 | ||||||
| acl CONNECT method CONNECT | ||||||
|
|
||||||
| # Security: Block direct IP address connections (bypass prevention) | ||||||
| # Clients must use domain names, not raw IP addresses | ||||||
| # This prevents bypassing domain-based filtering via direct IP HTTPS connections | ||||||
| acl ip_dst_ipv4 dstdom_regex ^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+$ | ||||||
|
||||||
| acl ip_dst_ipv4 dstdom_regex ^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+$ | |
| acl ip_dst_ipv4 dstdom_regex ^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$ |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The IPv6 regex pattern is overly permissive and will match invalid or malformed IPv6 addresses. The pattern [0-9a-fA-F]* allows zero or more hex digits, which means it would match strings like : (just a colon), ::::::: (multiple colons without hex digits), or [:] (brackets with just a colon). While the requirement of at least one colon helps distinguish from domain names, consider a more restrictive pattern that validates proper IPv6 structure, such as requiring at least one hex digit between colons: ^\\[?([0-9a-fA-F]{1,4}:)+[0-9a-fA-F:]*\\]?$ or using a more complete IPv6 validation regex.
| acl ip_dst_ipv6 dstdom_regex ^\\[?[0-9a-fA-F]*:[0-9a-fA-F:]*\\]?$ | |
| acl ip_dst_ipv6 dstdom_regex ^\\[?([0-9a-fA-F]{1,4}:)+[0-9a-fA-F:]*\\]?$ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment clarification about IP blocking ACLs is helpful, but the test name 'should handle only plain domains (backward compatibility)' could be clearer. Consider updating the test description to explicitly mention that it tests backward compatibility while allowing the new IP blocking ACLs, e.g., 'should handle only plain domains without pattern ACLs (backward compatibility, IP blocking ACLs are separate)'.