pub struct PacPolicy { /* private fields */ }pac only.Expand description
Safety envelope for PAC evaluation (pac-quickjs and pac-subprocess; ignored by the
native resolvers, which hand the script to the OS).
Defaults: no DNS, drop internal answers, myIpAddress() → 127.0.0.1, 5 s timeout.
QuickJsEvaluator interrupts the script at the deadline, and bounds the heap and the
native stack, the parser’s included, with fixed limits of its own.
One default is not a limit: the crate reads no time zone, so
local_utc_offset is 0 and weekdayRange, dateRange and
timeRange answer in GMT whether or not the script passed "GMT"; a browser reads the
host’s zone there. with_local_utc_offset is the only
way to move them, and a fixed offset does not follow DST.
The defaults restrict evaluation because scripts arrive over the network and standalone
PAC libraries have had security vulnerabilities: pac-resolver escaped its Node.js vm
and reached RCE (CVE-2021-23406),
and pacparser had
CVE-2023-37360.
Implementations§
Source§impl PacPolicy
impl PacPolicy
Sourcepub fn new() -> Self
pub fn new() -> Self
The default policy: no DNS, no internal addresses, no real local IP, 5 s budget.
Sourcepub fn with_dns_resolution(self, enabled: bool) -> Self
pub fn with_dns_resolution(self, enabled: bool) -> Self
Allow dnsResolve, isResolvable and isInNet to perform name resolution.
With the default false, dnsResolve returns null and no DNS query is made.
Sourcepub fn with_internal_addresses(self, allowed: bool) -> Self
pub fn with_internal_addresses(self, allowed: bool) -> Self
Allow answers in internal space (loopback, RFC 1918, link-local, CGNAT, … and the
IPv4-mapped spelling of those). Default false drops them.
Classic dnsResolve is IPv4-only, so a native IPv6 answer (a ULA, say) never
reaches this flag either way. IP literals in the script are never filtered.
Sourcepub fn with_my_ip_address(self, address: IpAddr) -> Self
pub fn with_my_ip_address(self, address: IpAddr) -> Self
Set the address myIpAddress() reports. Unset → 127.0.0.1 (no auto-discovery).
Sourcepub fn with_timeout(self, timeout: Option<Duration>) -> Self
pub fn with_timeout(self, timeout: Option<Duration>) -> Self
Wall-clock budget, or None to remove it (blocks the caller if the script hangs).
Some(Duration::ZERO) is a zero budget, not an unlimited one: every evaluation
returns Error::PacTimeout. None removes the limit.
WinHttpPacResolver::with_timeout treats zero the same way. Its name is left
unlinked because the type exists only under pac-windows-native on Windows; linking
it breaks doc builds elsewhere.
QuickJsEvaluator interrupts the script at the deadline, so its thread is free for
the next evaluation when the call returns, unless a host function (dnsResolve with
DNS on) is still running then.
Evaluation threads are limited process-wide to the number of cores, with a minimum
of 4. A thread holds its slot until its script ends, including after the call times
out. When all slots are occupied, a call waits for one within the same budget and
returns Error::PacSaturated without running the
script if the budget expires. Run untrusted scripts in a process the caller can kill
(pac-subprocess). With None, the in-process engine runs on the calling thread
without a slot, bypassing the thread limit as well as the timeout.
SubprocessEvaluator (pac-subprocess) still requires a slot and waits without a
time limit for a slot and its worker’s response.
Sourcepub fn with_local_utc_offset(self, seconds: i32) -> Self
pub fn with_local_utc_offset(self, seconds: i32) -> Self
Seconds from UTC treated as “local” for date/time predicates (default 0 = GMT).
Sourcepub fn with_now(self, now: SystemTime) -> Self
pub fn with_now(self, now: SystemTime) -> Self
Pin the clock the time-dependent host functions see.
Intended for tests and for reproducing a routing decision after the fact.
Sourcepub fn resolve_dns(&self) -> bool
pub fn resolve_dns(&self) -> bool
Whether name resolution is permitted.
Sourcepub fn allow_internal_addresses(&self) -> bool
pub fn allow_internal_addresses(&self) -> bool
Whether resolution results in internal address space are kept.
Sourcepub fn my_ip_address(&self) -> IpAddr
pub fn my_ip_address(&self) -> IpAddr
The address myIpAddress() reports, or 127.0.0.1 when unset.
Sourcepub fn local_utc_offset(&self) -> i32
pub fn local_utc_offset(&self) -> i32
The offset from UTC, in seconds, that counts as local time.
Sourcepub fn now(&self) -> Option<SystemTime>
pub fn now(&self) -> Option<SystemTime>
The pinned clock, when with_now was used.