PhoenixWebTransport.Origin (phoenix_wtransport v0.1.0)

Copy Markdown View Source

Origin validation for WebTransport CONNECT upgrades, matching Phoenix.Socket.Transport.check_origin/5 semantics.

Supports:

  • false - disables origin checking (useful for non-browser tests or CLI clients)
  • true - checks against endpoint.config(:url)[:host]
  • list of origin patterns (e.g. ["https://example.com", "//*.example.com:8443"])
  • :conn - compares origin scheme/host/port against the request :authority
  • {module, function, args} MFA tuple invoked as apply(module, function, [origin_uri | args])

When opts[:check_origin] is nil or omitted, defaults to endpoint.config(:check_origin) if endpoint defines config/1, or false.

Summary

Functions

Validates an Origin header binary against the resolved policy.

Resolves and validates the effective :check_origin policy.

Types

policy()

@type policy() :: boolean() | [String.t()] | :conn | {module(), atom(), list()}

Functions

check(origin, endpoint, opts, req_meta \\ %{})

@spec check(binary() | nil, module(), keyword(), map()) ::
  :ok | {:error, 403, :origin_missing | {:origin_not_allowed, binary()}}

Validates an Origin header binary against the resolved policy.

Unlike HTTP/WebSocket where non-browser clients may omit Origin, WebTransport rejects a missing Origin header with {:error, 403, :origin_missing} whenever origin checking is enabled (policy != false).

resolve_policy(endpoint, opts)

@spec resolve_policy(module(), keyword()) :: policy()

Resolves and validates the effective :check_origin policy.