r46889 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r46888‎ | r46889 | r46890 >
Date:03:46, 6 February 2009
Author:tstarling
Status:deferred
Tags:
Comment:
More installer XSS
Modified paths:
  • /trunk/phase3/config/index.php (modified) (history)
  • /trunk/phase3/includes/db/DatabasePostgres.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/db/DatabasePostgres.php
@@ -208,10 +208,10 @@
209209 $version = $this->getServerVersion();
210210 $PGMINVER = '8.1';
211211 if ($version < $PGMINVER) {
212 - print "<b>FAILED</b>. Required version is $PGMINVER. You have $version</li>\n";
 212+ print "<b>FAILED</b>. Required version is $PGMINVER. You have " . htmlspecialchars( $version ) . "</li>\n";
213213 dieout("</ul>");
214214 }
215 - print "version $this->numeric_version is OK.</li>\n";
 215+ print "version " . htmlspecialchars( $this->numeric_version ) . " is OK.</li>\n";
216216
217217 $safeuser = $this->quote_ident($wgDBuser);
218218 // Are we connecting as a superuser for the first time?
@@ -225,7 +225,7 @@
226226 FROM pg_catalog.pg_user WHERE usename = " . $this->addQuotes($wgDBsuperuser);
227227 $rows = $this->numRows($res = $this->doQuery($SQL));
228228 if (!$rows) {
229 - print "<li>ERROR: Could not read permissions for user \"$wgDBsuperuser\"</li>\n";
 229+ print "<li>ERROR: Could not read permissions for user \"" . htmlspecialchars( $wgDBsuperuser ) . "\"</li>\n";
230230 dieout('</ul>');
231231 }
232232 $perms = pg_fetch_result($res, 0, 0);
@@ -233,15 +233,15 @@
234234 $SQL = "SELECT 1 FROM pg_catalog.pg_user WHERE usename = " . $this->addQuotes($wgDBuser);
235235 $rows = $this->numRows($this->doQuery($SQL));
236236 if ($rows) {
237 - print "<li>User \"$wgDBuser\" already exists, skipping account creation.</li>";
 237+ print "<li>User \"" . htmlspecialchars( $wgDBuser ) . "\" already exists, skipping account creation.</li>";
238238 }
239239 else {
240240 if ($perms != 1 and $perms != 3) {
241 - print "<li>ERROR: the user \"$wgDBsuperuser\" cannot create other users. ";
 241+ print "<li>ERROR: the user \"" . htmlspecialchars( $wgDBsuperuser ) . "\" cannot create other users. ";
242242 print 'Please use a different Postgres user.</li>';
243243 dieout('</ul>');
244244 }
245 - print "<li>Creating user <b>$wgDBuser</b>...";
 245+ print "<li>Creating user <b>" . htmlspecialchars( $wgDBuser ) . "</b>...";
246246 $safepass = $this->addQuotes($wgDBpassword);
247247 $SQL = "CREATE USER $safeuser NOCREATEDB PASSWORD $safepass";
248248 $this->doQuery($SQL);
@@ -252,15 +252,15 @@
253253 $SQL = "SELECT 1 FROM pg_catalog.pg_database WHERE datname = " . $this->addQuotes($wgDBname);
254254 $rows = $this->numRows($this->doQuery($SQL));
255255 if ($rows) {
256 - print "<li>Database \"$wgDBname\" already exists, skipping database creation.</li>";
 256+ print "<li>Database \"" . htmlspecialchars( $wgDBname ) . "\" already exists, skipping database creation.</li>";
257257 }
258258 else {
259259 if ($perms < 2) {
260 - print "<li>ERROR: the user \"$wgDBsuperuser\" cannot create databases. ";
 260+ print "<li>ERROR: the user \"" . htmlspecialchars( $wgDBsuperuser ) . "\" cannot create databases. ";
261261 print 'Please use a different Postgres user.</li>';
262262 dieout('</ul>');
263263 }
264 - print "<li>Creating database <b>$wgDBname</b>...";
 264+ print "<li>Creating database <b>" . htmlspecialchars( $wgDBname ) . "</b>...";
265265 $safename = $this->quote_ident($wgDBname);
266266 $SQL = "CREATE DATABASE $safename OWNER $safeuser ";
267267 $this->doQuery($SQL);
@@ -269,17 +269,21 @@
270270 }
271271
272272 // Reconnect to check out tsearch2 rights for this user
273 - print "<li>Connecting to \"$wgDBname\" as superuser \"$wgDBsuperuser\" to check rights...";
 273+ print "<li>Connecting to \"" . htmlspecialchars( $wgDBname ) . "\" as superuser \"" .
 274+ htmlspecialchars( $wgDBsuperuser ) . "\" to check rights...";
274275
275 - $hstring="";
 276+ $connectVars = array();
276277 if ($this->mServer!=false && $this->mServer!="") {
277 - $hstring="host=$this->mServer ";
 278+ $connectVars['host'] = $this->mServer;
278279 }
279280 if ($this->mPort!=false && $this->mPort!="") {
280 - $hstring .= "port=$this->mPort ";
 281+ $connectVars['port'] = $this->mPort;
281282 }
 283+ $connectVars['dbname'] = $wgDBname;
 284+ $connectVars['user'] = $wgDBsuperuser;
 285+ $connectVars['password'] = $password;
282286
283 - @$this->mConn = pg_connect("$hstring dbname=$wgDBname user=$wgDBsuperuser password=$password");
 287+ @$this->mConn = pg_connect( $this->makeConnectionString( $connectVars ) );
284288 if ( $this->mConn == false ) {
285289 print "<b>FAILED TO CONNECT!</b></li>";
286290 dieout("</ul>");
@@ -289,15 +293,18 @@
290294
291295 if ($this->numeric_version < 8.3) {
292296 // Tsearch2 checks
293 - print "<li>Checking that tsearch2 is installed in the database \"$wgDBname\"...";
 297+ print "<li>Checking that tsearch2 is installed in the database \"" .
 298+ htmlspecialchars( $wgDBname ) . "\"...";
294299 if (! $this->tableExists("pg_ts_cfg", $wgDBts2schema)) {
295 - print "<b>FAILED</b>. tsearch2 must be installed in the database \"$wgDBname\".";
 300+ print "<b>FAILED</b>. tsearch2 must be installed in the database \"" .
 301+ htmlspecialchars( $wgDBname ) . "\".";
296302 print "Please see <a href='http://www.devx.com/opensource/Article/21674/0/page/2'>this article</a>";
297303 print " for instructions or ask on #postgresql on irc.freenode.net</li>\n";
298304 dieout("</ul>");
299305 }
300306 print "OK</li>\n";
301 - print "<li>Ensuring that user \"$wgDBuser\" has select rights on the tsearch2 tables...";
 307+ print "<li>Ensuring that user \"" . htmlspecialchars( $wgDBuser ) .
 308+ "\" has select rights on the tsearch2 tables...";
302309 foreach (array('cfg','cfgmap','dict','parser') as $table) {
303310 $SQL = "GRANT SELECT ON pg_ts_$table TO $safeuser";
304311 $this->doQuery($SQL);
@@ -309,7 +316,7 @@
310317 $result = $this->schemaExists($wgDBmwschema);
311318 $safeschema = $this->quote_ident($wgDBmwschema);
312319 if (!$result) {
313 - print "<li>Creating schema <b>$wgDBmwschema</b> ...";
 320+ print "<li>Creating schema <b>" . htmlspecialchars( $wgDBmwschema ) . "</b> ...";
314321 $result = $this->doQuery("CREATE SCHEMA $safeschema AUTHORIZATION $safeuser");
315322 if (!$result) {
316323 print "<b>FAILED</b>.</li>\n";
@@ -355,7 +362,7 @@
356363
357364 if ($this->numeric_version < 8.3) {
358365 // Do we have the basic tsearch2 table?
359 - print "<li>Checking for tsearch2 in the schema \"$wgDBts2schema\"...";
 366+ print "<li>Checking for tsearch2 in the schema \"" . htmlspecialchars( $wgDBts2schema ) . "\"...";
360367 if (! $this->tableExists("pg_ts_dict", $wgDBts2schema)) {
361368 print "<b>FAILED</b>. Make sure tsearch2 is installed. See <a href=";
362369 print "'http://www.devx.com/opensource/Article/21674/0/page/2'>this article</a>";
@@ -375,12 +382,13 @@
376383 $SQL = "SELECT count(*) FROM $safetsschema.pg_ts_$tname";
377384 $res = $this->doQuery($SQL);
378385 if (!$res) {
379 - print "<b>FAILED</b> to access pg_ts_$tname. Make sure that the user ".
380 - "\"$wgDBuser\" has SELECT access to all four tsearch2 tables</li>\n";
 386+ print "<b>FAILED</b> to access " . htmlspecialchars( "pg_ts_$tname" ) .
 387+ ". Make sure that the user \"". htmlspecialchars( $wgDBuser ) .
 388+ "\" has SELECT access to all four tsearch2 tables</li>\n";
381389 dieout("</ul>");
382390 }
383391 }
384 - $SQL = "SELECT ts_name FROM $safetsschema.pg_ts_cfg WHERE locale = '$ctype'";
 392+ $SQL = "SELECT ts_name FROM $safetsschema.pg_ts_cfg WHERE locale = " . $this->addQuotes( $ctype ) ;
385393 $SQL .= " ORDER BY CASE WHEN ts_name <> 'default' THEN 1 ELSE 0 END";
386394 $res = $this->doQuery($SQL);
387395 error_reporting( E_ALL );
@@ -391,28 +399,30 @@
392400 print "OK</li>";
393401
394402 // Will the current locale work? Can we force it to?
395 - print "<li>Verifying tsearch2 locale with $ctype...";
 403+ print "<li>Verifying tsearch2 locale with " . htmlspecialchars( $ctype ) . "...";
396404 $rows = $this->numRows($res);
397405 $resetlocale = 0;
398406 if (!$rows) {
399407 print "<b>not found</b></li>\n";
400 - print "<li>Attempting to set default tsearch2 locale to \"$ctype\"...";
 408+ print "<li>Attempting to set default tsearch2 locale to \"" . htmlspecialchars( $ctype ) . "\"...";
401409 $resetlocale = 1;
402410 }
403411 else {
404412 $tsname = pg_fetch_result($res, 0, 0);
405413 if ($tsname != 'default') {
406 - print "<b>not set to default ($tsname)</b>";
407 - print "<li>Attempting to change tsearch2 default locale to \"$ctype\"...";
 414+ print "<b>not set to default (" . htmlspecialchars( $tsname ) . ")</b>";
 415+ print "<li>Attempting to change tsearch2 default locale to \"" .
 416+ htmlspecialchars( $ctype ) . "\"...";
408417 $resetlocale = 1;
409418 }
410419 }
411420 if ($resetlocale) {
412 - $SQL = "UPDATE $safetsschema.pg_ts_cfg SET locale = '$ctype' WHERE ts_name = 'default'";
 421+ $SQL = "UPDATE $safetsschema.pg_ts_cfg SET locale = " . $this->addQuotes( $ctype ) . " WHERE ts_name = 'default'";
413422 $res = $this->doQuery($SQL);
414423 if (!$res) {
415424 print "<b>FAILED</b>. ";
416 - print "Please make sure that the locale in pg_ts_cfg for \"default\" is set to \"$ctype\"</li>\n";
 425+ print "Please make sure that the locale in pg_ts_cfg for \"default\" is set to \"" .
 426+ htmlspecialchars( $ctype ) . "\"</li>\n";
417427 dieout("</ul>");
418428 }
419429 print "OK</li>";
@@ -422,7 +432,7 @@
423433 $SQL = "SELECT $safetsschema.to_tsvector('default','MediaWiki tsearch2 testing')";
424434 $res = $this->doQuery($SQL);
425435 if (!$res) {
426 - print "<b>FAILED</b>. Specifically, \"$SQL\" did not work.</li>";
 436+ print "<b>FAILED</b>. Specifically, \"" . htmlspecialchars( $SQL ) . "\" did not work.</li>";
427437 dieout("</ul>");
428438 }
429439 print "OK</li>";
@@ -434,28 +444,32 @@
435445 // Does the schema already exist? Who owns it?
436446 $result = $this->schemaExists($wgDBmwschema);
437447 if (!$result) {
438 - print "<li>Creating schema <b>$wgDBmwschema</b> ...";
 448+ print "<li>Creating schema <b>" . htmlspecialchars( $wgDBmwschema ) . "</b> ...";
439449 error_reporting( 0 );
440450 $safeschema = $this->quote_ident($wgDBmwschema);
441451 $result = $this->doQuery("CREATE SCHEMA $safeschema");
442452 error_reporting( E_ALL );
443453 if (!$result) {
444 - print "<b>FAILED</b>. The user \"$wgDBuser\" must be able to access the schema. ".
 454+ print "<b>FAILED</b>. The user \"" . htmlspecialchars( $wgDBuser ) .
 455+ "\" must be able to access the schema. ".
445456 "You can try making them the owner of the database, or try creating the schema with a ".
446 - "different user, and then grant access to the \"$wgDBuser\" user.</li>\n";
 457+ "different user, and then grant access to the \"" .
 458+ htmlspecialchars( $wgDBuser ) . "\" user.</li>\n";
447459 dieout("</ul>");
448460 }
449461 print "OK</li>\n";
450462 }
451463 else if ($result != $wgDBuser) {
452 - print "<li>Schema \"$wgDBmwschema\" exists but is not owned by \"$wgDBuser\". Not ideal.</li>\n";
 464+ print "<li>Schema \"" . htmlspecialchars( $wgDBmwschema ) . "\" exists but is not owned by \"" .
 465+ htmlspecialchars( $wgDBuser ) . "\". Not ideal.</li>\n";
453466 }
454467 else {
455 - print "<li>Schema \"$wgDBmwschema\" exists and is owned by \"$wgDBuser\". Excellent.</li>\n";
 468+ print "<li>Schema \"" . htmlspecialchars( $wgDBmwschema ) . "\" exists and is owned by \"" .
 469+ htmlspecialchars( $wgDBuser ) . "\". Excellent.</li>\n";
456470 }
457471
458472 // Always return GMT time to accomodate the existing integer-based timestamp assumption
459 - print "<li>Setting the timezone to GMT for user \"$wgDBuser\" ...";
 473+ print "<li>Setting the timezone to GMT for user \"" . htmlspecialchars( $wgDBuser ) . "\" ...";
460474 $SQL = "ALTER USER $safeuser SET timezone = 'GMT'";
461475 $result = pg_query($this->mConn, $SQL);
462476 if (!$result) {
@@ -471,7 +485,7 @@
472486 dieout("</ul>");
473487 }
474488
475 - print "<li>Setting the datestyle to ISO, YMD for user \"$wgDBuser\" ...";
 489+ print "<li>Setting the datestyle to ISO, YMD for user \"" . htmlspecialchars( $wgDBuser ) . "\" ...";
476490 $SQL = "ALTER USER $safeuser SET datestyle = 'ISO, YMD'";
477491 $result = pg_query($this->mConn, $SQL);
478492 if (!$result) {
@@ -488,7 +502,7 @@
489503 }
490504
491505 // Fix up the search paths if needed
492 - print "<li>Setting the search path for user \"$wgDBuser\" ...";
 506+ print "<li>Setting the search path for user \"" . htmlspecialchars( $wgDBuser ) . "\" ...";
493507 $path = $this->quote_ident($wgDBmwschema);
494508 if ($wgDBts2schema !== $wgDBmwschema)
495509 $path .= ", ". $this->quote_ident($wgDBts2schema);
@@ -529,12 +543,14 @@
530544 $result = $this->doQuery("CREATE LANGUAGE plpgsql");
531545 error_reporting($olde);
532546 if (!$result) {
533 - print "<b>FAILED</b>. You need to install the language plpgsql in the database <tt>$wgDBname</tt></li>";
 547+ print "<b>FAILED</b>. You need to install the language plpgsql in the database <tt>" .
 548+ htmlspecialchars( $wgDBname ) . "</tt></li>";
534549 dieout("</ul>");
535550 }
536551 }
537552 else {
538 - print "<b>FAILED</b>. You need to install the language plpgsql in the database <tt>$wgDBname</tt></li>";
 553+ print "<b>FAILED</b>. You need to install the language plpgsql in the database <tt>" .
 554+ htmlspecialchars( $wgDBname ) . "</tt></li>";
539555 dieout("</ul>");
540556 }
541557 }
@@ -1229,7 +1245,8 @@
12301246 $res = $this->doQuery($SQL);
12311247 error_reporting( $olde );
12321248 if (!$res) {
1233 - print "<b>FAILED</b>. Make sure that the user \"$wgDBuser\" can write to the schema \"$wgDBmwschema\"</li>\n";
 1249+ print "<b>FAILED</b>. Make sure that the user \"" . htmlspecialchars( $wgDBuser ) .
 1250+ "\" can write to the schema \"" . htmlspecialchars( $wgDBmwschema ) . "\"</li>\n";
12341251 dieout("</ul>");
12351252 }
12361253 $this->doQuery("DROP TABLE $safeschema.$ctest");
@@ -1244,11 +1261,11 @@
12451262 $tss = $this->addQuotes($wgDBts2schema);
12461263 $pgp = $this->addQuotes($wgDBport);
12471264 $dbn = $this->addQuotes($this->mDBname);
1248 - $ctype = pg_fetch_result($this->doQuery("SHOW lc_ctype"),0,0);
 1265+ $ctype = $this->addQuotes( pg_fetch_result($this->doQuery("SHOW lc_ctype"),0,0) );
12491266
12501267 $SQL = "UPDATE mediawiki_version SET mw_version=$mwv, pg_version=$pgv, pg_user=$pgu, ".
12511268 "mw_schema = $mws, ts2_schema = $tss, pg_port=$pgp, pg_dbname=$dbn, ".
1252 - "ctype = '$ctype' ".
 1269+ "ctype = $ctype ".
12531270 "WHERE type = 'Creation'";
12541271 $this->query($SQL);
12551272
Index: trunk/phase3/config/index.php
@@ -2013,7 +2013,7 @@
20142014 fclose( $fp );
20152015 }
20162016 if ( !$errstr ) {
2017 - echo "<li>Connected to memcached on $host:$port successfully";
 2017+ echo "<li>Connected to memcached on " . htmlspecialchars( "$host:$port" ) ." successfully</li>";
20182018 }
20192019 return $errstr;
20202020 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r46891Backported r46840, r46843, r46889tstarling04:54, 6 February 2009
r46892Backported r46840, r46843, r46889 (installer XSS fixes)tstarling05:05, 6 February 2009
r46898Backported r46840, r46843, r46889 (installer XSS fixes)tstarling05:47, 6 February 2009
r46899Backported r46840, r46843, r46889 (installer XSS fixes)tstarling06:29, 6 February 2009

Status & tagging log