Skip to main content

PacPolicy

Struct PacPolicy 

Source
pub struct PacPolicy { /* private fields */ }
Available on crate feature 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

Source

pub fn new() -> Self

The default policy: no DNS, no internal addresses, no real local IP, 5 s budget.

Source

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.

Source

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.

Source

pub fn with_my_ip_address(self, address: IpAddr) -> Self

Set the address myIpAddress() reports. Unset → 127.0.0.1 (no auto-discovery).

Source

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 ends with the call 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.

Source

pub fn with_local_utc_offset(self, seconds: i32) -> Self

Seconds from UTC treated as “local” for date/time predicates (default 0 = GMT).

Source

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.

Source

pub fn resolve_dns(&self) -> bool

Whether name resolution is permitted.

Source

pub fn allow_internal_addresses(&self) -> bool

Whether resolution results in internal address space are kept.

Source

pub fn my_ip_address(&self) -> IpAddr

The address myIpAddress() reports, or 127.0.0.1 when unset.

Source

pub fn timeout(&self) -> Option<Duration>

The wall-clock evaluation budget.

Source

pub fn local_utc_offset(&self) -> i32

The offset from UTC, in seconds, that counts as local time.

Source

pub fn now(&self) -> Option<SystemTime>

The pinned clock, when with_now was used.

Trait Implementations§

Source§

impl Clone for PacPolicy

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for PacPolicy

Source§

impl Debug for PacPolicy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PacPolicy

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for PacPolicy

Source§

impl PartialEq for PacPolicy

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for PacPolicy

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more