mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-06-27 13:01:33 +00:00
Set strict CSP policies when serving files from the attachment endpoints
This commit is contained in:
parent
02726fdf69
commit
0cd83f0322
1 changed files with 12 additions and 0 deletions
|
|
@ -93,6 +93,8 @@ class AttachmentFileController extends AbstractController
|
||||||
//Set header content disposition, so that the file will be downloaded
|
//Set header content disposition, so that the file will be downloaded
|
||||||
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $attachment->getFilename());
|
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $attachment->getFilename());
|
||||||
|
|
||||||
|
$this->setAttachmentCSPHeaders($response);
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -112,6 +114,16 @@ class AttachmentFileController extends AbstractController
|
||||||
//Set header content disposition, so that the file will be downloaded
|
//Set header content disposition, so that the file will be downloaded
|
||||||
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_INLINE, $attachment->getFilename());
|
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_INLINE, $attachment->getFilename());
|
||||||
|
|
||||||
|
$this->setAttachmentCSPHeaders($response);
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function setAttachmentCSPHeaders(Response $response): Response
|
||||||
|
{
|
||||||
|
//Set an CSP that disallow to run any scripts, styles or images from the attachment render page, as it is not used anywhere else for now and can be a security risk if used without proper precautions, so it should be opt-in
|
||||||
|
$response->headers->set('Content-Security-Policy', "default-src 'none'; script-src 'none'; style-src 'self' 'unsafe-inline'; img-src 'self'; sandbox;");
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue