r111120 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111119‎ | r111120 | r111121 >
Date:23:22, 9 February 2012
Author:reedy
Status:resolved (Comments)
Tags:
Comment:
* (bug 32341) Add upload by URL domain limitation.

Essentially reverts r109741 live again

Which was r109562, r109564, r109570
Modified paths:
  • /trunk/phase3/RELEASE-NOTES-1.20 (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/api/ApiBase.php (modified) (history)
  • /trunk/phase3/includes/api/ApiUpload.php (modified) (history)
  • /trunk/phase3/includes/upload/UploadFromUrl.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -2236,6 +2236,7 @@
22372237 'upload-too-many-redirects' => 'The URL contained too many redirects',
22382238 'upload-unknown-size' => 'Unknown size',
22392239 'upload-http-error' => 'An HTTP error occured: $1',
 2240+'upload-copy-upload-invalid-domain' => 'Copy uploads are not available from this domain.',
22402241
22412242 # File backend
22422243 'backend-fail-stream' => 'Could not stream file $1.',
Index: trunk/phase3/includes/DefaultSettings.php
@@ -453,6 +453,10 @@
454454 * This feature is experimental and broken as of r81612.
455455 */
456456 $wgAllowAsyncCopyUploads = false;
 457+/**
 458+ * A list of domains copy uploads can come from
 459+ */
 460+$wgCopyUploadsDomains = array();
457461
458462 /**
459463 * Max size for uploads, in bytes. If not set to an array, applies to all
Index: trunk/phase3/includes/upload/UploadFromUrl.php
@@ -37,6 +37,28 @@
3838 }
3939
4040 /**
 41+ * Checks whether the URL is for an allowed host
 42+ *
 43+ * @param $url string
 44+ * @return bool
 45+ */
 46+ public static function isAllowedHost( $url ) {
 47+ global $wgCopyUploadsDomains;
 48+ if ( !count( $wgCopyUploadsDomains ) ) {
 49+ return true;
 50+ }
 51+ $valid = false;
 52+ $parsedUrl = wfParseUrl( $url );
 53+ foreach( $wgCopyUploadsDomains as $domain ) {
 54+ if ( $parsedUrl['host'] === $domain ) {
 55+ $valid = true;
 56+ break;
 57+ }
 58+ }
 59+ return $valid;
 60+ }
 61+
 62+ /**
4163 * Entry point for API upload
4264 *
4365 * @param $name string
@@ -101,6 +123,9 @@
102124 return Status::newFatal( 'http-invalid-url' );
103125 }
104126
 127+ if( !self::isAllowedHost( $this->mUrl ) ) {
 128+ return Status::newFatal( 'upload-copy-upload-invalid-domain' );
 129+ }
105130 if ( !$this->mAsync ) {
106131 return $this->reallyFetchFile();
107132 }
Index: trunk/phase3/includes/api/ApiUpload.php
@@ -322,6 +322,10 @@
323323 $this->dieUsageMsg( 'copyuploaddisabled' );
324324 }
325325
 326+ if ( !UploadFromUrl::isAllowedHost( $this->mParams['url'] ) ) {
 327+ $this->dieUsageMsg( 'copyuploadbaddomain' );
 328+ }
 329+
326330 $async = false;
327331 if ( $this->mParams['asyncdownload'] ) {
328332 $this->checkAsyncDownloadEnabled();
Index: trunk/phase3/includes/api/ApiBase.php
@@ -1231,6 +1231,7 @@
12321232 'nouploadmodule' => array( 'code' => 'nouploadmodule', 'info' => 'No upload module set' ),
12331233 'uploaddisabled' => array( 'code' => 'uploaddisabled', 'info' => 'Uploads are not enabled. Make sure $wgEnableUploads is set to true in LocalSettings.php and the PHP ini setting file_uploads is true' ),
12341234 'copyuploaddisabled' => array( 'code' => 'copyuploaddisabled', 'info' => 'Uploads by URL is not enabled. Make sure $wgAllowCopyUploads is set to true in LocalSettings.php.' ),
 1235+ 'copyuploadbaddomain' => array( 'code' => 'copyuploadbaddomain', 'info' => 'Uploads by URL are not allowed from this domain.' ),
12351236
12361237 'filename-tooshort' => array( 'code' => 'filename-tooshort', 'info' => 'The filename is too short' ),
12371238 'filename-toolong' => array( 'code' => 'filename-toolong', 'info' => 'The filename is too long' ),
Index: trunk/phase3/maintenance/language/messages.inc
@@ -1345,6 +1345,7 @@
13461346 'upload-too-many-redirects',
13471347 'upload-unknown-size',
13481348 'upload-http-error',
 1349+ 'upload-copy-upload-invalid-domain',
13491350 ),
13501351
13511352 'filebackend-errors' => array(
Index: trunk/phase3/RELEASE-NOTES-1.20
@@ -14,6 +14,7 @@
1515
1616 === New features in 1.20 ===
1717 * Added TitleIsKnown hook which gets called when determining if a page exists.
 18+* (bug 32341) Add upload by URL domain limitation.
1819
1920 === Bug fixes in 1.20 ===
2021 * (bug 30245) Use the correct way to construct a log page title.

Follow-up revisions

RevisionCommit summaryAuthorDate
r111239Followup r11120, wfParseUrl() can return false, if it does, the host isn't go...reedy15:13, 11 February 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r109562* (bug 32341) Add upload by URL domain limitation.reedy19:16, 19 January 2012
r109564Followup r109562...reedy20:26, 19 January 2012
r109570r109562: Register new message key for maintenance scriptraymond21:12, 19 January 2012
r109741Revert feature out of r109562, r109564, r109570...reedy17:33, 22 January 2012

Comments

#Comment by Aaron Schulz (talk | contribs)   00:39, 11 February 2012

wfParseUrl() can return false.

#Comment by Reedy (talk | contribs)   15:11, 11 February 2012

Why am I not getting emails from CR atm? :/

#Comment by Reedy (talk | contribs)   15:15, 11 February 2012

Also, omg table css change...

#Comment by IAlex (talk | contribs)   14:00, 12 February 2012

Please create a description page on this wiki for the new setting and link to it from Manual:Configuration settings. Thank you.

Status & tagging log