3 namespace Drupal\Core\Routing;
6 * Provides a redirect response which contains trusted URLs.
8 * Use this class in case you know that you want to redirect to an external URL.
10 class TrustedRedirectResponse extends CacheableSecuredRedirectResponse {
12 use LocalAwareRedirectResponseTrait;
15 * A list of trusted URLs, which are safe to redirect to.
19 protected $trustedUrls = [];
24 public function __construct($url, $status = 302, $headers = []) {
25 $this->trustedUrls[$url] = TRUE;
26 parent::__construct($url, $status, $headers);
30 * Sets the target URL to a trusted URL.
37 public function setTrustedTargetUrl($url) {
38 $this->trustedUrls[$url] = TRUE;
39 return $this->setTargetUrl($url);
45 protected function isSafe($url) {
46 return !empty($this->trustedUrls[$url]) || $this->isLocal($url);