mirror of
https://github.com/getformwork/formwork.git
synced 2025-02-24 01:32:25 +01:00
Validate referer before redirecting
This commit is contained in:
parent
9b405395d9
commit
05bb5b1c41
@ -84,7 +84,7 @@ trait AdminTrait
|
||||
*/
|
||||
protected function redirectToReferer($code = 302, $default = '/')
|
||||
{
|
||||
if (!is_null(HTTPRequest::referer()) && HTTPRequest::referer() !== Uri::current()) {
|
||||
if (HTTPRequest::validateReferer($this->uri('/')) && HTTPRequest::referer() !== Uri::current()) {
|
||||
Header::redirect(HTTPRequest::referer(), $code);
|
||||
} else {
|
||||
Header::redirect($this->uri($default), $code);
|
||||
|
@ -108,6 +108,19 @@ class HTTPRequest
|
||||
return static::hasHeader('Referer') ? static::$headers['Referer'] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the request referer has the same origin
|
||||
*
|
||||
* @param string $path Optional URI path
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function validateReferer($path = null)
|
||||
{
|
||||
$base = Uri::normalize(Uri::base() . '/' . ltrim($path, '/'));
|
||||
return substr(static::referer(), 0, strlen($base)) === $base;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get request origin
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user