diff options
author | Umherirrender <umherirrender_de.wp@web.de> | 2024-09-27 22:00:28 +0200 |
---|---|---|
committer | Umherirrender <umherirrender_de.wp@web.de> | 2024-10-17 18:22:41 +0000 |
commit | be1c33e05ea3e01efe4ac0cd79c67dda3b89183e (patch) | |
tree | 14bf9a69a01afde78693783c8e80ee91d802f8b8 /includes/api/ApiMain.php | |
parent | 73bb50edb4ee7734471b010178679ec1bbb32ee9 (diff) | |
download | mediawikicore-be1c33e05ea3e01efe4ac0cd79c67dda3b89183e.tar.gz mediawikicore-be1c33e05ea3e01efe4ac0cd79c67dda3b89183e.zip |
api: Check for post_max_size on api requests
php documentation:
If the size of post data is greater than post_max_size, the $_POST and
$_FILES superglobals are empty.
When the action= and format= are not in the GET data,
the help page is returned in html, breaking the clients expected format.
Return api error with http status 413
Bug: T291754
Change-Id: I5906fb6b4412b161b198df0b51e2476e7e1079b8
Diffstat (limited to 'includes/api/ApiMain.php')
-rw-r--r-- | includes/api/ApiMain.php | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index 7ea691074831..58810a91b89e 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -1907,10 +1907,20 @@ class ApiMain extends ApiBase { $this->dieWithErrorOrDebug( [ 'apierror-mustbeposted', $this->mAction ] ); } - if ( $request->wasPosted() && !$request->getHeader( 'Content-Type' ) ) { - $this->addDeprecation( - 'apiwarn-deprecation-post-without-content-type', 'post-without-content-type' - ); + if ( $request->wasPosted() ) { + if ( !$request->getHeader( 'Content-Type' ) ) { + $this->addDeprecation( + 'apiwarn-deprecation-post-without-content-type', 'post-without-content-type' + ); + } + $contentLength = $request->getHeader( 'Content-Length' ); + $maxPostSize = wfShorthandToInteger( ini_get( 'post_max_size' ), 0 ); + if ( $maxPostSize && $contentLength > $maxPostSize ) { + $this->dieWithError( + [ 'apierror-http-contenttoolarge', Message::sizeParam( $maxPostSize ) ], + null, null, 413 + ); + } } // See if custom printer is used |