diff --git a/src/infrastructure/PhabricatorRequestOverseer.php b/src/infrastructure/PhabricatorRequestOverseer.php index dfa099a8c3..6ae4b8bdbc 100644 --- a/src/infrastructure/PhabricatorRequestOverseer.php +++ b/src/infrastructure/PhabricatorRequestOverseer.php @@ -31,11 +31,10 @@ final class PhabricatorRequestOverseer { * the request anyway, and provides no formal way to detect that this * happened. * - * We can still read the entire body out of `php://input`. However, this - * stream can't be rewound, and according to the documentation isn't available - * for "multipart/form-data" (on nginx + php-fpm it appears that it is - * available, though, at least) so any attempt to generate $_POST would create - * side effects and be fragile. + * We can still read the entire body out of `php://input`. However according + * to the documentation the stream isn't available for "multipart/form-data" + * (on nginx + php-fpm it appears that it is available, though, at least) so + * any attempt to generate $_POST would be fragile. */ private function detectPostMaxSizeTriggered() { // If this wasn't a POST, we're fine. @@ -48,6 +47,16 @@ final class PhabricatorRequestOverseer { return; } + // For HTML5 drag-and-drop file uploads, Safari submits the data as + // "application/x-www-form-urlencoded". For most files this generates + // something in POST because most files decode to some nonempty (albeit + // meaningless) value. However, some files (particularly small images) + // don't decode to anything. If we know this is a drag-and-drop upload, + // we can skip this check. + if (isset($_REQUEST['__upload__'])) { + return; + } + // PHP generates $_POST only for two content types. This routing happens // in `main/php_content_types.c` in PHP. Normally, all forms use one of // these content types, but some requests may not -- for example, Firefox diff --git a/webroot/rsrc/js/application/core/DragAndDropFileUpload.js b/webroot/rsrc/js/application/core/DragAndDropFileUpload.js index 00c3c05ed9..d77e7c2986 100644 --- a/webroot/rsrc/js/application/core/DragAndDropFileUpload.js +++ b/webroot/rsrc/js/application/core/DragAndDropFileUpload.js @@ -107,6 +107,7 @@ JX.install('PhabricatorDragAndDropFileUpload', { var up_uri = JX.$U(this.getURI()) .setQueryParam('name', file.getName()) + .setQueryParam('__upload__', 1) .toString(); var onupload = JX.bind(this, function(r) { diff --git a/webroot/rsrc/js/application/core/PasteFileUpload.js b/webroot/rsrc/js/application/core/PasteFileUpload.js index 2869087665..d3e7c79703 100644 --- a/webroot/rsrc/js/application/core/PasteFileUpload.js +++ b/webroot/rsrc/js/application/core/PasteFileUpload.js @@ -45,6 +45,7 @@ JX.install('PhabricatorPasteFileUpload', { var up_uri = JX.$U(this.getURI()) .setQueryParam('name', 'clipboard.png') + .setQueryParam('__upload__', 1) .toString(); new JX.Request(up_uri, JX.bind(this, function(r) {