Security update for Core, with self-updated composer
[yaffs-website] / web / core / lib / Drupal / Core / Routing / TrustedRedirectResponse.php
1 <?php
2
3 namespace Drupal\Core\Routing;
4
5 /**
6  * Provides a redirect response which contains trusted URLs.
7  *
8  * Use this class in case you know that you want to redirect to an external URL.
9  */
10 class TrustedRedirectResponse extends CacheableSecuredRedirectResponse {
11
12   use LocalAwareRedirectResponseTrait;
13
14   /**
15    * A list of trusted URLs, which are safe to redirect to.
16    *
17    * @var string[]
18    */
19   protected $trustedUrls = [];
20
21   /**
22    * {@inheritdoc}
23    */
24   public function __construct($url, $status = 302, $headers = []) {
25     $this->trustedUrls[$url] = TRUE;
26     parent::__construct($url, $status, $headers);
27   }
28
29   /**
30    * Sets the target URL to a trusted URL.
31    *
32    * @param string $url
33    *   A trusted URL.
34    *
35    * @return $this
36    */
37   public function setTrustedTargetUrl($url) {
38     $this->trustedUrls[$url] = TRUE;
39     return $this->setTargetUrl($url);
40   }
41
42   /**
43    * {@inheritdoc}
44    */
45   protected function isSafe($url) {
46     return !empty($this->trustedUrls[$url]) || $this->isLocal($url);
47   }
48
49 }