mirror of
https://github.com/daijro/camoufox.git
synced 2026-11-19 00:07:28 +00:00
In both Python and TypeScript launchers, IP validation used loose regular expressions that allowed octets above 255 for IPv4 (e.g. 999.999.999.999) and malformed colon sequences for IPv6 (e.g. :, :::, 1::2::3). Downstream, these invalid addresses reached WebRTC init script generation and MaxMind DB lookups, causing broken script calls or unhandled errors instead of rejecting them early with InvalidIP. Replaced the regex checks with ipaddress in Python and node:net in TypeScript, and added test cases covering the boundary strings.
35 lines
938 B
Python
35 lines
938 B
Python
"""The per-context init script hands a WebRTC IP to the setter for its family."""
|
|
|
|
import pytest
|
|
|
|
from camoufox.exceptions import InvalidIP
|
|
from camoufox.fingerprints import _build_init_script
|
|
|
|
|
|
def test_ipv4_goes_to_the_ipv4_setter():
|
|
script = _build_init_script({"webrtcIP": "203.0.113.7"})
|
|
assert 'w.setWebRTCIPv4("203.0.113.7")' in script
|
|
assert "setWebRTCIPv6(" not in script
|
|
|
|
|
|
def test_ipv6_goes_to_the_ipv6_setter():
|
|
script = _build_init_script({"webrtcIP": "2001:db8::7"})
|
|
assert 'w.setWebRTCIPv6("2001:db8::7")' in script
|
|
assert "2001:db8::7" not in script.split("setWebRTCIPv6")[0]
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"invalid_ip",
|
|
[
|
|
"not-an-ip",
|
|
"999.999.999.999",
|
|
"256.1.1.1",
|
|
":",
|
|
":::",
|
|
"1::2::3",
|
|
],
|
|
)
|
|
def test_an_invalid_address_is_refused(invalid_ip: str):
|
|
with pytest.raises(InvalidIP):
|
|
_build_init_script({"webrtcIP": invalid_ip})
|