aeat.adapters.inbound.sanitizer._dynamic module

Dynamic-surface strip for adapters.inbound.sanitizer.

Dynamic surfaces are the parts of a PDF that can rewrite content at view time: embedded JavaScript, AcroForm field values, annotations, optional content groups, attachments. The Manafort, NSA Russia memo and AstraZeneca redaction-failure post-mortems all share the same root cause — these surfaces must be removed before content-stream rewriting so a JS action, layer toggle, or hierarchical AcroForm field cannot re-inject PII the sanitiser just stripped.

Each function in this module is a single-surface scrubber. They record their work as ScrubbedSurface rows so the SanitizationResult audit log carries one row per surface that was either present-and-cleared or absent (count zero).

strip_attachments(pdf)[source]

Remove every embedded file attachment from pdf.

Parameters:

pdf (Pdf) – An open PDF whose attachment table should be wiped.

Return type:

ScrubbedSurface

Returns:

A ScrubbedSurface counter recording how many attachments were removed.

strip_javascript(pdf)[source]

Remove embedded JavaScript from the Names tree and document actions.

Parameters:

pdf (Pdf) – An open PDF whose JavaScript surfaces should be wiped.

Return type:

tuple[ScrubbedSurface, ScrubbedSurface, ScrubbedSurface]

Returns:

A 3-tuple of ScrubbedSurface counters (javascript, open_action, additional_actions). javascript covers the Root.Names.JavaScript name tree; open_action covers Root.OpenAction; additional_actions covers Root.AA plus per-page AA.

strip_annotations(pdf)[source]

Drop every page annotation from pdf.

Annotations can carry PII via their /Contents strings, embedded files, or JavaScript actions. The sanitiser drops them entirely rather than scrubbing them per-key, since their only role in a justificante PDF is decoration.

Parameters:

pdf (Pdf) – An open PDF whose annotation arrays should be wiped.

Return type:

ScrubbedSurface

Returns:

A ScrubbedSurface counter of annotations removed across all pages.

strip_optional_content_groups(pdf)[source]

Remove any Optional Content (layer) properties from pdf.

OCG layers can selectively show or hide content at view time — a redaction that hides content with a layer toggle is not a redaction. The sanitiser drops the layers wholesale so any associated content streams are visible to the body rewriter.

Parameters:

pdf (Pdf) – An open PDF whose Root.OCProperties should be wiped.

Return type:

ScrubbedSurface

Returns:

A ScrubbedSurface counter of OCG entries removed (zero or one).

strip_acroform(pdf, *, drop_entirely=False)[source]

Clear AcroForm field values, optionally dropping the form structure.

Parameters:
  • pdf (Pdf) – An open PDF whose form values should be cleared.

  • drop_entirely (bool) – When True, deletes Root.AcroForm outright; otherwise clears the /V (value) and /DV (default value) entries on every field while preserving the form.

Return type:

tuple[ScrubbedSurface, tuple[SanitizationWarning, ...]]

Returns:

A 2-tuple (counter, warnings). The counter is a ScrubbedSurface recording the number of fields whose values were cleared (or 1 when the form was dropped wholesale). The warnings tuple contains SanitizationWarning entries, including unknown_surface_present when a hierarchical form (/Kids chains) is detected.

strip_thumbnails(pdf)[source]

Drop every page-level rasterised thumbnail.

Thumbnails can carry PII visible at a glance even after body sanitisation — a renderer that ignores the body but renders the thumbnail would still leak the original.

Parameters:

pdf (Pdf) – An open PDF whose page thumbnails should be wiped.

Return type:

ScrubbedSurface

Returns:

A ScrubbedSurface counter of thumbnails removed across all pages.

strip_outlines(pdf)[source]

Remove the document outline (bookmarks) tree.

Bookmarks have historically retained the redacted term in the AstraZeneca contract failure case. The sanitiser drops them.

Parameters:

pdf (Pdf) – An open PDF whose outline should be wiped.

Return type:

ScrubbedSurface

Returns:

A ScrubbedSurface counter (zero or one).

strip_page_labels(pdf)[source]

Remove per-page label dictionaries.

Parameters:

pdf (Pdf) – An open PDF whose Root.PageLabels should be wiped.

Return type:

ScrubbedSurface

Returns:

A ScrubbedSurface counter (zero or one).