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

# uv (recommended)
uv tool install pdf-injection-scanner

# pip
pip install pdf-injection-scanner

# Homebrew (macOS)
brew install Andy8647/tap/pdf-injection-scanner

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

Usage

# Basic scan
pdf-scan assignment.pdf

# Verbose output with details
pdf-scan assignment.pdf -v

# JSON output for piping
pdf-scan 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.1.tar.gz (707.2 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.1-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pdf_injection_scanner-0.1.1.tar.gz
  • Upload date:
  • Size: 707.2 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.1.tar.gz
Algorithm Hash digest
SHA256 a9ed0c5f535b80dda816d754b8e75ccc34e85078e8106a282771a1606d3a674e
MD5 f28826b585d96526a9de3eff7382b9f0
BLAKE2b-256 27283e65cfb2025e997423f3aa17bef77812b872a261c671224379c1a9b10462

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pdf_injection_scanner-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 615f60729141911481e4e1d3bcedf254f8f0f32eb23cb71a030f290216f0ad68
MD5 2cb0336854808b1bf9dd0bb38893dc57
BLAKE2b-256 eeaf9c4c532e9b56423916ac09618457836ab39396673d806878af3cdf79948a

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