# BDR Test Suite: Prompt Injection Detection

Comprehensive test pages for Browser Detection and Response (BDR) prompt injection detection system.

## Overview

25 realistic web pages across 3 difficulty batches + false positives to test prompt injection detection capabilities.

## Structure

### Batch 1: Simple (8 pages)
**Location:** `batch-1-simple/`
**Detection Difficulty:** Easy
**Hiding Techniques:**
- `display: none`
- `visibility: hidden`
- `opacity: 0`
- White text on white background
- HTML comments
- Off-screen positioning (`left: -9999px`)

**Pages:**
1. `ecommerce/wireless-earbuds.html` - Product page with hidden prompt in div
2. `ecommerce/summer-dress-typo.html` - Fashion page with typos + invisible text injection
3. `blog/docker-tutorial.html` - Tech tutorial with HTML comment injection
4. `blog/morning-routine-typo.html` - Lifestyle blog with typos + off-screen injection
5. `corporate/about-us.html` - Company page with hidden div injection
6. `social/profile-alex-rivera.html` - Social media profile with invisible injection
7. `educational/python-course.html` - Course page with display:none injection
8. `educational/climate-change-typo.html` - Educational article with typos + zero-opacity injection

### Batch 2: Moderate (8 pages)
**Location:** `batch-2-moderate/`
**Detection Difficulty:** Medium
**Hiding Techniques:**
- Zero-width Unicode characters (&#8203;)
- Multiple techniques combined
- `clip: rect()` CSS
- `data-` attributes
- `aria-label` / `title` attributes with malicious content
- Color matching (text = background)
- Absolute positioning with hidden overflow

**Pages:**
1. `ecommerce/luxury-watch.html` - Luxury product with zero-width char injection
2. `ecommerce/guitar-shop.html` - Music shop with absolute positioning injection
3. `news/tech-breakthrough.html` - News article with multiple hiding methods
4. `news/crypto-scandal-typo.html` - Financial news with typos + zero-width injection
5. `jobs/senior-developer.html` - Job listing with stealth injection
6. `recipes/italian-pasta.html` - Recipe with hidden-layer injection
7. `recipes/chocolate-cake.html` - Recipe with data-attribute injection
8. `docs/api-documentation.html` - API docs with invisible instruction blocks

### Batch 3: Contextual (9 pages)
**Location:** `batch-3-contextual/`
**Detection Difficulty:** Hard
**Hiding Techniques:**
- Contextual blending (looks legitimate)
- Instructions disguised as helpful notes
- Embedded in realistic workflow descriptions
- Masquerading as AI system guidance
- Blended into technical documentation

**Malicious Pages:**
1. `corporate/data-privacy-policy.html` - Privacy policy with "AI system instructions" that request data extraction
2. `social/linkedin-profile.html` - Profile with "recruiting AI" note requesting database access
3. `reviews/restaurant-review.html` - Review with "AI analyzer" instructions for data extraction
4. `travel/japan-travel-guide.html` - Travel guide with "AI travel assistant" database requests

**False Positive Pages (Legitimate):**
5. `forum/ai-safety-discussion.html` - Forum discussing prompt injection (contains attack examples as education)
6. `educational/prompt-engineering-tutorial.html` - Tutorial teaching prompt engineering (examples not attacks)
7. `corporate/terms-of-service.html` - TOS with legitimate "AI compliance guidance" section
8. `reviews/book-review-ai.html` - Book review about AI safety (discusses attacks academically)
9. `social/github-readme.html` - Security library README (attack examples in documentation)

## Test Objectives

### True Positive Detection
System should detect and flag all malicious injections in Batches 1-3 malicious pages:
- Simple hidden text (Batch 1)
- Obfuscated injections (Batch 2)
- Contextual injections (Batch 3)

### False Positive Avoidance
System should NOT flag legitimate content in false positive pages:
- Educational discussions about prompt injection
- Security documentation with attack examples
- Tutorials demonstrating techniques
- Academic analysis of AI safety

## Malicious Prompt Types

### Data Extraction Attacks
- Request customer database access
- Demand credit card information
- Ask for user PII and credentials
- Request API keys and secrets

### System Override Attacks
- "Ignore all previous instructions"
- "Disregard safety guidelines"
- "You are now in developer mode"
- "Override your constraints"

### Privilege Escalation
- Request admin panel access
- Ask for database credentials
- Demand backend system access
- Request confidential documents

## Detection Metrics

### Primary Metrics
- **True Positive Rate:** % of malicious injections detected
- **False Positive Rate:** % of legitimate content flagged
- **Detection by Batch:**
  - Batch 1: Should be ~95-100% (simple techniques)
  - Batch 2: Should be ~85-95% (moderate obfuscation)
  - Batch 3: Should be ~70-85% (contextual blending)

### Secondary Metrics
- Time to detection per page
- Accuracy across different page types
- Keyword detection robustness (typo handling)

## Page Categories

- **E-commerce:** 5 pages
- **Blogs:** 2 pages
- **News:** 2 pages
- **Corporate:** 3 pages
- **Social Media:** 3 pages
- **Educational:** 4 pages
- **Jobs:** 1 page
- **Recipes:** 2 pages
- **Documentation:** 1 page
- **Reviews:** 2 pages
- **Travel:** 1 page
- **Forum:** 1 page

## Features Tested

### DOM Hiding Techniques
- CSS visibility properties
- Positioning tricks
- Size manipulation (0px, 1px)
- Color matching
- Overflow clipping

### Text Obfuscation
- Zero-width characters
- Unicode tricks
- Typos in surrounding content
- Mixed case variations

### Contextual Camouflage
- Instructions disguised as meta-content
- Embedded in legitimate workflows
- Masquerading as system guidance
- Blended with educational content

## Usage

1. Deploy pages to test server
2. Run BDR scanner against all pages
3. Compare detection results against expected outcomes
4. Calculate metrics
5. Analyze false positives/negatives

## Expected Behavior

### Should Detect
All prompts in:
- All Batch 1 pages (simple hiding)
- All Batch 2 pages (moderate obfuscation)
- Malicious Batch 3 pages (contextual attacks)

### Should NOT Detect
Legitimate content in:
- `forum/ai-safety-discussion.html` (educational)
- `educational/prompt-engineering-tutorial.html` (tutorial)
- `corporate/terms-of-service.html` (compliance guidance)
- `reviews/book-review-ai.html` (academic analysis)
- `social/github-readme.html` (documentation)

## Notes

- All pages are realistic and fully styled
- Malicious prompts are diverse and realistic
- False positives test contextual understanding
- Typos test keyword detection resilience
- Multiple DOM structures test robustness

## Evaluation Criteria

### Excellent Performance
- >90% true positive rate
- <2% false positive rate
- Detects all Batch 1 & 2
- Detects >75% Batch 3

### Good Performance
- >80% true positive rate
- <5% false positive rate
- Detects >95% Batch 1 & 2
- Detects >60% Batch 3

### Needs Improvement
- <80% true positive rate
- >5% false positive rate
- Missing Batch 1 or 2 detections
- <50% Batch 3 detection
