Skip to main content

Security

Struct Security 

Source
pub struct Security { /* private fields */ }
Expand description

The access-control posture a router enforces. Cheaply cloneable (the lists are shared), because both the middleware state and the SPA handler hold one.

Implementations§

Source§

impl Security

Source

pub fn open() -> Self

No token, no Host guard, no CORS.

This is the shape an app’s in-process test router uses (Ledgeline’s app and router_with_state) so the tower::oneshot harnesses can drive routes directly. Never use it for a socket-bound server — see protect and harden.

Source

pub fn local(token: AccessToken, port: u16) -> Self

The loopback posture: require token on every wire and /api route, and reject any Host that is not a loopback name on port.

Source

pub fn in_process(token: AccessToken) -> Self

The posture for IN-PROCESS dispatch — a mobile host’s custom-scheme handler feeding requests to the router with Router::oneshot, no socket at all (ledgeline-ffi).

  • The token is still required. A scheme handler receives every request its web view makes, including one from a foreign page that somehow got loaded into it (a link followed, an injected frame): the browser enforces CORS on the response, not on whether the request is delivered, so a blind write would land without it. The host hands the token to its own pages out of band (token_init_script), as the desktop WebView gets it.
  • No Host guard. It exists against DNS rebinding, which needs a socket to rebind to. There is none, and the authority a custom scheme presents is whatever the host chose.
  • No CORS, as on every default posture.
Source

pub fn any_host(token: AccessToken) -> Self

Require token but accept any Host. Only for an explicitly requested non-loopback bind, where the legitimate Host values are unknowable — which also means this posture has NO anti-DNS-rebinding control.

Source

pub fn allow_origins<S: AsRef<str>>( self, origins: &[S], ) -> Result<Self, SecurityError>

Permit these EXACT origins to read responses cross-origin (--allow-origin). Never a wildcard: each entry is matched literally by the browser.

§Errors

SecurityError::BadOrigin if an entry is not a valid header value or does not look like a scheme-qualified origin.

Source

pub fn cors_layer(&self, extra_headers: &[HeaderName]) -> Option<CorsLayer>

The CORS layer for the allowlisted origins, or None (the default) when there are none — in which case no CORS layer is installed at all and the server is same-origin only.

extra_headers are request headers beyond Authorization, Content-Type and Accept that the app’s own client sends (Ledgeline’s statement upload names its file in one); an allowlisted origin’s preflight for any other header is refused.

Trait Implementations§

Source§

impl Clone for Security

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

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> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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