Whitelist PDF context options (#5924)

This commit is contained in:
Kevin Papst
2026-04-26 09:28:28 +02:00
committed by GitHub
parent 3b051e4aa5
commit 7a559a09e6
6 changed files with 126 additions and 16 deletions

View File

@@ -15,10 +15,27 @@ namespace App\Pdf;
*/
final class PdfContext
{
/**
* Keys that may be set from inside a (sandboxed) Twig template.
*
* Sinks that read the local filesystem inside mPDF (e.g. `associated_files`
* with a `path` entry, or `additional_xmp_rdf`) must NOT appear here. Those
* remain reachable via InvoiceModel::setOption() from PHP code.
*/
private const ALLOWED_KEYS = [
'filename', 'mode', 'format', 'orientation', 'default_font', 'default_font_size', 'fonts',
'margin_left', 'margin_right', 'margin_top', 'margin_bottom', 'margin_header', 'margin_footer',
'setAutoTopMargin', 'setAutoBottomMargin', 'PDFA', 'PDFAauto', 'useActiveForms',
];
private array $options = [];
public function setOption(string $key, string|int|array|null|bool $value): void
{
if (!\in_array($key, self::ALLOWED_KEYS, true)) {
return;
}
$this->options[$key] = $value;
}