@@ -82,10 +82,7 @@ public function __construct(
8282 public function get ($ app , $ lang = null , $ locale = null ) {
8383 return new LazyL10N (function () use ($ app , $ lang , $ locale ) {
8484 $ app = \OC_App::cleanAppId ($ app );
85- if ($ lang !== null ) {
86- $ lang = str_replace (['\0 ' , '/ ' , '\\' , '.. ' ], '' , $ lang );
87- }
88-
85+ $ lang = $ this ->cleanLanguage ($ lang );
8986 $ forceLang = $ this ->config ->getSystemValue ('force_language ' , false );
9087 if (is_string ($ forceLang )) {
9188 $ lang = $ forceLang ;
@@ -118,6 +115,29 @@ public function get($app, $lang = null, $locale = null) {
118115 });
119116 }
120117
118+ /**
119+ * Remove some invalid characters before using a string as a language
120+ *
121+ * @psalm-taint-escape callable
122+ * @psalm-taint-escape cookie
123+ * @psalm-taint-escape file
124+ * @psalm-taint-escape has_quotes
125+ * @psalm-taint-escape header
126+ * @psalm-taint-escape html
127+ * @psalm-taint-escape include
128+ * @psalm-taint-escape ldap
129+ * @psalm-taint-escape shell
130+ * @psalm-taint-escape sql
131+ * @psalm-taint-escape unserialize
132+ */
133+ private function cleanLanguage (?string $ lang ): ?string {
134+ if ($ lang === null ) {
135+ return null ;
136+ }
137+ $ lang = preg_replace ('/[^a-zA-Z0-9.;,=-]/ ' , '' , $ lang );
138+ return str_replace ('.. ' , '' , $ lang );
139+ }
140+
121141 /**
122142 * Find the best language
123143 *
@@ -427,7 +447,7 @@ public function localeExists($locale) {
427447 * @throws LanguageNotFoundException
428448 */
429449 private function getLanguageFromRequest (?string $ app = null ): string {
430- $ header = $ this ->request ->getHeader ('ACCEPT_LANGUAGE ' );
450+ $ header = $ this ->cleanLanguage ( $ this -> request ->getHeader ('ACCEPT_LANGUAGE ' ) );
431451 if ($ header !== '' ) {
432452 $ available = $ this ->findAvailableLanguages ($ app );
433453
0 commit comments