Skip to content

Commit

Permalink
Move to stricter CSP
Browse files Browse the repository at this point in the history
Do not allow unsafe eval by default.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
  • Loading branch information
rullzer committed Sep 3, 2018
1 parent 41d213c commit efcec80
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\EmptyContentSecurityPolicy;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\StrictEvalContentSecurityPolicy;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Middleware;
use OCP\AppFramework\Http\Response;
Expand Down Expand Up @@ -202,7 +203,7 @@ public function beforeController($controller, $methodName) {
* @return Response
*/
public function afterController($controller, $methodName, Response $response): Response {
$policy = !is_null($response->getContentSecurityPolicy()) ? $response->getContentSecurityPolicy() : new ContentSecurityPolicy();
$policy = !is_null($response->getContentSecurityPolicy()) ? $response->getContentSecurityPolicy() : new StrictEvalContentSecurityPolicy();

if (get_class($policy) === EmptyContentSecurityPolicy::class) {
return $response;
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Security/CSP/ContentSecurityPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*
* @package OC\Security\CSP
*/
class ContentSecurityPolicy extends \OCP\AppFramework\Http\ContentSecurityPolicy {
class ContentSecurityPolicy extends \OCP\AppFramework\Http\StrictEvalContentSecurityPolicy {
/**
* @return boolean
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/public/AppFramework/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public function getHeaders() {

// Build Content-Security-Policy and use default if none has been specified
if(is_null($this->contentSecurityPolicy)) {
$this->setContentSecurityPolicy(new ContentSecurityPolicy());
$this->setContentSecurityPolicy(new StrictEvalContentSecurityPolicy());
}
$this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy();

Expand Down

0 comments on commit efcec80

Please sign in to comment.