Remove invalid characters from REQUEST_URI

This commit is contained in:
Kijin Sung 2018-07-31 19:08:02 +09:00
parent b62a1322c9
commit 109203d12b
3 changed files with 11 additions and 3 deletions

View file

@ -18,7 +18,8 @@ class URL
*/
public static function getCurrentURL(array $changes = array())
{
$url = self::getCurrentDomainURL(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/');
$request_uri = preg_replace('/[<>"]/', '', isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/');
$url = self::getCurrentDomainURL($request_uri);
if (count($changes))
{
return self::modifyURL($url, $changes);

View file

@ -917,7 +917,7 @@ function getScriptPath()
*/
function getRequestUriByServerEnviroment()
{
return escape($_SERVER['REQUEST_URI']);
return preg_replace('/[<>"]/', '', $_SERVER['REQUEST_URI']);
}
/**

View file

@ -9,7 +9,7 @@ class URLTest extends \Codeception\TestCase\Test
// Getting the current URL
$this->assertEquals('https://www.rhymix.org/rhymix/index.php?foo=bar&xe=sucks', Rhymix\Framework\URL::getCurrentURL());
// Adding items to the query string
$this->assertEquals('https://www.rhymix.org/rhymix/index.php?foo=bar&xe=sucks&var=1&arr%5B0%5D=2&arr%5B1%5D=3', Rhymix\Framework\URL::getCurrentURL(array('var' => '1', 'arr' => array(2, 3))));
@ -22,6 +22,13 @@ class URLTest extends \Codeception\TestCase\Test
// Adding and removing parameters at the same time
$this->assertEquals('https://www.rhymix.org/rhymix/index.php?xe=sucks&l=ko', Rhymix\Framework\URL::getCurrentURL(array('l' => 'ko', 'foo' => null)));
// Removing invalid characters in the current URL
$_SERVER['REQUEST_URI'] = '/rhymix/?foo="bar"';
$this->assertEquals('https://www.rhymix.org/rhymix/?foo=bar', Rhymix\Framework\URL::getCurrentURL());
$_SERVER['REQUEST_URI'] = '/rhymix/?foo=<bar&baz=rhymix>';
$this->assertEquals('https://www.rhymix.org/rhymix/?foo=bar&baz=rhymix', Rhymix\Framework\URL::getCurrentURL());
$this->assertEquals('https://www.rhymix.org/rhymix/?baz=rhymix&l=ko', Rhymix\Framework\URL::getCurrentURL(array('l' => 'ko', 'foo' => null)));
$_SERVER['REQUEST_URI'] = $old_request_uri;
}