howdy/websocket/origin

Internal browser-origin validation shared by every socket upgrade.

The same-origin policy compares the browser’s origin with the origin it reached the app at. Behind a proxy that ends TLS, the app sees plain HTTP, so the scheme comes from x-forwarded-proto and, for proxies that rewrite host, the authority from x-forwarded-host. Trusting them is safe here, unlike for a client’s address: a hostile page cannot set either header on a browser’s socket handshake, and a client outside a browser can send any origin it likes anyway.

Types

pub opaque type Origin
pub type Policy {
  SameOrigin
  Allowlist(List(Origin))
}

Constructors

  • SameOrigin
  • Allowlist(List(Origin))

Values

pub fn allowed(
  req: request.Request(body),
  policy: Policy,
  required: Bool,
) -> Bool
pub fn allowlist(values: List(String)) -> Policy
✨ Search Document