summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2016-06-15 11:50:26 +0200
committerLukas Reschke <lukas@owncloud.com>2016-06-15 11:50:26 +0200
commit202530f4f3e984a8fb4302f2a6863d426671e9ad (patch)
tree4cfa02aafc079ddf29925258c0ee8e66eb8a40ce /tests
parent7a5093c43e1915046d299877f35b0f2822bc516c (diff)
downloadnextcloud-server-202530f4f3e984a8fb4302f2a6863d426671e9ad.tar.gz
nextcloud-server-202530f4f3e984a8fb4302f2a6863d426671e9ad.zip
Soften the cookie check if no cookies are sent
When no cookies are sent it is not required to perform any check for the strict or lax cookie, it does not provide any significant security advantage. It does however interfer with the Android client which requests thumbnails from the unofficial API at `/index.php/apps/files/api/v1/thumbnail/256/256/{filename}`. This endpoint expects the strict cookie to be existent to not leak the existence of files. The Android client authenticates against this endpoint using Basic Auth and without cookies in some cases at least. This will make these endpoints work again with such cases. To test this issue the following cURL command once without the patch and once with: > curl http://localhost/index.php/apps/files/api/v1/thumbnail/256/256/welcome.txt -u admin -v Without the patch the request is redirected (which the client does not obey) and with the patch the preview is returned.
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/appframework/http/RequestTest.php53
1 files changed, 41 insertions, 12 deletions
diff --git a/tests/lib/appframework/http/RequestTest.php b/tests/lib/appframework/http/RequestTest.php
index 787f410e0c4..335a7e9c8e2 100644
--- a/tests/lib/appframework/http/RequestTest.php
+++ b/tests/lib/appframework/http/RequestTest.php
@@ -1404,7 +1404,7 @@ class RequestTest extends \Test\TestCase {
$this->assertTrue($request->passesCSRFCheck());
}
- public function testFailsCSRFCheckWithGetAndWithoutCookies() {
+ public function testPassesCSRFCheckWithGetAndWithoutCookies() {
/** @var Request $request */
$request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
->setMethods(['getScriptName'])
@@ -1421,13 +1421,14 @@ class RequestTest extends \Test\TestCase {
])
->getMock();
$this->csrfTokenManager
- ->expects($this->never())
- ->method('isTokenValid');
+ ->expects($this->once())
+ ->method('isTokenValid')
+ ->willReturn(true);
- $this->assertFalse($request->passesCSRFCheck());
+ $this->assertTrue($request->passesCSRFCheck());
}
- public function testFailsCSRFCheckWithPostAndWithoutCookies() {
+ public function testPassesCSRFCheckWithPostAndWithoutCookies() {
/** @var Request $request */
$request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
->setMethods(['getScriptName'])
@@ -1444,13 +1445,14 @@ class RequestTest extends \Test\TestCase {
])
->getMock();
$this->csrfTokenManager
- ->expects($this->never())
- ->method('isTokenValid');
+ ->expects($this->once())
+ ->method('isTokenValid')
+ ->willReturn(true);
- $this->assertFalse($request->passesCSRFCheck());
+ $this->assertTrue($request->passesCSRFCheck());
}
- public function testFailsCSRFCheckWithHeaderAndWithoutCookies() {
+ public function testPassesCSRFCheckWithHeaderAndWithoutCookies() {
/** @var Request $request */
$request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
->setMethods(['getScriptName'])
@@ -1467,10 +1469,11 @@ class RequestTest extends \Test\TestCase {
])
->getMock();
$this->csrfTokenManager
- ->expects($this->never())
- ->method('isTokenValid');
+ ->expects($this->once())
+ ->method('isTokenValid')
+ ->willReturn(true);
- $this->assertFalse($request->passesCSRFCheck());
+ $this->assertTrue($request->passesCSRFCheck());
}
public function testFailsCSRFCheckWithHeaderAndNotAllChecksPassing() {
@@ -1523,6 +1526,32 @@ class RequestTest extends \Test\TestCase {
$this->assertTrue($request->passesStrictCookieCheck());
}
+ public function testFailsSRFCheckWithPostAndWithCookies() {
+ /** @var Request $request */
+ $request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
+ ->setMethods(['getScriptName'])
+ ->setConstructorArgs([
+ [
+ 'post' => [
+ 'requesttoken' => 'AAAHGxsTCTc3BgMQESAcNR0OAR0=:MyTotalSecretShareds',
+ ],
+ 'cookies' => [
+ 'foo' => 'bar',
+ ],
+ ],
+ $this->secureRandom,
+ $this->config,
+ $this->csrfTokenManager,
+ $this->stream
+ ])
+ ->getMock();
+ $this->csrfTokenManager
+ ->expects($this->never())
+ ->method('isTokenValid');
+
+ $this->assertFalse($request->passesCSRFCheck());
+ }
+
public function testFailStrictCookieCheckWithOnlyLaxCookie() {
/** @var Request $request */
$request = $this->getMockBuilder('\OC\AppFramework\Http\Request')