Skip to main content
scrapai implements defense-in-depth security with input validation, SSRF protection, and agent safety controls.

Security Model

scrapai’s approach: the agent writes config, not code. JSON configs are validated through Pydantic before import, and at runtime, Scrapy executes deterministically with no AI in the loop. Threat model:
  1. Malicious user input: URLs, spider names, settings
  2. AI agent hallucination: Generates bad configs or tries to modify framework code
  3. Prompt injection from scraped pages: Untrusted web content influencing agent behavior
  4. SSRF attacks: Crawling internal/private network resources
  5. SQL injection: Through spider names or settings

Input Validation

All spider configs go through strict Pydantic validation before touching the database or crawler.

Spider Config Schema

Key protections:
  • extra="forbid": Unknown fields are rejected (prevents injection of arbitrary data)
  • Type enforcement: Strings must be strings, lists must be lists, etc.
  • Required fields: Missing data causes validation error
  • Field length limits: Prevents excessively large inputs

Spider Name Validation

Prevents: SQL injection, path traversal, and command injection. Examples:

SSRF Protection

Server-Side Request Forgery (SSRF) attacks trick the crawler into accessing internal resources.

URL Scheme Validation

Blocked schemes: file://, ftp://, gopher://, dict://, ldap://, and custom schemes.

Localhost Protection

Blocked hostnames: localhost, 0.0.0.0, 127.0.0.1, ::1 (IPv6 loopback)

Private IP Protection

Blocked IP ranges: Private networks (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16), loopback (127.0.0.0/8), link-local (169.254.0.0/16), multicast, and reserved ranges. DNS resolution check catches public hostnames that resolve to private IPs.

URL Length Limit

Prevents: Buffer overflow, DoS via memory exhaustion, and excessively large database fields.

Settings Validation

Extractor Whitelist

Prevents: Loading arbitrary Python modules as extractors.

Concurrency and Delay Limits

Prevents: DoS via excessive concurrency and zero-delay hammering.

Processor Whitelist

Prevents: Arbitrary code execution through custom processors.

Callback Validation

Reserved Names Protection

Prevents: Overwriting built-in Scrapy methods, Python injection, and namespace collisions.

Cross-Validation

Prevents: Runtime errors from calling non-existent callbacks.

SQL Injection Protection

All database queries use SQLAlchemy ORM with parameterized bindings.

Safe Query Pattern

CLI Database Access

db query validates table names against a whitelist; UPDATE/DELETE require row count confirmation.

Agent Safety

scrapai’s approach: the agent writes config, not code.

Permission Rules (Claude Code)

Configured via ./scrapai setup:
.claude/settings.local.json
What the agent can do:
  • Run ./scrapai commands, database clients, and allowed shell commands
  • Read any file (Python, JSON, configs, documentation)
  • Write, edit, and update JSON configs and analysis files
  • Use file search tools (Glob, Grep)
What the agent cannot do:
  • Modify Python framework code
  • Delete files
  • Run privileged commands
  • Execute arbitrary scripts

Validation Before Import

All configs must pass Pydantic validation before import:

Deterministic Runtime

At runtime, no AI models are called, no LLM inference on scraped content, and Scrapy executes deterministically based on validated config.

Prompt Injection Resistance

Scraped pages cannot influence the agent:
  1. AI is not in the crawl loop: Scrapy runs without LLM inference
  2. Configs are static: Once imported, extraction rules don’t change based on page content
  3. Validation is deterministic: Pydantic schemas don’t depend on context
Malicious page content is extracted as data only and the AI agent never sees it during crawl.

Security Checklist

Before deploying scrapai:
  • Review all spider configs for localhost/private IPs
  • Confirm extra="forbid" in Pydantic schemas
  • Verify SQLAlchemy ORM usage (no raw SQL)
  • Test SSRF protection with internal hostnames
  • Configure Claude Code permissions (if using AI agent)
  • Set up database backups
  • Enable SSL/TLS for PostgreSQL connections
  • Rotate S3 credentials if using S3 upload
  • Monitor logs for validation errors
  • Set up alerts for repeated validation failures (possible attack)

Reporting Vulnerabilities

Please DO NOT report security vulnerabilities through public GitHub issues. Email us directly: dev@discourselab.ai Include:
  1. Type of vulnerability (SQL injection, command injection, SSRF, etc.)
  2. Affected component (CLI command, spider, handler)
  3. Steps to reproduce
  4. Impact assessment
We’ll acknowledge within 72 hours and work with you on a fix.

In Scope

  • Injection vulnerabilities (SQL, command, code)
  • Path traversal / directory access
  • Remote code execution
  • Sensitive data exposure
  • Server-side request forgery (SSRF)
  • Insecure defaults

Out of Scope

  • Web scraping ethics (scraping public websites is not a vulnerability)
  • Cloudflare bypass techniques (core feature, not a bug)
  • Robots.txt violations (user responsibility)
  • Outdated dependencies (unless actively exploitable)

See Also

Migration

See validation in action during config import

Custom Callbacks

Write safe extraction logic with validated processors