Skip to content

Commit

Permalink
Add more Fetch Metadata Resource Isolation Policy logging (#373)
Browse files Browse the repository at this point in the history
Follow-up to #371
  • Loading branch information
spaze authored Jul 28, 2024
2 parents 7d784f1 + bb16169 commit 552fe97
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion site/app/Http/FetchMetadata/ResourceIsolationPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,17 @@ public function install(): void
$presenter->onStartup[] = function () use ($presenter): void {
if (!$this->isRequestAllowed($presenter)) {
if ($this->reportOnly) {
$message = sprintf('%s %s %s', $this->httpRequest->getMethod(), $presenter->getAction(true), implode(', ', array_keys($presenter->getParameters())));
$headers = [];
foreach ($this->fetchMetadata->getAllHeaders() as $header => $value) {
$headers[] = sprintf('%s: %s', $header, $value ?? '[not sent]');
}
$message = sprintf(
'%s %s; param names: %s; headers: %s',
$this->httpRequest->getMethod(),
$presenter->getAction(true),
implode(', ', array_keys($presenter->getParameters())),
implode(', ', $headers),
);
Debugger::log($message, 'cross-site');
} else {
$presenter->forward(':Www:Forbidden:', ['message' => 'messages.forbidden.crossSite']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ResourceIsolationPolicyTest extends TestCase
$this->installPolicy(true);
$this->httpRequest->setHeader(FetchMetadataHeader::Site->value, 'cross-site');
$this->callPresenterAction();
Assert::same(['GET :Www:Homepage:default foo, waldo'], $this->logger->getLogged());
Assert::same(['GET :Www:Homepage:default; param names: foo, waldo; headers: Sec-Fetch-Dest: [not sent], Sec-Fetch-Mode: [not sent], Sec-Fetch-Site: cross-site, Sec-Fetch-User: [not sent]'], $this->logger->getLogged());
Assert::same(IResponse::S200_OK, $this->httpResponse->getCode());
}

Expand Down

0 comments on commit 552fe97

Please sign in to comment.