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:
- Returns:
A
ScrubbedSurfacecounter 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:
- Returns:
A 3-tuple of
ScrubbedSurfacecounters(javascript, open_action, additional_actions).javascriptcovers theRoot.Names.JavaScriptname tree;open_actioncoversRoot.OpenAction;additional_actionscoversRoot.AAplus per-pageAA.
- strip_annotations(pdf)[source]¶
Drop every page annotation from
pdf.Annotations can carry PII via their
/Contentsstrings, 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:
- Returns:
A
ScrubbedSurfacecounter 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 whoseRoot.OCPropertiesshould be wiped.- Return type:
- Returns:
A
ScrubbedSurfacecounter 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, deletesRoot.AcroFormoutright; otherwise clears the/V(value) and/DV(default value) entries on every field while preserving the form.
- Return type:
- Returns:
A 2-tuple
(counter, warnings). The counter is aScrubbedSurfacerecording the number of fields whose values were cleared (or 1 when the form was dropped wholesale). The warnings tuple containsSanitizationWarningentries, includingunknown_surface_presentwhen a hierarchical form (/Kidschains) 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:
- Returns:
A
ScrubbedSurfacecounter 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:
- Returns:
A
ScrubbedSurfacecounter (zero or one).
- strip_page_labels(pdf)[source]¶
Remove per-page label dictionaries.
- Parameters:
pdf (
Pdf) – An open PDF whoseRoot.PageLabelsshould be wiped.- Return type:
- Returns:
A
ScrubbedSurfacecounter (zero or one).