r110922 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110921‎ | r110922 | r110923 >
Date:09:00, 8 February 2012
Author:aaron
Status:resolved (Comments)
Tags:filebackend 
Comment:
Added some simple path validation to resolveContainerPath() in FSFileBackend. This makes file op batches a bit more robust.
Modified paths:
  • /trunk/phase3/includes/filerepo/backend/FSFileBackend.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/filerepo/backend/FSFileBackend.php
@@ -61,13 +61,34 @@
6262 * @see FileBackendStore::resolveContainerPath()
6363 */
6464 protected function resolveContainerPath( $container, $relStoragePath ) {
 65+ // Check that container has a root directory
6566 if ( isset( $this->containerPaths[$container] ) || isset( $this->basePath ) ) {
66 - return $relStoragePath; // container has a root directory
 67+ // Check for sane relative paths (assume the base paths are OK)
 68+ if ( $this->isLegalRelPath( $relStoragePath ) ) {
 69+ return $relStoragePath;
 70+ }
6771 }
6872 return null;
6973 }
7074
7175 /**
 76+ * Sanity check a relative file system path for validity
 77+ *
 78+ * @param $path string Normalized relative path
 79+ */
 80+ protected function isLegalRelPath( $path ) {
 81+ // Check for file names longer than 255 chars
 82+ if ( preg_match( '![^/]{256}!', $path ) ) { // ext3/NTFS
 83+ return false;
 84+ }
 85+ if ( wfIsWindows() ) { // NTFS
 86+ return !preg_match( '![:*?"<>]!', $path );
 87+ } else {
 88+ return true;
 89+ }
 90+ }
 91+
 92+ /**
7293 * Given the short (unresolved) and full (resolved) name of
7394 * a container, return the file system path of the container.
7495 *

Follow-up revisions

RevisionCommit summaryAuthorDate
r110991Blacklist | in windows paths too...reedy00:24, 9 February 2012

Comments

#Comment by Reedy (talk | contribs)   00:17, 9 February 2012

You're missing | from the windows regex.

On Windows \ and / aren't valid in folder names, but it uses backslashes in paths... So shouldn't / be blacklisted also? Or will PHP use it sometimes?

#Comment by Aaron Schulz (talk | contribs)   00:20, 9 February 2012

Note that $relStoragePath already has normalized directory separators (only "/").

Status & tagging log