r25299 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25298‎ | r25299 | r25300 >
Date:01:32, 30 August 2007
Author:brion
Status:old
Tags:
Comment:
Validate language input, for goodness' sake. :P
http://www.0x000000.com/index.php?i=405
Modified paths:
  • /trunk/wap/hawpedia.php (modified) (history)
  • /trunk/wap/settings.php (modified) (history)

Diff [purge]

Index: trunk/wap/settings.php
@@ -13,8 +13,8 @@
1414 require('lang/' . $_SESSION['language'] . '/phonenumbers.php');
1515
1616 if (isset($_GET['save'])) {
17 - // store submitted data in session
18 - if (isset($_GET['lang'])) {
 17+ // store validated submitted data in session
 18+ if (isset($_GET['lang']) && validate_language($_GET['lang'])) {
1919 $_SESSION['language'] = $_GET['lang'];
2020
2121 // unset language-specific session variables
Index: trunk/wap/hawpedia.php
@@ -51,13 +51,23 @@
5252 exit();
5353 }
5454
 55+function validate_language($lang) {
 56+ global $supportedLanguages;
 57+ return is_string($lang) &&
 58+ preg_match('/^[a-z][a-z_]*[a-z]$/', $lang) &&
 59+ isset($supportedLanguages[$lang]) &&
 60+ $supportedLanguages[$lang] == 1;
 61+}
 62+
5563 function determine_settings()
5664 {
57 - global $supportedLanguages;
 65+ // Validate previously set session data
 66+ if (isset($_SESSION['lang']) && !validate_language($_SESSION['lang'])) {
 67+ unset($_SESSION['lang']);
 68+ }
5869
5970 if (isset($_GET['lang']) &&
60 - isset($supportedLanguages[$_GET['lang']]) &&
61 - ($supportedLanguages[$_GET['lang']] == 1)) {
 71+ validate_language($_GET['lang'])) {
6272 // language explicitely requested in url parameter
6373 $_SESSION['language'] = $_GET['lang']; // overwrite session info
6474 }
@@ -65,18 +75,19 @@
6676 {
6777 // no language info stored in session
6878 if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) &&
69 - isset($supportedLanguages[$_SERVER['HTTP_ACCEPT_LANGUAGE']]) &&
70 - ($supportedLanguages[$_SERVER['HTTP_ACCEPT_LANGUAGE']] == 1) &&
 79+ validate_language($_SERVER['HTTP_ACCEPT_LANGUAGE']) &&
7180 (!defined('FORCE_DEFAULT_LANGUAGE') || !FORCE_DEFAULT_LANGUAGE))
7281 {
7382 // store browser's preference in session
 83+ // @fixme -- Won't actually work, since Accept-Language
 84+ // isn't just a language code, but a list of codes with
 85+ // priority values :)
7486 $_SESSION['language'] = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
7587 }
7688 elseif(isset($_SERVER['HTTP_HOST']) &&
7789 ($dot = strpos($_SERVER['HTTP_HOST'], '.')) &&
7890 ($domlang = substr($_SERVER['HTTP_HOST'], 0, $dot)) &&
79 - isset($supportedLanguages[$domlang]) &&
80 - ($supportedLanguages[$domlang] == 1) &&
 91+ validate_language($domlang) &&
8192 (defined('FORCE_DEFAULT_LANGUAGE') && ('subdomain'==FORCE_DEFAULT_LANGUAGE)))
8293 {
8394 // store language subdomain in session
@@ -89,6 +100,10 @@
90101 }
91102 }
92103
 104+ if (!validate_language($_SESSION['language'])) {
 105+ $_SESSION['language'] = DEFAULT_LANGUAGE;
 106+ }
 107+
93108 require('lang/' . $_SESSION['language'] . '/phonenumbers.php');
94109
95110 if (isset($_GET['tel']) &&

Status & tagging log