Commit graph

275 commits

Author SHA1 Message Date
Kunal Mehta
316641798f UploadBase: Avoid deprecated wfMemcKey()
Change-Id: I717948d6550ed2d98c3a89b3e48e161c3af15d48
2017-05-25 11:20:24 -07:00
addshore
65538b0ccd UploadBase::getTitle can return null
Change-Id: I5bd94f6233476bda43a01155f6e7d6df420412e2
2017-04-18 20:42:54 +01:00
Brian Wolff
bc31c5bd57 SECURITY: Whitelist DTD declaration in SVG
Only allow ENTITY declarations inside the doctype internal
subset. Do not allow parameter entities, recursive entity
references are entity values longer than 255 bytes, or
external entity references. Filter external doctype subset
to only allow the standard svg doctypes.

Recursive entities that are simple aliases are allowed
because people appear to use them on commons. Declaring
xmlns:xlink to have a #FIXED value to the xlink namespace
is allowed because GraphViz apparently does that so its
somewhat common.

This prevents someone bypassing filter by using default
attribute values in internal dtd subset. No browser loads
the external dtd subset that I could find, but whitelist
just to be safe anyways.

Issue reported by Cassiogomes11.

Bug: T151735
Change-Id: I7cb4690f759ad97e70e06e560978b6207d84c446
2017-04-06 13:43:04 -07:00
addshore
d2bf8056b7 Use getMainObjectStash from MediawikiServices in static UploadBase methods
Change-Id: Ic547efe231c1457b2028301b9db055d3d4e6abfe
2017-03-04 11:49:05 +00:00
jenkins-bot
766d795f27 Merge "Add missing access modifiers in UploadBase" 2017-02-28 18:34:13 +00:00
James D. Forrester
9635dda73a includes: Replace implicit Bugzilla bug numbers with Phab ones
It's unreasonable to expect newbies to know that "bug 12345" means "Task T14345"
except where it doesn't, so let's just standardise on the real numbers.

Change-Id: I6f59febaf8fc96e80f8cfc11f4356283f461142a
2017-02-21 18:13:24 +00:00
addshore
c1968a584d Add missing access modifiers in UploadBase
Change-Id: Ia7a755ec3871f786b440005003f05ed91c14ce5b
2017-02-21 16:49:05 +00:00
Bartosz Dziewoński
3313b348cc UploadBase: Allow RDF Schema namespace in SVG files
Bug: T153285
Change-Id: I88938644e7e35ce9372ec33be687c7a899970534
2017-01-19 16:14:40 +01:00
rlot
0d742832f4 upload: Avoid &$this in hooks
&$this triggers warnings in PHP 7.1. Simply renaming the variable before
passing it by reference avoids the warning, without breaking backwards
compatibility.

Bug: T153505
Change-Id: I78ea04a01ecce82294837e92c2a05b00ffb6e0f6
2016-12-20 15:24:58 -08:00
Mark Holmquist
a3d562ccd1 Allow empty href in SVGs
bawolff is right, this shouldn't harm anything.

Bug: T149549
Change-Id: I377efdee7478940154ef5ec921bd0c8f7ec0c110
2016-10-31 08:29:38 -05:00
Bartosz Dziewoński
19d692051f UploadBase: Permit SVG files with broken namespace definition (Inkscape bug)
Inkscape mangles namespace definitions created by Adobe Illustrator
(apparently it can't parse custom entities or something, maybe just
in 'xmlns' attributes). These files are still valid SVG, and not
a security issue (although Illustrator probably won't like them),
so it's okay to allow them.

Added tests with some example files.

* buggynamespace-original.svg
  File generated by Illustrator (edited by hand to reduce filesize).
  Based on <https://commons.wikimedia.org/w/?curid=16495597>.

* buggynamespace-okay.svg
  The original file, opened and saved in Inkscape (no other changes).

* buggynamespace-okay2.svg
  The original file, opened and saved in Inkscape twice.

* buggynamespace-bad.svg
  The original file, edited by hand to remove custom entities.
  This is not valid XML and should be rejected (although it's valid
  when parsed as HTML, and some image viewers might display it).

* buggynamespace-evilhtml.svg
  An SVG file using an entity declared namespace for a namespace
  we want to ban. Based on buggynamespace-original.svg.

Bug: T144827
Change-Id: I0eb9766cab86a58d729f10033c64f57d2076d917
2016-10-27 10:24:32 +00:00
Aaron Schulz
ff5abb66b4 Migrate callers to new MWFileProps::getPropsFromPath() method
* FSFile should not be responsible for handling this much logic.
* Make more MediaHandler classes aware of the fact that an object
  other than File might be passed in. Use the FSFile instead of a
  useless empty stdClass object.
* Also added more fields to FSFile::placeholderProps to make it
  more complete.

Change-Id: I9fe764b2a7261af507c6555e6a57273cf7d00d36
2016-09-22 00:33:46 +00:00
Matthias Mullie
4e50971b32 Add API warnings when upload is same as older versions
Bug: T141822
Change-Id: I115d84d865c59200dbb60bd962c093185c9afafe
2016-09-06 18:43:00 +00:00
Amir Sarabadani
6b221fa96a Clean up array() syntax in docs, part IV
Change-Id: If626409a93d31bf90c054c9bf7ba44a78ea9a621
2016-08-26 16:06:58 +04:30
Bartosz Dziewoński
ec41a9c559 UploadBase: Stop mLocalFile doubling as stashed file
"I've a great idea", they said. "You know what would be cool? If I
made this boring getter, getLocalFile(), return something completely
different after the file was stashed. This will be a nice surprise for
someone in the future to discover", they added gleefully.

I am pretty sure everything still works, but I never could get async
upload publishing to work locally, so I'd appreciate some testing.

Change-Id: I11dcf2ed89e4f1dd8ddf081af521da005efdbf39
2016-08-19 03:00:30 +02:00
Bartosz Dziewoński
c9b5b3e988 Run 'UploadStashFile' hook for chunked uploads too
In UploadFromChunks, doStashFile() only stashes the current chunk,
and stashing the whole file after all chunks are uploaded is done
in concatenateChunks().

Also more custom code on top of custom code to handle ApiMessage
errors, because action=upload is special.

Follow-up to 2ee27d9a4d.

Change-Id: I968280353f15bbca9b1059631fa2cfd7c3cd2f1d
2016-08-17 17:53:08 +02:00
Bartosz Dziewoński
09f2cba006 Do not call the 'UploadStashFile' hook for partially uploaded files
Consumers of this hook don't expect partial files, and even if they did,
they have no way to tell if they've been given a partial file.

Also document a pre-existing restriction that verifyUpload() must be
called first (for non-partial files). ApiUpload previously called this
function for partial files too, causing T143161.

Follow-up to 2ee27d9a4d.

Bug: T143161
Change-Id: I107cb957e046545ea72834d72233cc1ed2867e42
2016-08-17 01:34:52 +02:00
Gilles Dubuc
7e0d148f57 Move thumbnail rendering to a more appropriate spot
At the moment the job might start before the transaction
that creates the file's row in the DB has had a chance
to run.

Bug: T106740
Change-Id: If5b94e83d8bbcc6aebfe7193f7b580f03cbd627d
2016-08-16 14:19:20 +02:00
Bartosz Dziewoński
2ee27d9a4d Introduce UploadStashFile hook, improve API handling of stash errors
UploadBase:
* Introduce a new method, tryStashFile(), as a replacement for the
  now-soft-deprecated stashFile(). The method runs the new hook and
  returns a Status object, with an error (if the hook returned an
  error) or a value (if it didn't).
* Introduce a new hook, UploadStashFile, allowing extensions to
  prevent a file from being stashed. Note that code in extensions
  which has not been updated for MediaWiki 1.28 may still call
  stashFile() directly, and therefore not call this hook. For
  important checks (not just for UI), extension authors should use
  UploadVerifyFile or UploadVerifyUpload hooks.
* Extract common code of tryStashFile() and stashFile() to
  a new protected method doStashFile().

SpecialUpload:
* Use tryStashFile() when stashing a file after a warning or
  "recoverable error" was encountered.

ApiUpload:
* Refactor stashing code so that error handling only happens in one
  place, not four different ones. Use Status objects rather than
  exception throwing/catching for control flow.
* Simplify the error messages slightly (error codes are unchanged).
  Produce better ones by always using handleStashException().
  'stashfailed' is now always at root (not nested inside 'warnings'),
  behaving the same as 'filekey' does on success.
* Use tryStashFile() when stashing. Handle errors so as to allow
  custom API results passed via ApiMessage to be preserved.

Some API result changes for different requests are shown below.

  api.php?action=upload&format=json&filename=good.png&file=...&stash=1

    Before:
      {
        "error": {
          "code": "stashfilestorage",
          "info": "Could not store upload in the stash: Stashing temporary file failed: UploadStashFileException Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\".",
          "*": "See http://localhost:3080/w/api.php for API usage"
        }
      }

    After:
      {
        "error": {
          "code": "stashfilestorage",
          "info": "Could not store upload in the stash: Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\".",
          "*": "See http://localhost:3080/w/api.php for API usage"
        }
      }

  api.php?action=upload&format=json&filename=[bad].png&file=...

    Before:
      {
        "upload": {
          "result": "Warning",
          "warnings": {
            "badfilename": "-bad-.png",
            "stashfailed": "Stashing temporary file failed: UploadStashFileException Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\"."
          }
        }
      }

    After:
      {
        "upload": {
          "result": "Warning",
          "stashfailed": "Could not store upload in the stash: Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\"."
          "warnings": {
            "badfilename": "-bad-.png",
          }
        }
      }

Bug: T140521
Change-Id: I2f574b355cd33b2e9fa7ff8e1793503b257cce65
2016-08-09 18:10:18 +02:00
Aaron Schulz
9fb541b5cc Mention UploadBase::stashFile() "checked" exceptions in docs
Change-Id: I732db6526511711e7c21cf81ddd088e50ab601ec
2016-08-05 16:28:18 -07:00
Bartosz Dziewoński
521742a9ff UploadBase: Formally deprecate old methods for stashing files
Change-Id: I4c60083a4e773e401aae8c90b99a051cbca4c961
2016-08-03 01:59:36 +02:00
Brian Wolff
4fd1f42d0b Allow SVGs encoded as WINDOWS-125[0-8].
The check is meant to prevent weird encodings like UTF-7 or HZ.
Encodings like the WINDOWS-125X family which are extensions of ascii
are safe. Additionally people still use windows-1252 on rare occasion.

Bug: T72937
Change-Id: I6cd63274cc04a7fca3afd244b4122ea64042dced
2016-08-01 11:34:05 +00:00
jenkins-bot
b3307c8a5a Merge "ApiUpload: Better handle ApiMessage errors from UploadVerifyFile hook" 2016-07-11 19:34:49 +00:00
jenkins-bot
96d9fb9731 Merge "Introduce new hook UploadVerifyUpload to allow preventing file uploads" 2016-07-07 02:27:44 +00:00
Bartosz Dziewoński
7ba4e28655 Deprecate the 'UploadVerification' hook
It has been replaced by 'UploadVerifyFile' a long time ago,
but never officially deprecated.

Change-Id: I345dca48c28ee5e1e2ad35bb6f42bbc03a1f4dd1
2016-06-28 21:52:31 +02:00
Brian Wolff
c631aa894b Fix misleading comment about svg filtering.
Follow-up 551d79a3e6. See also Bug T122653.

Change-Id: I0662dc6618596bb3a3bad345de45b054b6f7f968
2016-06-27 05:47:21 -04:00
Bartosz Dziewoński
931796f88b ApiUpload: Better handle ApiMessage errors from UploadVerifyFile hook
The extra data is actually understood and output now.

Bug: T137961
Change-Id: Ifac8995a4d16d11840cee814177fc2808bc2072c
2016-06-23 04:39:02 +00:00
Bartosz Dziewoński
8f2acfcde4 Introduce new hook UploadVerifyUpload to allow preventing file uploads
The new hook runs at the beginning of UploadBase::performUpload().
Unlike the existing UploadVerifyFile hook, the new one provides the
information about the file description page being created, and the
user who is performing the upload. It also does not run for uploads
to stash.

The action=upload API and Special:Upload have been changed to treat
errors from UploadBase::performUpload() as recoverable, which means
that they will attempt to stash the file (previously they would require
the user to upload it again). This is mostly intended for errors from
the new hook, but I think it makes sense for the existing ones, which
are mostly transient filesystem erorrs.

Bug: T89302
Change-Id: Ie68801b307de8456e1753ba54a29c34c8063bc36
2016-06-22 23:38:50 +02:00
csteipp
fdc70074bb SECURITY: Don't use m modifier when checking link prefix
SVG filter incorrectly used the m modifier when checking if an href
attribute started with 'https?://', incorrectly matching attributes
such as, "javascript:alert('&#10;http://foo')".

Bug: T122653
Change-Id: I41291fff344241cad3171f3e8050de99b62a2296

Signed-off-by: Chad Horohoe <chadh@wikimedia.org>
2016-05-20 09:47:45 -07:00
jenkins-bot
4de8aca50b Merge "UploadBase: Remove debug logging for T64241" 2016-04-01 09:39:34 +00:00
Bartosz Dziewoński
ed6ddf7410 UploadBase: Replace 'emptyfile' warning code by 'empty-file'
'empty-file' is already used elsewhere.

Bug: T130484
Change-Id: I593a9efeb20e301b289b47ff5cb831f334250a2d
2016-03-31 13:46:26 +00:00
Bartosz Dziewoński
25175703cb UploadBase: Remove debug logging for T64241
Added in 0fb104497c, no longer needed
after the bug was resolved.

Change-Id: I2771a4057f8109701f2da830d8a17c23d03f2fa2
2016-03-28 23:19:29 +02:00
Bartosz Dziewoński
93d65f2968 UploadBase: Set mFileSize, if given, even if mTempPath is unknown
When uploading a file from stash using the action=upload API, with
async=1, UploadFromStash is initialized without initializing a temp
file. dcb5ec5cbf accidentally made it so
that the given file size is ignored if there's no path. This caused
validity checks to fail (because mFileSize is null) and action=upload
to also fail with cryptic 'emptyfile' warning.

This made it impossible to upload files bigger than 10 MB using
UploadWizard, as it uses the async mode for them.

Bug: T130238
Change-Id: Ie35a66a565a370fe9adc66d5fee0866c4d51470e
2016-03-20 08:24:29 +01:00
jenkins-bot
a25d6fbc28 Merge "Make UploadBase use TempFSFile to wrap the temporary file" 2016-03-10 20:04:54 +00:00
addshore
fee0afdc8a Move WatchedItem logic to WatchedItemStore
This also removes assumptions that when a page
in one Namespace should be watched / removed
that the page in the talk / subject ns for the
page should have the same action applied

This should maintain all backward compatability
for the WatchedItem class

This also includes tests written by:
 - WMDE-leszek
 - Addshore

Bug: T127956
Change-Id: Iad9abafe4417bb479151a3bfbee6e1c78a3afe3c
2016-03-08 15:41:22 +00:00
Aaron Schulz
dcb5ec5cbf Make UploadBase use TempFSFile to wrap the temporary file
* The cleanupTempFile() method now only marks it as ready
  for unlinking when unreferenced.
* Pass TempFSFile down the FileRepo call chain so that it
  can build off a5d903860a and allow more fast async writes
  for secondary backends. Previously, the 'store' operation
  used on upload forced sync file change replication writes.
* Also fix bogus method call in LocalFile::publishTo().

Bug: T91869
Change-Id: I06caa6e5d8bdec9a7cae2b68cb02dd2e64b9ac74
2016-03-07 20:54:06 +00:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
Bartosz Dziewoński
b40bfd30c5 Document how LocalFile::upload() and UploadBase::performUpload() ignore user permissions
Follow-up to 61c7852049.

Change-Id: I6e69b1fa12f336dc4dd12e845cb8bf42abd599b2
2016-01-26 18:03:56 +01:00
Bartosz Dziewoński
61c7852049 Make it possible to tag new file uploads without messy queries
UploadBase::performUpload() now takes a $tags parameter and passes it
to LocalFile::upload() and LocalFile::recordUpload2(), which
eventually adds the requested tags to the log_id, rev_id and rc_id
that are created for the file upload.

Previously you'd have to query the database for the latest rev_id and
log_id for the page title under which the title is being uploaded, as
performUpload() is unable to return them to you because it's all
deferred in funny ways.

Bug: T121874
Change-Id: I99a8fd67c84219d2715d3d88cc21500614431179
2016-01-25 20:06:53 +01:00
Bartosz Dziewoński
ed6648427a Work around broken HHVM ini_get() for 'upload_max_filesize' and 'post_max_size'
In HHVM, the settings 'upload_max_filesize' and 'post_max_size' are
not available via ini_get() due to some long-standing bug
(https://github.com/facebook/hhvm/issues/4993). Instead, one can use
'hhvm.server.upload.upload_max_file_size' and 'hhvm.server.max_post_size'
(in a typical PHP fashion, their names are subtly different than the
originals as to increase the potential for confusion).

Added a new method UploadBase::getMaxPhpUploadSize() to handle this.

Additionally:
* 'post_max_size' can be set to 0, which is equivalent to no limit.
  Handle this correctly.
* $wgMaxUploadSize can be an array structure, instead of just a number.
  Handle this correctly by using UploadBase::getMaxUploadSize().
* When no maximum is set, use PHP_INT_MAX rather than 1e100. It should
  be big enough, and the latter is a float, results in 0 when cast to
  int, and doesn't look as pretty when formatted in GB in the interface.

Bug: T116347
Change-Id: Idf707253eeae1b90792a7e26d2ab66d1317e67ae
2015-11-08 19:48:23 +00:00
Timo Tijhof
e8275758fe objectcache: Introduce IExpiringStore for convenient TTL constants
Also consistently use self:: instead of BagOStuff:: for constants
referenced within the BagOStuff class.

Change-Id: I20fde9fa5cddcc9e92fa6a02b05dc7effa846742
2015-10-28 04:07:25 +00:00
csteipp
c804391572 SECURITY: Throttle uploads
Add throttle check in ApiUpload and SpecialUpload.

Bug: T91850
Change-Id: If33cc99f304aab2486507c7500b4abb06b6b5d70
2015-10-16 11:23:18 -07:00
umherirrender
977c810302 Remove empty line comments
Remove empty line comments as found by the
MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.EmptyComment sniff

Change-Id: I5d694f7a7d3bc97e16300ba03c60ad17f3c912a5
2015-10-14 09:46:44 +02:00
Bartosz Dziewoński
f90c0659a9 UploadBase: Return 'was-deleted' warning in addition to 'exists-normalized', not instead of
The 'was-deleted' warning was generated by getExistsWarning(), which
was returning immediately if this was found to be the case. A bunch of
later checks were incorrectly skipped, in particular 'exists-normalized',
which was resulting in UploadWizard incorrectly ignoring that problem.

I'm not sure why that was part of getExistsWarning() at all, it
doesn't seem very relevant. For that matter, neither do the 'thumb',
'thumb-name' and 'bad-prefix' warnings that it also generates, but
this should not be a problem in practice and so I'm leaving them alone.

Other than by allowing some more warning types to appear together or
in different order, this should not affect action=upload API output or
Special:Upload (which was updated appropriately). It does affect
'action=query&prop=imageinfo' output's 'html' property (used for AJAX
checks on Special:Upload), which no longer includes the 'was-deleted'
warning; this was never specified anywhere and just a side-effect.

Bug: T48741
Change-Id: I3686ee8ffd635f5f06f51971b6f16e3e66f33a9e
2015-10-12 14:22:11 +02:00
Amir E. Aharoni
c37d6549fd Fix Generic.Files.LineLength phpcs failure in 11 files under includes/
Bug: T102614
Change-Id: I0d759be6ef568c2c6f28606d3002484ad77a1830
2015-10-03 17:08:26 +00:00
Prateek Saxena
183d45c988 UploadBase: Remove UPLOAD_VERIFICATION_ERROR
It was replaced by HOOK_ABORTED five years ago and isn't being used
anywhere now.

Change-Id: I20feb33c108ae56f25a0cd01da1a326b290106c2
2015-10-01 20:09:28 +05:30
Vivek Ghaisas
c54766586a Fix issues identified by SpaceBeforeSingleLineComment sniff
Change-Id: I048ccb1fa260e4b7152ca5f09b053defdd72d8f9
2015-09-26 23:06:52 +00:00
Aaron Schulz
592a6e7d2e Avoid master queries on image history view
* The path that needs READ_LATEST already calls load() as needed first

Bug: T92357
Change-Id: Ia06bba6c2853823add2e527bb1b013b64d3f020a
2015-09-16 10:41:12 -07:00
Alex Monk
d4a0af097e Avoid passing anything but a string to Title::newFromText in UploadBase::getTitle
Bug: T109974
Change-Id: I54d42bcdcb95cb5b6a09c1c3bdea8891a14a7fdb
2015-08-23 19:27:40 +01:00
Aaron Schulz
3e7d509699 Switched upload chunk status store to the main object stash
Bug: T88493
Change-Id: I91993943ebc39846b78956e71c83358868198c2a
2015-06-30 11:04:33 -07:00