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
impl Security
Sourcepub fn local(token: AccessToken, port: u16) -> Self
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.
Sourcepub fn in_process(token: AccessToken) -> Self
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
Hostguard. 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.
Sourcepub fn any_host(token: AccessToken) -> Self
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.
Sourcepub fn allow_origins<S: AsRef<str>>(
self,
origins: &[S],
) -> Result<Self, SecurityError>
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.
Sourcepub fn cors_layer(&self, extra_headers: &[HeaderName]) -> Option<CorsLayer>
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§
Auto Trait Implementations§
impl Forget for Security
impl Freeze for Securitywhere
*const ArcInner<str> is !null: Freeze,
PhantomData<ArcInner<str>>: Freeze,
*const ArcInner<[String]> is !null: Freeze,
PhantomData<ArcInner<[String]>>: Freeze,
*const ArcInner<[HeaderValue]> is !null: Freeze,
PhantomData<ArcInner<[HeaderValue]>>: Freeze,
impl Move for Security
impl RefUnwindSafe for Security
impl Send for Security
impl Sync for Security
impl Unpin for Security
impl UnsafeUnpin for Securitywhere
*const ArcInner<str> is !null: UnsafeUnpin,
PhantomData<ArcInner<str>>: UnsafeUnpin,
*const ArcInner<[String]> is !null: UnsafeUnpin,
PhantomData<ArcInner<[String]>>: UnsafeUnpin,
*const ArcInner<[HeaderValue]> is !null: UnsafeUnpin,
PhantomData<ArcInner<[HeaderValue]>>: UnsafeUnpin,
impl UnwindSafe for Security
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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