Skip to content

Commit 548c545

Browse files
committed
Merge branch 'fix/validation' into develop
* fix/validation: Validate the content lang and interface lang before setting them. See #227.
2 parents 96ad102 + 7461466 commit 548c545

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

class-locale.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,19 +235,31 @@ public function set_locale( $locale ) {
235235
$this->set_content_lang( $lang );
236236
}
237237

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+
238242
if ( is_admin() ) {
239-
// @FIXME: At this point a mischievous XSS "attack" could set a user's admin area language for them
240243
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 );
242249
}
243-
// @FIXME: At this point a mischievous XSS "attack" could set a user's content language for them
244250
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 );
246256
}
247257
} 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+
}
251263
}
252264

253265
if ( ! isset( $this->content_lang ) || ! $this->content_lang )

0 commit comments

Comments
 (0)