diff --git a/src/Controllers/Traits/Referer.php b/src/Controllers/Traits/Referer.php index 5bd1228..bbaeaa6 100644 --- a/src/Controllers/Traits/Referer.php +++ b/src/Controllers/Traits/Referer.php @@ -4,14 +4,31 @@ trait Referer { + /** + * Verify that the referer's origin matches the origin of the given url(s) + * + * @param string|array $url If array, it would throw exception if the origin does not match any + * @throws \Exception + * @return void + */ protected function verifyReferer($url) { + if (!is_array($url)) $url = [$url]; $referer = request()->headers->get('referer'); $refOrigin = $this->originFromUrl($referer); - $urlOrigin = $this->originFromUrl($url); - if ($refOrigin !== $urlOrigin) throw new \Exception($referer . ' is not a valid domain.'); + foreach ($url as $urll) { + $urlOrigin = $this->originFromUrl($url); + if ($refOrigin == $urlOrigin) return; + } + throw new \Exception($referer . ' is not a valid domain.'); } + /** + * Gets the origin from the url string + * + * @param string $url + * @return string + */ protected function originFromUrl($url) { // remove protocol