Skip to content

Commit d861843

Browse files
committed
1 parent 052ab23 commit d861843

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Controller/Controller.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
use Symfony\Component\Config\ConfigCache;
1818
use Symfony\Component\HttpFoundation\Request;
1919
use Symfony\Component\HttpFoundation\Response;
20-
use Symfony\Component\HttpKernel\Kernel;
2120
use Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag;
21+
use Symfony\Component\HttpKernel\Exception\HttpException;
22+
use Symfony\Component\HttpKernel\Kernel;
2223

2324
/**
2425
* Controller class.
@@ -100,7 +101,11 @@ public function indexAction(Request $request, $_format)
100101

101102
$content = file_get_contents((string) $cache);
102103

103-
if ($callback = $request->query->get('callback')) {
104+
if (null !== $callback = $request->query->get('callback')) {
105+
if (false === ctype_alnum($callback)) {
106+
throw new HttpException(400, 'Invalid JSONP callback value');
107+
}
108+
104109
$content = $callback.'('.$content.');';
105110
}
106111

Tests/Controller/ControllerTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ public function testGenerateWithCallback()
4747
$this->assertEquals('foo({"base_url":"","routes":[],"prefix":"","host":"","scheme":""});', $response->getContent());
4848
}
4949

50+
/**
51+
* @expectedException Symfony\Component\HttpKernel\Exception\HttpException
52+
*/
53+
public function testGenerateWithInvalidCallback()
54+
{
55+
$controller = new Controller($this->getSerializer(), $this->getExtractor());
56+
$response = $controller->indexAction($this->getRequest('/', 'GET', array('callback' => '(function xss(x){evil()})')), 'json');
57+
}
58+
5059
public function testIndexActionWithoutRoutes()
5160
{
5261
$controller = new Controller($this->getSerializer(), $this->getExtractor(), array(), sys_get_temp_dir());

0 commit comments

Comments
 (0)