Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| PanelFraming | |
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| process | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Cosray\Middleware; |
| 6 | |
| 7 | use Override; |
| 8 | use Psr\Http\Message\ResponseInterface as Response; |
| 9 | use Psr\Http\Message\ServerRequestInterface as Request; |
| 10 | use Psr\Http\Server\MiddlewareInterface as Middleware; |
| 11 | use Psr\Http\Server\RequestHandlerInterface as Handler; |
| 12 | |
| 13 | /** |
| 14 | * Only the panel itself and the origins in `panel.embed` may frame panel |
| 15 | * pages. Every panel response says so, because an embedded editor frames |
| 16 | * further panel pages and the policy applies to each of their ancestors. |
| 17 | */ |
| 18 | final class PanelFraming implements Middleware |
| 19 | { |
| 20 | /** @param list<string> $origins */ |
| 21 | public function __construct( |
| 22 | private readonly array $origins, |
| 23 | ) {} |
| 24 | |
| 25 | #[Override] |
| 26 | public function process(Request $request, Handler $handler): Response |
| 27 | { |
| 28 | return $handler |
| 29 | ->handle($request) |
| 30 | ->withHeader('Content-Security-Policy', 'frame-ancestors ' . implode(' ', ["'self'", ...$this->origins])); |
| 31 | } |
| 32 | } |