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 30+ regex patterns for prompt injection phrases (EN + CN)

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.2.0.tar.gz (569.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.2.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pdf_injection_scanner-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d8419251c5f6a093b132b8590eddbd351342f587ceb58aadef879dfcea3b7989
MD5 155c47f2ddba82f17a835e2e55dd4b39
BLAKE2b-256 1776ebd7296ccb2170cee8c70016b4fc4d3233373fd73dcb351f85f3e65af8cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pdf_injection_scanner-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 083700468c922a122fb32dd44813647a20e669dfa0a59407949ed5112c52dd9f
MD5 77db70c9e5375f276e6abc5ada43e5f9
BLAKE2b-256 b387f872d6fc1f887b3bc3defdd6891422cb410157b1500f954e2a3deaa1c03e

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