Skip to content

Commit e3a28eb

Browse files
committed
Merge pull request #807 from willdurand/jsonp-rosetta
Mitigate CSRF bypassing Same Origin Policy attack
2 parents 1ca8cbe + 9a57653 commit e3a28eb

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

Resources/doc/2-the-view-layer.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,15 @@ fos_rest:
304304
callback_param: false
305305
```
306306
307+
When working with JSONP, be aware of
308+
[CVE-2014-4671](http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2014-4671)
309+
(full explanation can be found here: [Abusing JSONP with Rosetta
310+
Flash](http://miki.it/blog/2014/7/8/abusing-jsonp-with-rosetta-flash/)). You
311+
SHOULD use
312+
[NelmioSecurityBundle](https://github.com/nelmio/NelmioSecurityBundle) and
313+
[disable the content type sniffing for script
314+
resources](https://github.com/nelmio/NelmioSecurityBundle#content-type-sniffing).
315+
307316
#### CSRF validation
308317
309318
When building a single application that should handle forms both via HTML forms as well

Tests/View/JsonpHandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function testHandle($query)
6262

6363
$response = $viewHandler->handle($view, $request);
6464

65-
$this->assertEquals(reset($query).'('.var_export($data, true).')', $response->getContent());
65+
$this->assertEquals('/**/'.reset($query).'('.var_export($data, true).')', $response->getContent());
6666
}
6767

6868
public static function handleDataProvider()

View/JsonpHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function createResponse(ViewHandler $handler, View $view, Request $reques
5757

5858
if ($response->isSuccessful()) {
5959
$callback = $this->getCallback($request);
60-
$response->setContent($callback.'('.$response->getContent().')');
60+
$response->setContent(sprintf('/**/%s(%s)', $callback, $response->getContent()));
6161
$response->headers->set('Content-Type', $request->getMimeType($format));
6262
}
6363

0 commit comments

Comments
 (0)