Skip to content

Commit

Permalink
Fix potential code injection via locale parameter
Browse files Browse the repository at this point in the history
Depending on the server configuration, it seems to be possible to inject
actual JavaScript code:

    http://localhost/translations?locales=foo%0Auncommented%20code;

=>

    (function (Translator) {
        Translator.fallback      = 'en';
        Translator.defaultDomain = 'messages';
        // foo
    uncommented code;
    })(Translator);

This issue has been reported by Andreas Forsblom.

This fix filters given locales and remove all locales that are not known
by the Locale (intl extension) class.

Signed-off-by: William DURAND <william.durand1@gmail.com>
  • Loading branch information
willdurand committed Jul 29, 2014
1 parent df6c0fd commit 7accee9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Controller/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ private function getLocales(Request $request)
$locales = array($request->getLocale());
}

$locales = array_filter($locales, function ($locale) {
return strcasecmp(\Locale::getDisplayLanguage($locale), $locale) !== 0;
});

return array_unique(array_map(function ($locale) {
return trim($locale);
}, $locales));
Expand Down
18 changes: 18 additions & 0 deletions Tests/Controller/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,22 @@ public function testGetTranslationsWithPathTraversalAttack()

$this->assertEquals(200, $response->getStatusCode());
}

public function testGetTranslationsWithLocaleInjection()
{
$client = static::createClient();

$crawler = $client->request('GET', '/translations/messages.json?locales=foo%0Auncommented%20code;');
$response = $client->getResponse();

$this->assertEquals(<<<JSON
{
"fallback": "en",
"defaultDomain": "messages",
"translations": []
}
JSON
, $response->getContent());
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"require": {
"symfony/framework-bundle": "~2.3",
"symfony/finder": "~2.3",
"symfony/console": "~2.3"
"symfony/console": "~2.3",
"symfony/intl": "~2.3"
},
"require-dev": {
"symfony/yaml": "~2.3",
Expand Down

0 comments on commit 7accee9

Please sign in to comment.