T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/redact_contract.py:204
- Finding
- Redacted PDF Retains Recoverable Underlying Content## Vulnerability Details **File Location**: `scripts/redact_contract.py:204-217` **Vulnerability Type**: Insecure visual-only redaction **Risk Level**: High **Vulnerable Code**: ```python for page_num, page_values in values_by_page.items(): if page_num >= len(doc): continue page = doc[page_num] for fv in page_values: x0, y0, x1, y1 = fv.value_bbox pdf_x0, pdf_y0 = x0 * scale, y0 * scale pdf_x1, pdf_y1 = x1 * scale, y1 * scale padding = 3 rect = fitz.Rect(pdf_x0 - padding, pdf_y0 - padding, pdf_x1 + padding, pdf_y1 + padding) page.draw_rect(rect, color=(0, 0, 0), fill=(0, 0, 0)) doc.save(output_path) doc.close() ``` ### Technical Analysis The implementation draws opaque rectangles over sensitive values but does not remove the underlying PDF text, image pixels, or content streams. An opaque drawing operation is a visual overlay rather than a secure redaction operation. Existing text may remain available through text extraction, while scanned image pixels remain embedded beneath the rectangle. PDF editing or forensic tools may also permit removal or bypass of the overlay object. Consequently, the generated file can appear redacted while continuing to contain the original confidential information. ### Attack Path 1. A user processes a confidential contract and distributes the generated redacted PDF. 2. An attacker obtains that PDF without requiring access to the source document. 3. The attacker uses a PDF editor, object inspector, text extractor, or content-stream parser. 4. The attacker removes or bypasses the rectangle objects, extracts underlying text, or recovers the original scanned image. 5. Sensitive contract values hidden by the visual overlays are disclosed. ### Impact Assessment This issue can disclose identities, telephone numbers, addresses, bank accounts, contract amounts, project identifiers, and other contract data. ...[truncated 160 chars]
- Remediation
- ## Remediation Suggestions - Use PyMuPDF redaction annotations and invoke the API that permanently applies those redactions. - Save the result with appropriate garbage collection and content cleaning so removed objects are not retained. - For scanned contracts, flatten each finalized redacted page into a new raster image and construct a new image-only PDF. - Ensure metadata, embedded files, annotations, alternate image representations, and OCR text layers are also sanitized. - Add automated tests that attempt text extraction, object removal, image extraction, and content-stream inspection on generated files. - Do not describe an output as securely redacted unless these recovery tests fail.
