Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow reading params of PUT with empty body more than once #37394

Merged
merged 1 commit into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelog/unreleased/37394
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Bugfix: Allow unlimited access to PUT body if content length is 0

It was not possible to read more than one URL param of the PUT request with the empty body.
This change checks Content-Length and do not throw the exception on empty request body if
Content-Length states that the empty body had been sent.

https://github.com/owncloud/core/pull/37394
2 changes: 2 additions & 0 deletions lib/private/AppFramework/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,8 @@ public function getCookie($key) {
protected function getContent() {
// If the content can't be parsed into an array then return a stream resource.
if ($this->method === 'PUT'
&& $this->getHeader('Content-Length') !== 0
&& $this->getHeader('Content-Length') !== null
&& \strpos($this->getHeader('Content-Type'), 'application/x-www-form-urlencoded') === false
&& \strpos($this->getHeader('Content-Type'), 'application/json') === false
) {
Expand Down
36 changes: 35 additions & 1 deletion tests/lib/AppFramework/Http/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,10 @@ public function testPutStream() {
$vars = [
'put' => $data,
'method' => 'PUT',
'server' => ['CONTENT_TYPE' => 'image/png'],
'server' => [
'CONTENT_TYPE' => 'image/png',
'CONTENT_LENGTH' => \strlen($data),
],
];

$request = new Request(
Expand All @@ -332,6 +335,37 @@ public function testPutStream() {
$this->fail('Expected LogicException.');
}

public function testDoubleGetParamOnPut() {
$vars = [
'method' => 'PUT',
'server' => [],
];

$request = new Request(
$vars,
$this->secureRandom,
$this->config,
$this->csrfTokenManager,
$this->stream
);

// trigger decoding of the request
$request->getParam('foo');

$request->setUrlParameters([
'var1' => 'value1',
'var2' => 'value2'
]);

// it should be possible to get unlimited number of URL parameters
// without reading the request body
$var1 = $request->getParam('var1');
$var2 = $request->getParam('var2');

$this->assertEquals('value1', $var1);
$this->assertEquals('value2', $var2);
}

public function testSetUrlParameters() {
$vars = [
'post' => [],
Expand Down