@@ -235,19 +235,31 @@ public function set_locale( $locale ) {
235
235
$ this ->set_content_lang ( $ lang );
236
236
}
237
237
238
+ $ active_langs = bbl_get_active_langs ();
239
+ $ active_lang_codes = wp_list_pluck ( $ active_langs , 'code ' );
240
+ $ active_lang_prefixes = wp_list_pluck ( $ active_langs , 'url_prefix ' );
241
+
238
242
if ( is_admin () ) {
239
- // @FIXME: At this point a mischievous XSS "attack" could set a user's admin area language for them
240
243
if ( isset ( $ _POST [ 'interface_lang ' ] ) ) {
241
- $ this ->set_interface_lang ( $ _POST [ 'interface_lang ' ] );
244
+ $ lang = $ _POST [ 'interface_lang ' ];
245
+ if ( ! in_array ( $ lang , $ active_lang_codes , true ) ) {
246
+ $ lang = bbl_get_default_lang_code ();
247
+ }
248
+ $ this ->set_interface_lang ( $ lang );
242
249
}
243
- // @FIXME: At this point a mischievous XSS "attack" could set a user's content language for them
244
250
if ( isset ( $ _GET [ 'lang ' ] ) ) {
245
- $ this ->set_content_lang ( $ _GET [ 'lang ' ] );
251
+ $ lang = $ _GET [ 'lang ' ];
252
+ if ( ! in_array ( $ lang , $ active_lang_codes , true ) ) {
253
+ $ lang = bbl_get_default_lang_code ();
254
+ }
255
+ $ this ->set_content_lang ( $ lang );
246
256
}
247
257
} else { // Front end
248
- // @FIXME: Should probably check the available languages here
249
- if ( preg_match ( $ this ->lang_regex , $ this ->get_request_string (), $ matches ) )
250
- $ this ->set_content_lang_from_prefix ( $ matches [ 0 ] );
258
+ if ( preg_match ( $ this ->lang_regex , $ this ->get_request_string (), $ matches ) ) {
259
+ if ( in_array ( $ matches [ 0 ], $ active_lang_prefixes , true ) ) {
260
+ $ this ->set_content_lang_from_prefix ( $ matches [ 0 ] );
261
+ }
262
+ }
251
263
}
252
264
253
265
if ( ! isset ( $ this ->content_lang ) || ! $ this ->content_lang )
0 commit comments