Skip to content

Commit c53be23

Browse files
committed
FIX Filtering the HTTP Header "Accept-Language".
1 parent 9cfe126 commit c53be23

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

htdocs/core/class/translate.class.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,12 @@ public function setDefaultLang($srclang = 'en_US')
8888

8989
if (empty($srclang) || $srclang == 'auto')
9090
{
91+
// $_SERVER['HTTP_ACCEPT_LANGUAGE'] can be 'fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7,it;q=0.6' but can contains also malicious content
9192
$langpref=empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])?'':$_SERVER['HTTP_ACCEPT_LANGUAGE'];
92-
$langpref=preg_replace("/;([^,]*)/i", "", $langpref);
93+
$langpref=preg_replace("/;([^,]*)/i", "", $langpref); // Remove the 'q=x.y,' part
9394
$langpref=str_replace("-", "_", $langpref);
9495
$langlist=preg_split("/[;,]/", $langpref);
95-
$codetouse=$langlist[0];
96+
$codetouse=preg_replace('/[^_a-zA-Z]/', '', $langlist[0]);
9697
}
9798
else $codetouse=$srclang;
9899

test/phpunit/SecurityTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,24 @@ protected function tearDown()
130130
print __METHOD__."\n";
131131
}
132132

133+
/**
134+
* testSetLang
135+
*
136+
* @return string
137+
*/
138+
public function testSetLang()
139+
{
140+
global $conf;
141+
$conf=$this->savconf;
142+
143+
$tmplangs = new Translate('', $conf);
144+
145+
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = "' malicious text with quote";
146+
$tmplangs->setDefaultLang('auto');
147+
print __METHOD__.' $tmplangs->defaultlang='.$tmplangs->defaultlang."\n";
148+
$this->assertEquals($tmplangs->defaultlang, 'malicioustextwithquote_MALICIOUSTEXTWITHQUOTE');
149+
}
150+
133151
/**
134152
* testGETPOST
135153
*

0 commit comments

Comments
 (0)