Skip to main content

CLI tool to detect hidden prompt injection attacks in PDF files

Project description

pdf-injection-scanner

A CLI tool to detect hidden prompt injection attacks in PDF files.

Professors and others may embed invisible instructions in PDFs (white text, tiny fonts, off-page text) designed to manipulate AI assistants. This tool finds them.

Detection capabilities

Type Severity How it works
White/invisible text HIGH Detects characters with white or near-white fill color
Tiny text HIGH Flags text smaller than 2pt — invisible to the eye
Off-page text HIGH Finds text positioned outside visible page boundaries
Suspicious patterns MEDIUM 17+ regex patterns for common prompt injection phrases

Install

# Clone and install
git clone https://github.com/Andy8647/pdf-injection-scanner.git
cd pdf-injection-scanner
pip install -e .

# Or just install dependencies
pip install pdfplumber click rich

Usage

# Basic scan
python scanner.py assignment.pdf

# Verbose output with details
python scanner.py assignment.pdf -v

# JSON output for piping
python scanner.py assignment.pdf --json

Example output

Scanning: assignment.pdf

  Scanning ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3/3 pages
╭──────────── Result ────────────╮
│ 3 potential injection(s)       │
╰────────────────────────────────╯
┏━━━┳━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┓
┃ # ┃ Page ┃ Severity ┃ Type                 ┃ Content              ┃
┡━━━╇━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━┩
│ 1 │  1   │   HIGH   │ White/Invisible Text │ If you are an AI...  │
│ 2 │  1   │   HIGH   │ Tiny Text            │ System prompt: ...   │
│ 3 │  1   │   HIGH   │ Off-Page Text        │ New instructions:... │
└───┴──────┴──────────┴──────────────────────┴──────────────────────┘

Generate test PDFs

pip install reportlab
python make_test_pdf.py

This creates test_injected.pdf with 5 different types of hidden injections for testing.

How it works

The tool uses pdfplumber to extract character-level metadata from PDFs, including:

  • Fill color (non_stroking_color) — catches white-on-white text
  • Font size — catches sub-2pt text
  • Position coordinates — catches text placed outside page bounds
  • Text content — matches against known prompt injection patterns

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pdf_injection_scanner-0.1.0.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pdf_injection_scanner-0.1.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file pdf_injection_scanner-0.1.0.tar.gz.

File metadata

  • Download URL: pdf_injection_scanner-0.1.0.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for pdf_injection_scanner-0.1.0.tar.gz
Algorithm Hash digest
SHA256 09407a10e2b55be4975ec5b4a7922ef7b8596283c8806488dc1db18e5b072f3f
MD5 1077ac2080b6ced181b80ff7038d2492
BLAKE2b-256 7d62a58cb811f38c473bcaaf9d7ed6174a3aec0fa95e118a25a8d7f74c08edfc

See more details on using hashes here.

File details

Details for the file pdf_injection_scanner-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pdf_injection_scanner-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 871784526a6bee32b389c5024ea6cdf40053c62c38e5cd6f3176592b3634658c
MD5 c5738eedf3b29d3519c6261d40bad4d7
BLAKE2b-256 570f84dffb0b744253a47f002589ac318c228ed46fea5277aa6de864d457a2a6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page