Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
40.00% |
2 / 5 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| GlobalInjectionMiddleware | |
40.00% |
2 / 5 |
|
0.00% |
0 / 1 |
2.86 | |
0.00% |
0 / 1 |
| afterController | |
40.00% |
2 / 5 |
|
0.00% |
0 / 1 |
2.86 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | /** |
| 5 | * SPDX-FileCopyrightText: 2020-2024 LibreCode coop and contributors |
| 6 | * SPDX-License-Identifier: AGPL-3.0-or-later |
| 7 | */ |
| 8 | |
| 9 | namespace OCA\Libresign\Middleware; |
| 10 | |
| 11 | use OCA\Files\Controller\ViewController; |
| 12 | use OCP\AppFramework\Controller; |
| 13 | use OCP\AppFramework\Http\ContentSecurityPolicy; |
| 14 | use OCP\AppFramework\Http\Response; |
| 15 | use OCP\AppFramework\Middleware; |
| 16 | |
| 17 | class GlobalInjectionMiddleware extends Middleware { |
| 18 | #[\Override] |
| 19 | public function afterController(Controller $controller, string $methodName, Response $response) { |
| 20 | if ($controller instanceof ViewController) { |
| 21 | $policy = new ContentSecurityPolicy(); |
| 22 | $policy->addAllowedFrameDomain("'self'"); |
| 23 | $response->setContentSecurityPolicy($policy); |
| 24 | } |
| 25 | return $response; |
| 26 | } |
| 27 | } |