r43661 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r43660‎ | r43661 | r43662 >
Date:05:57, 18 November 2008
Author:tstarling
Status:ok
Tags:
Comment:
Protect users from attacks against their browsers via malicious script-containing uploads, by:
1) Requiring a session token before streaming files out via Special:Undelete
2) Restricting img_auth.php to private wikis only (its intended use case)
Modified paths:
  • /trunk/phase3/img_auth.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUndelete.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialUndelete.php
@@ -569,7 +569,7 @@
570570 */
571571 class UndeleteForm {
572572 var $mAction, $mTarget, $mTimestamp, $mRestore, $mInvert, $mTargetObj;
573 - var $mTargetTimestamp, $mAllowed, $mComment;
 573+ var $mTargetTimestamp, $mAllowed, $mComment, $mToken;
574574
575575 function UndeleteForm( $request, $par = "" ) {
576576 global $wgUser;
@@ -588,6 +588,7 @@
589589 $this->mDiff = $request->getCheck( 'diff' );
590590 $this->mComment = $request->getText( 'wpComment' );
591591 $this->mUnsuppress = $request->getVal( 'wpUnsuppress' ) && $wgUser->isAllowed( 'suppressrevision' );
 592+ $this->mToken = $request->getVal( 'token' );
592593
593594 if( $par != "" ) {
594595 $this->mTarget = $par;
@@ -654,6 +655,9 @@
655656 if( !$file->userCan( File::DELETED_FILE ) ) {
656657 $wgOut->permissionRequired( 'suppressrevision' );
657658 return false;
 659+ } elseif ( !$wgUser->matchEditToken( $this->mToken, $this->mFile ) ) {
 660+ $this->showFileConfirmationForm( $this->mFile );
 661+ return false;
658662 } else {
659663 return $this->showFile( $this->mFile );
660664 }
@@ -887,6 +891,29 @@
888892 }
889893
890894 /**
 895+ * Show a form confirming whether a tokenless user really wants to see a file
 896+ */
 897+ private function showFileConfirmationForm( $key ) {
 898+ global $wgOut, $wgUser, $wgLang;
 899+ $file = new ArchivedFile( $this->mTargetObj, '', $this->mFile );
 900+ $wgOut->addWikiMsg( 'undelete-show-file-confirm',
 901+ $this->mTargetObj->getText(),
 902+ $wgLang->timeanddate( $file->getTimestamp() ) );
 903+ $wgOut->addHTML(
 904+ Xml::openElement( 'form', array(
 905+ 'method' => 'POST',
 906+ 'action' => SpecialPage::getTitleFor( 'Undelete' )->getLocalUrl(
 907+ 'target=' . urlencode( $this->mTarget ) .
 908+ '&file=' . urlencode( $key ) .
 909+ '&token=' . urlencode( $wgUser->editToken( $key ) ) )
 910+ )
 911+ ) .
 912+ Xml::submitButton( wfMsg( 'undelete-show-file-submit' ) ) .
 913+ '</form>'
 914+ );
 915+ }
 916+
 917+ /**
891918 * Show a deleted file version requested by the visitor.
892919 */
893920 private function showFile( $key ) {
@@ -1194,13 +1221,15 @@
11951222 * @return string
11961223 */
11971224 function getFileLink( $file, $titleObj, $ts, $key, $sk ) {
1198 - global $wgLang;
 1225+ global $wgLang, $wgUser;
11991226
12001227 if( !$file->userCan(File::DELETED_FILE) ) {
12011228 return '<span class="history-deleted">' . $wgLang->timeanddate( $ts, true ) . '</span>';
12021229 } else {
12031230 $link = $sk->makeKnownLinkObj( $titleObj, $wgLang->timeanddate( $ts, true ),
1204 - "target=".$this->mTargetObj->getPrefixedUrl()."&file=$key" );
 1231+ "target=".$this->mTargetObj->getPrefixedUrl().
 1232+ "&file=$key" .
 1233+ "&token=" . urlencode( $wgUser->editToken( $key ) ) );
12051234 if( $file->isDeleted(File::DELETED_FILE) )
12061235 $link = '<span class="history-deleted">' . $link . '</span>';
12071236 return $link;
Index: trunk/phase3/img_auth.php
@@ -17,6 +17,12 @@
1818 wfProfileIn( 'img_auth.php' );
1919 require_once( dirname( __FILE__ ) . '/includes/StreamFile.php' );
2020
 21+$perms = User::getGroupPermissions( array( '*' ) );
 22+if ( in_array( 'read', $perms, true ) ) {
 23+ wfDebugLog( 'img_auth', 'Public wiki' );
 24+ wfPublicError();
 25+}
 26+
2127 // Extract path and image information
2228 if( !isset( $_SERVER['PATH_INFO'] ) ) {
2329 wfDebugLog( 'img_auth', 'Missing PATH_INFO' );
@@ -88,3 +94,25 @@
8995 wfLogProfilingData();
9096 exit();
9197 }
 98+
 99+/**
 100+ * Show a 403 error for use when the wiki is public
 101+ */
 102+function wfPublicError() {
 103+ header( 'HTTP/1.0 403 Forbidden' );
 104+ header( 'Content-Type: text/html; charset=utf-8' );
 105+ echo <<<ENDS
 106+<html>
 107+<body>
 108+<h1>Access Denied</h1>
 109+<p>The function of img_auth.php is to output files from a private wiki. This wiki
 110+is configured as a public wiki. For optimal security, img_auth.php is disabled in
 111+this case.
 112+</p>
 113+</body>
 114+</html>
 115+ENDS;
 116+ wfLogProfilingData();
 117+ exit;
 118+}
 119+
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -2491,6 +2491,8 @@
24922492 'undelete-error-long' => 'Errors were encountered while undeleting the file:
24932493
24942494 $1',
 2495+'undelete-show-file-confirm' => 'Are you sure you want to view a deleted revision of the file "<nowiki>$1</nowiki>" from $2?',
 2496+'undelete-show-file-submit' => 'Yes',
24952497
24962498 # Namespace form on various pages
24972499 'namespace' => 'Namespace:',

Follow-up revisions

RevisionCommit summaryAuthorDate
r43666Update per r43658 and r43661raymond08:11, 18 November 2008
r43669Backported r43621, r43622, r43623, r43624, r43625, r43627, r43660, r43661. Ne...tstarling11:36, 18 November 2008

Status & tagging log