pub struct Redirect { /* private fields */ }Expand description
HTTP redirect response.
Implementations§
Source§impl Redirect
impl Redirect
Sourcepub fn to(uri: impl Into<String>) -> Result<Self, RedirectError>
pub fn to(uri: impl Into<String>) -> Result<Self, RedirectError>
302 Found redirect.
§Safe-by-default validation (br-asupersync-0hj233)
Returns Err(RedirectError) for any URI that is not a
site-relative path (/foo). Specifically rejects:
- empty strings,
- protocol-relative URIs (
//attacker.com/...), - URIs containing backslash (
/\\attacker.com/...), - any URI with a scheme (
javascript:,https://attacker.com/, …).
For redirects that legitimately point at an external host (OAuth
callbacks, payment hand-offs), use Self::to_with_allowed_hosts
(validated against an allowlist) or Self::external_unchecked
(caller asserts the URI is trustworthy).
Sourcepub fn permanent(uri: impl Into<String>) -> Result<Self, RedirectError>
pub fn permanent(uri: impl Into<String>) -> Result<Self, RedirectError>
301 Moved Permanently redirect. Same safe-by-default validation
as Self::to; see that method for details.
Sourcepub fn temporary(uri: impl Into<String>) -> Result<Self, RedirectError>
pub fn temporary(uri: impl Into<String>) -> Result<Self, RedirectError>
307 Temporary Redirect (preserves method). Same safe-by-default
validation as Self::to; see that method for details.
Sourcepub fn to_with_allowed_hosts(
uri: impl Into<String>,
allowed_hosts: &[&str],
) -> Result<Self, RedirectError>
pub fn to_with_allowed_hosts( uri: impl Into<String>, allowed_hosts: &[&str], ) -> Result<Self, RedirectError>
302 Found redirect with an explicit allowed-hosts allowlist (br-asupersync-0hj233).
Accepts site-relative paths AND absolute http(s) URIs whose
host appears (case-insensitive) in allowed_hosts. Use this
for redirect flows whose target host space is
statically-known (OAuth providers, payment gateways).
Sourcepub fn external_unchecked(uri: impl Into<String>) -> Self
pub fn external_unchecked(uri: impl Into<String>) -> Self
Unchecked 302 Found redirect — caller asserts the URI is trustworthy (br-asupersync-0hj233).
This bypasses the open-redirect validation in Self::to.
Use ONLY when the URI is genuinely controlled by the
application (a hard-coded constant, a value derived from
trusted server-side state, or an OAuth provider URL whose
host is independently verified). NEVER pass user-supplied
strings (URL parameters, form fields, request body) to this
constructor — that’s the canonical phishing vector this bead
is defending against.
The CRLF stripping in the wire-format step (see
into_response) still applies — this only bypasses the
scheme/host validation.
Sourcepub fn external_unchecked_permanent(uri: impl Into<String>) -> Self
pub fn external_unchecked_permanent(uri: impl Into<String>) -> Self
Unchecked 301 Moved Permanently redirect; see
Self::external_unchecked for the safety contract.
Sourcepub fn external_unchecked_temporary(uri: impl Into<String>) -> Self
pub fn external_unchecked_temporary(uri: impl Into<String>) -> Self
Unchecked 307 Temporary Redirect; see
Self::external_unchecked for the safety contract.
Trait Implementations§
Source§impl IntoResponse for Redirect
impl IntoResponse for Redirect
Source§fn into_response(self) -> Response
fn into_response(self) -> Response
Response.