fix(pdf): security hardening — hex-encoded link URIs, strict branding URL schema, branding and labels re-validated at export, PNG dimension budget, CSS escape and parenthesis rules in the sanitiser, finite raster size, file size checked before read
This commit is contained in:
1 parent
4930704d8a
commit
1f417b21fd
12 files changed
+437
-25
No files matched your search
@@ -1,9 +1,11 @@
|
||||
import { PDFDocument } from 'pdf-lib'
|
||||
import {
|
||||
assertSnapshot,
|
||||
BrandingSchema,
|
||||
buildSheetIndex,
|
||||
ENVELOPE_FORMAT,
|
||||
ENVELOPE_VERSION,
|
||||
PdfLabelSetSchema,
|
||||
snapshotIndexSource,
|
||||
SnapshotError,
|
||||
type Report,
|
||||
@@ -43,6 +45,20 @@ export const PAGE_CAPS = {
|
||||
viewsPerObservation: 8,
|
||||
} as const
|
||||
|
||||
/**
|
||||
* Step 0: the branding and the labels pass their schemas again. They reach
|
||||
* the engine from an archive or from the application and end up in link
|
||||
* URIs and drawn text, so a caller cannot be trusted to have validated them.
|
||||
*/
|
||||
function assertBrandingAndLabels(input: ExportInput): void {
|
||||
if (!BrandingSchema.safeParse(input.branding).success) {
|
||||
throw new ArchiveExportError('branding_invalid', 'branding')
|
||||
}
|
||||
if (!PdfLabelSetSchema.safeParse(input.labels).success) {
|
||||
throw new ArchiveExportError('branding_invalid', 'labels')
|
||||
}
|
||||
}
|
||||
|
||||
/** Step 1: the snapshot gate, with every asset accepted by the sanitiser. */
|
||||
function checkedSnapshot(sheet: SheetSnapshot): SheetSnapshot {
|
||||
let parsed: SheetSnapshot
|
||||
@@ -161,6 +177,7 @@ async function drawPages(pages: Pages): Promise<void> {
|
||||
export async function exportReportArchive(
|
||||
input: ExportInput,
|
||||
): Promise<ExportResult> {
|
||||
assertBrandingAndLabels(input)
|
||||
const sheet = checkedSnapshot(input.sheet)
|
||||
assertExportable(input.report, sheet)
|
||||
const envelope = buildEnvelope(input, sheet)
|
||||
|
||||
Reference in new issue
Block a user