summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2015-03-10 10:06:15 +0100
committerLukas Reschke <lukas@owncloud.com>2015-03-10 10:06:15 +0100
commit48243a2949932f187cb260912b0bebc11389dff5 (patch)
tree4f5a9b074d3ae7bb4c055ddfe88c8486fad4c907
parente069d9d3f913c867085d5969843c8c12786b1133 (diff)
downloadnextcloud-server-48243a2949932f187cb260912b0bebc11389dff5.tar.gz
nextcloud-server-48243a2949932f187cb260912b0bebc11389dff5.zip
Allow iframes from same domain in share view
This is required because the PDF Viewer itself is embedded using an iframe from the same domain. The default policy is blocking this. Going on further, we have to come up with a solution in the future how to handle previews by applications, one example might be that they call their own endpoint and not the generic share page to allow applications to have full control over how to display previews. Anyways, to test this behaviour use a decent newer browser (such as Chrome 41) and share a PDF file, obviously the PDF viewer needs to be enabled as well. Without this patch publicly shared PDF files should not get previewed and an error is thrown. (if it isn't then your browser is probably not obeying our Content-Security-Policy and you might consider switching to another one ;))
-rw-r--r--apps/files_sharing/lib/controllers/sharecontroller.php7
-rw-r--r--apps/files_sharing/tests/controller/sharecontroller.php5
2 files changed, 11 insertions, 1 deletions
diff --git a/apps/files_sharing/lib/controllers/sharecontroller.php b/apps/files_sharing/lib/controllers/sharecontroller.php
index 2e23ac5908e..ebc54265bf0 100644
--- a/apps/files_sharing/lib/controllers/sharecontroller.php
+++ b/apps/files_sharing/lib/controllers/sharecontroller.php
@@ -203,7 +203,12 @@ class ShareController extends Controller {
$shareTmpl['downloadURL'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.downloadShare', array('token' => $token));
$shareTmpl['maxSizeAnimateGif'] = $this->config->getSystemValue('max_filesize_animated_gifs_public_sharing', 10);
- return new TemplateResponse($this->appName, 'public', $shareTmpl, 'base');
+ $csp = new OCP\AppFramework\Http\ContentSecurityPolicy();
+ $csp->addAllowedFrameDomain('\'self\'');
+ $response = new TemplateResponse($this->appName, 'public', $shareTmpl, 'base');
+ $response->setContentSecurityPolicy($csp);
+
+ return $response;
}
/**
diff --git a/apps/files_sharing/tests/controller/sharecontroller.php b/apps/files_sharing/tests/controller/sharecontroller.php
index 173f606e188..81e60b03cdc 100644
--- a/apps/files_sharing/tests/controller/sharecontroller.php
+++ b/apps/files_sharing/tests/controller/sharecontroller.php
@@ -159,7 +159,12 @@ class ShareControllerTest extends \Test\TestCase {
'nonHumanFileSize' => 33,
'maxSizeAnimateGif' => 10,
);
+
+ $csp = new \OCP\AppFramework\Http\ContentSecurityPolicy();
+ $csp->addAllowedFrameDomain('\'self\'');
$expectedResponse = new TemplateResponse($this->container['AppName'], 'public', $sharedTmplParams, 'base');
+ $expectedResponse->setContentSecurityPolicy($csp);
+
$this->assertEquals($expectedResponse, $response);
}