Skip to content

Commit 7accee9

Browse files
committed
Fix potential code injection via locale parameter
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>
1 parent df6c0fd commit 7accee9

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

Diff for: Controller/Controller.php

+4
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ private function getLocales(Request $request)
173173
$locales = array($request->getLocale());
174174
}
175175

176+
$locales = array_filter($locales, function ($locale) {
177+
return strcasecmp(\Locale::getDisplayLanguage($locale), $locale) !== 0;
178+
});
179+
176180
return array_unique(array_map(function ($locale) {
177181
return trim($locale);
178182
}, $locales));

Diff for: Tests/Controller/ControllerTest.php

+18
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,22 @@ public function testGetTranslationsWithPathTraversalAttack()
197197

198198
$this->assertEquals(200, $response->getStatusCode());
199199
}
200+
201+
public function testGetTranslationsWithLocaleInjection()
202+
{
203+
$client = static::createClient();
204+
205+
$crawler = $client->request('GET', '/translations/messages.json?locales=foo%0Auncommented%20code;');
206+
$response = $client->getResponse();
207+
208+
$this->assertEquals(<<<JSON
209+
{
210+
"fallback": "en",
211+
"defaultDomain": "messages",
212+
"translations": []
213+
}
214+
215+
JSON
216+
, $response->getContent());
217+
}
200218
}

Diff for: composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"require": {
1414
"symfony/framework-bundle": "~2.3",
1515
"symfony/finder": "~2.3",
16-
"symfony/console": "~2.3"
16+
"symfony/console": "~2.3",
17+
"symfony/intl": "~2.3"
1718
},
1819
"require-dev": {
1920
"symfony/yaml": "~2.3",

0 commit comments

Comments
 (0)