Skip to content

Commit

Permalink
Response::redirect() link is printed only for https? protocols [Closes
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Nov 15, 2014
1 parent c2ca723 commit 88e0ba8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,10 @@ public function redirect($url, $code = self::S302_FOUND)
{
$this->setCode($code);
$this->setHeader('Location', $url);
$escapedUrl = htmlSpecialChars($url, ENT_IGNORE | ENT_QUOTES);
echo "<h1>Redirect</h1>\n\n<p><a href=\"$escapedUrl\">Please click here to continue</a>.</p>";
if (preg_match('#^https?:|^\s*+[a-z0-9+.-]*+[^:]#i', $url)) {
$escapedUrl = htmlSpecialChars($url, ENT_IGNORE | ENT_QUOTES);
echo "<h1>Redirect</h1>\n\n<p><a href=\"$escapedUrl\">Please click here to continue</a>.</p>";
}
}


Expand Down
34 changes: 34 additions & 0 deletions tests/Http/Response.redirect.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/**
* Test: Nette\Http\Response redirect.
*/

use Nette\Http,
Tester\Assert;


require __DIR__ . '/../bootstrap.php';


$response = new Http\Response;

ob_start();
$response->redirect('http://nette.org/&');
Assert::same("<h1>Redirect</h1>\n\n<p><a href=\"http://nette.org/&amp;\">Please click here to continue</a>.</p>", ob_get_clean());

if (PHP_SAPI !== 'cli') {
Assert::contains('Location: http://nette.org/&', headers_list());
}


ob_start();
$response->redirect(' javascript:alert(1)');
Assert::same('', ob_get_clean());

if (PHP_SAPI !== 'cli') {
Assert::contains('Location: javascript:alert(1)', headers_list());
}


$response->setCode(200);

0 comments on commit 88e0ba8

Please sign in to comment.