Commit graph

6 commits

Author SHA1 Message Date
Tim Starling
20d06b34bb Safer autoloading with respect to file-scope code
Many files were in the autoloader despite having potentially harmful
file-scope code.

* Exclude all CommandLineInc maintenance scripts from the autoloader.
* Introduce  "NO_AUTOLOAD" tag which excludes the file containing it
  from the autoloader. Use it on CommandLineInc.php and a few
  suspicious-looking files without classes in case they are refactored
  to add classes in the future.
* Add a test which parses all non-PSR4 class files and confirms that
  they do not contain dangerous file-scope code. It's slow (15s) but
  its results were enlightening.
* Several maintenance scripts define constants in the file scope,
  intending to modify the behaviour of MediaWiki. Either move the
  define() to a later setup function, or protect with NO_AUTOLOAD.
* Use require_once consistently with Maintenance.php and
  doMaintenance.php, per the original convention which is supposed to
  allow one maintenance script to use the class of another maintenance
  script. Using require breaks autoloading of these maintenance class
  files.
* When Maintenance.php is included, check if MediaWiki has already
  started, and if so, return early. Revert the fix for T250003 which
  is incompatible with this safety measure. Hopefully it was superseded
  by splitting out the class file.
* In runScript.php add a redundant PHP_SAPI check since it does some
  things in file-scope code before any other check will be run.
* Change the if(false) class_alias(...) to something more hackish and
  more compatible with the new test.
* Some site-related scripts found Maintenance.php in a non-standard way.
  Use the standard way.
* fileOpPerfTest.php called error_reporting(). Probably debugging code
  left in; removed.
* Moved mediawiki.compress.7z registration from the class file to the
  caller.

Change-Id: I1b1be90343a5ab678df6f1b1bdd03319dcf6537f
2021-01-11 11:59:36 +11:00
Umherirrender
e9e784a09e build: Enable phan-taint-check-plugin and suppress issues
Taint check checks for possible security issues by tracking html
escaping and more by using phan.
This slows done the phan-job a bit and requires more ram

Keep the DoubleEscaped issues out to make reviewer easier

Adds suppression for false positives
Adds taint-annotation to help taint-check
Removes suppression for code phan now understand better by the tracking
of keys in taint-check
Fix some small issues by adding int cast or htmlspecialchars calls

Bug: T216348
Bug: T268920
Change-Id: I849ac4f120fd15b483e8939d4db45c98dc351259
2020-12-30 19:02:22 +01:00
Umherirrender
11b71b2a98 Suppress taint-check issues in maintenance scripts/cli context
all places detected as SecurityCheck-XSS by
mediawiki/phan-taint-check-plugin 3.1.0

Bug: T216348
Change-Id: Ib4c8295ad95c2c605fd2f0791e73322f747a00af
2020-12-07 17:20:07 +00:00
Derick A
fd02dc6aac maintenance: Add file extension as expected for PHP scripts
The example in the block comment above uses the .php file extension
in the example but the usage string omits it and it can be misleading.

If the extension (.php) is not given, `runScript.php` will think that
the script doesn't exist and trigger a different code path rather than
actually run the script in question.

Change-Id: I4d60f65629472f2243ead2c8768f597ae23b6beb
2020-01-29 11:44:06 +01:00
MarcoAurelio
cbe7eab07c Fix typo "maintainance"
Bug: T201491
Change-Id: I8724206404a461eaace3b60f91c7704bd6581ee2
2018-12-24 15:51:11 +01:00
aude
f36f49380e Add convenience maintenance script wrapper
Useful for scripts or extensions installed in non-standard locations.

Example usage:

php maintenance/runScript.php
extensions/Wikibase/lib/maintenance/dispatchChanges.php

Change-Id: I6ffc72f41f3f96dd535a427d90c7166372459bd2
2013-11-07 21:10:07 +01:00