class TrustedRedirectResponse extends CacheableSecuredRedirectResponse (View source)

Provides a redirect response which contains trusted URLs.

Use this class in case you know that you want to redirect to an external URL.

Traits

Provides a trait which ensures that a URL is safe to redirect to.

Provides an implementation of CacheableResponseInterface.

Properties

protected CacheableMetadata $cacheabilityMetadata

The cacheability metadata.

from  CacheableResponseTrait
protected RequestContext $requestContext

The request context.

from  LocalAwareRedirectResponseTrait
protected string[] $trustedUrls

A list of trusted URLs, which are safe to redirect to.

Methods

createFromRedirectResponse(RedirectResponse $response)

Copies an existing redirect response into a safe one.

fromResponse(RedirectResponse $response)

Copies over the values from the given response.

setTargetUrl($url)

{@inheritdoc}

bool
isSafe(string $url)

Returns whether the URL is considered as safe to redirect to.

addCacheableDependency($dependency)

{@inheritdoc}

bool
isLocal(string $url)

Determines whether a path is local.

$this
setRequestContext(RequestContext $request_context)

Sets the request context.

__construct($url, $status = 302, $headers = [])

{@inheritdoc}

$this
setTrustedTargetUrl(string $url)

Sets the target URL to a trusted URL.

Details

static SecuredRedirectResponse createFromRedirectResponse(RedirectResponse $response)

Copies an existing redirect response into a safe one.

The safe one cannot accidentally redirect to an external URL, unless actively wanted (see TrustedRedirectResponse).

Parameters

RedirectResponse $response

The original redirect.

Return Value

SecuredRedirectResponse

protected fromResponse(RedirectResponse $response)

Copies over the values from the given response.

Parameters

RedirectResponse $response

The redirect response object.

setTargetUrl($url)

{@inheritdoc}

Parameters

$url

protected bool isSafe(string $url)

Returns whether the URL is considered as safe to redirect to.

Parameters

string $url

The URL checked for safety.

Return Value

bool

addCacheableDependency($dependency)

{@inheritdoc}

Parameters

$dependency

getCacheableMetadata()

{@inheritdoc}

protected bool isLocal(string $url)

Determines whether a path is local.

Parameters

string $url

The internal path or external URL being linked to, such as "node/34" or "http://example.com/foo".

Return Value

bool

TRUE or FALSE, where TRUE indicates a local path.

protected RequestContext getRequestContext()

Returns the request context.

Return Value

RequestContext

The request context.

$this setRequestContext(RequestContext $request_context)

Sets the request context.

Parameters

RequestContext $request_context

The request context.

Return Value

$this

__construct($url, $status = 302, $headers = [])

{@inheritdoc}

Parameters

$url
$status
$headers

$this setTrustedTargetUrl(string $url)

Sets the target URL to a trusted URL.

Parameters

string $url

A trusted URL.

Return Value

$this