Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ public function __construct(string $appName, array $urlParams = [], ?ServerConta
new OC\AppFramework\Middleware\Security\CSPMiddleware(
$server->query(OC\Security\CSP\ContentSecurityPolicyManager::class),
$server->query(OC\Security\CSP\ContentSecurityPolicyNonceManager::class),
$server->query(OC\Security\CSRF\CsrfTokenManager::class)
)
);
$dispatcher->registerMiddleware(
Expand Down
23 changes: 7 additions & 16 deletions lib/private/AppFramework/Middleware/Security/CSPMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,18 @@

use OC\Security\CSP\ContentSecurityPolicyManager;
use OC\Security\CSP\ContentSecurityPolicyNonceManager;
use OC\Security\CSRF\CsrfTokenManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\EmptyContentSecurityPolicy;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Middleware;

class CSPMiddleware extends Middleware {
/** @var ContentSecurityPolicyManager */
private $contentSecurityPolicyManager;
/** @var ContentSecurityPolicyNonceManager */
private $cspNonceManager;
/** @var CsrfTokenManager */
private $csrfTokenManager;

public function __construct(ContentSecurityPolicyManager $policyManager,
ContentSecurityPolicyNonceManager $cspNonceManager,
CsrfTokenManager $csrfTokenManager) {
$this->contentSecurityPolicyManager = $policyManager;
$this->cspNonceManager = $cspNonceManager;
$this->csrfTokenManager = $csrfTokenManager;

public function __construct(
private ContentSecurityPolicyManager $policyManager,
private ContentSecurityPolicyNonceManager $cspNonceManager,
) {
}

/**
Expand All @@ -49,8 +40,8 @@ public function afterController($controller, $methodName, Response $response): R
return $response;
}

$defaultPolicy = $this->contentSecurityPolicyManager->getDefaultPolicy();
$defaultPolicy = $this->contentSecurityPolicyManager->mergePolicies($defaultPolicy, $policy);
$defaultPolicy = $this->policyManager->getDefaultPolicy();
$defaultPolicy = $this->policyManager->mergePolicies($defaultPolicy, $policy);

if ($this->cspNonceManager->browserSupportsCspV3()) {
$defaultPolicy->useJsNonce($this->cspNonceManager->getNonce());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ public function beforeController($controller, $methodName) {

public function afterException($controller, $methodName, \Exception $exception) {
if ($exception instanceof LaxSameSiteCookieFailedException) {
$respone = new Response();
$respone->setStatus(Http::STATUS_FOUND);
$respone->addHeader('Location', $this->request->getRequestUri());
$response = new Response();
$response->setStatus(Http::STATUS_FOUND);
$response->addHeader('Location', $this->request->getRequestUri());

$this->setSameSiteCookie();

return $respone;
return $response;
}

throw $exception;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use OC\Security\CSP\ContentSecurityPolicy;
use OC\Security\CSP\ContentSecurityPolicyManager;
use OC\Security\CSP\ContentSecurityPolicyNonceManager;
use OC\Security\CSRF\CsrfTokenManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\EmptyContentSecurityPolicy;
use OCP\AppFramework\Http\Response;
Expand All @@ -25,8 +24,6 @@ class CSPMiddlewareTest extends \Test\TestCase {
private $controller;
/** @var ContentSecurityPolicyManager&MockObject */
private $contentSecurityPolicyManager;
/** @var CsrfTokenManager&MockObject */
private $csrfTokenManager;
/** @var ContentSecurityPolicyNonceManager&MockObject */
private $cspNonceManager;

Expand All @@ -35,12 +32,10 @@ protected function setUp(): void {

$this->controller = $this->createMock(Controller::class);
$this->contentSecurityPolicyManager = $this->createMock(ContentSecurityPolicyManager::class);
$this->csrfTokenManager = $this->createMock(CsrfTokenManager::class);
$this->cspNonceManager = $this->createMock(ContentSecurityPolicyNonceManager::class);
$this->middleware = new CSPMiddleware(
$this->contentSecurityPolicyManager,
$this->cspNonceManager,
$this->csrfTokenManager
);
}

Expand Down