Skip to content

feat: add SSRF protection for df.http() - #46

Merged
Pino de Candia (pinodeca) merged 5 commits into
mainfrom
pinodeca/ssrf-sec
Mar 10, 2026
Merged

feat: add SSRF protection for df.http()#46
Pino de Candia (pinodeca) merged 5 commits into
mainfrom
pinodeca/ssrf-sec

Conversation

@pinodeca

@pinodeca Pino de Candia (pinodeca) commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Add compile-time dataplane SSRF protection that blocks HTTP requests to private/reserved IP ranges from the pg_durable background worker. This prevents malicious users from using df.http() to probe internal network services, cloud metadata endpoints (169.254.169.254), or localhost services.

Addresses threat T8 (CRITICAL) in spec-security-model.md.

Changes

New: src/ssrf.rs

  • IP blocklist covering RFC 1918, loopback, link-local, ULA, and unspecified ranges
  • IPv4-mapped IPv6 handling (::ffff:A.B.C.D → extract and check IPv4)
  • URL scheme validation (HTTP/HTTPS only)
  • Pre-flight IP-literal check (validate_url_host) — reqwest skips DNS resolution for IP literal URLs, so the resolver alone is insufficient
  • Custom DNS resolver (SsrfSafeResolver) that checks resolved IPs before TCP connect — prevents DNS rebinding attacks
  • Comprehensive unit tests (25 tests covering all ranges, edge cases, IPv6 variants, IP literals)

Modified: src/activities/execute_http.rs

  • Scheme validation before any network I/O
  • IP-literal validation before reqwest sees the URL
  • SSRF-safe DNS resolver injected into reqwest client
  • Structured HTTP BLOCKED (scheme) and HTTP BLOCKED (ip) audit logs with submitted_by and login_role

Modified: src/orchestrations/execute_function_graph.rs

  • Thread submitted_by and login_role from FunctionNode into HttpConfig JSON

Modified: src/types.rs

  • Add submitted_by and login_role fields to HttpConfig

Modified: Cargo.toml

  • SSRF protection is on by default (no feature flag needed)
  • New no-ssrf-protection Cargo feature to opt out for local dev/testing

Modified: .github/workflows/ci.yml

  • Clippy runs in both modes: default (SSRF on) and no-ssrf-protection

Modified: docs/spec-ssrf-protection.md

  • Status updated to Completed
  • Feature flag docs updated to reflect no-ssrf-protection inversion

Modified: docs/spec-security-model.md

  • T8 status updated to Implemented
  • Trimmed duplicated SSRF implementation detail, now references spec-ssrf-protection.md

New: tests/e2e/sql/36_ssrf_protection.sql

  • E2E test with 4 cases: block metadata endpoint (169.254.169.254), block localhost (127.0.0.1), block file:// scheme, allow legitimate public HTTPS

Design

Two-layer model:

  1. Layer 1 (this PR): Compile-time dataplane protection — hardcoded IP blocklist, no GUC/superuser override possible
  2. Layer 2 (future): Customer-level controls — URL allowlists, REVOKE EXECUTE, rate limiting

Key decisions:

  • SSRF protection is on by default with no feature flag needed; no-ssrf-protection is an opt-in escape hatch
  • --no-default-features builds (e.g., CI) retain SSRF protection
  • Both IP literals and DNS-resolved hostnames are checked (two enforcement points)
  • DNS rebinding prevented by checking IPs inline in the resolver (same address used for check and connect)
  • Error messages do not leak resolved IPs
  • CI verifies compilation in both modes

Add impact/severity assessment to all threats (T0-T11) in the security
spec. Severity reflects the unmitigated impact of each threat regardless
of implementation status.

- Add implementation priority summary table to Section 3.2
- Annotate each threat with severity and implementation status
- Expand T4, T8, T9, T10, T11 descriptions with attack impact detail
- Rewrite T8 (SSRF) to reference separate spec-ssrf-protection.md
- Rewrite T9 to defer customer-level controls to a future spec
Add compile-time dataplane protection that blocks HTTP requests to
private/reserved IP ranges from the background worker. This prevents
malicious users from using df.http() to probe internal network services,
cloud metadata endpoints, or localhost services.

Implementation:
- New src/ssrf.rs module with IP blocklist (RFC 1918, loopback,
  link-local, ULA) and custom DNS resolver (SsrfSafeResolver)
- Scheme validation: only http:// and https:// allowed
- IPv4-mapped IPv6 handling (::ffff:A.B.C.D)
- DNS rebinding protection via inline IP check before connect
- Cargo feature 'ssrf-protection' (default=on), no runtime bypass
- Audit logging: submitted_by and login_role on all HTTP requests
- New spec: docs/spec-ssrf-protection.md

Addresses threat T8 in spec-security-model.md.
The initial SSRF implementation only checked IPs via a custom DNS
resolver. However, reqwest does not invoke the DNS resolver for IP
literal URLs (e.g., http://169.254.169.254/), leaving them unprotected.

Fixes:
- Add validate_url_host() pre-flight check that parses the URL, detects
  IP literals (including bracketed IPv6 like [::ffff:127.0.0.1]), and
  checks them against the blocklist before reqwest sees the URL
- Add structured 'HTTP BLOCKED (ip)' audit log with submitted_by and
  login_role for both IP-literal and resolver-based blocks

Tests:
- E2E test (36_ssrf_protection.sql) with 4 cases: block metadata
  endpoint, block localhost, block file:// scheme, allow public HTTPS
- Unit tests for validate_url_host() covering IPv4/IPv6 literals,
  public IPs, and hostname passthrough

CI:
- Split clippy into two steps: with and without ssrf-protection feature
  to verify both compilation modes
…ty spec

- Invert Cargo feature: SSRF protection is now on by default (no feature
  needed). Add 'no-ssrf-protection' as an opt-in escape hatch for local
  development. This ensures --no-default-features builds still have SSRF
  protection enabled.
- Update all cfg gates in ssrf.rs and execute_http.rs accordingly.
- Update CI to clippy-check both configurations.
- Trim duplicated SSRF implementation detail from spec-security-model.md,
  referencing spec-ssrf-protection.md for the full specification.
- Update spec-ssrf-protection.md status to Completed.
- Update spec-security-model.md T8 status to Implemented.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds Server-Side Request Forgery (SSRF) protection for df.http(), preventing HTTP requests to private/reserved IP ranges from the pg_durable background worker. It implements a compile-time IP blocklist with DNS rebinding protection, addressing threat T8 (CRITICAL) in the security model.

Changes:

  • New src/ssrf.rs module with IP blocklist, URL scheme/host validation, a custom DNS resolver (SsrfSafeResolver) that filters blocked IPs inline, and comprehensive unit tests
  • Integration of SSRF checks into the HTTP activity (execute_http.rs) with audit logging of submitted_by/login_role, and threading of those fields through HttpConfig and orchestration code
  • Updated security documentation (spec-ssrf-protection.md, spec-security-model.md), CI workflow for both compilation modes, and a new E2E test with 4 cases

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/ssrf.rs New module: IP blocklist, scheme/host validation, SSRF-safe DNS resolver, system resolver, unit tests
src/activities/execute_http.rs Integrates scheme validation, IP-literal check, SSRF-safe client builder, and audit logging
src/orchestrations/execute_function_graph.rs Threads submitted_by and login_role from FunctionNode into HttpConfig JSON
src/types.rs Adds submitted_by and login_role optional fields to HttpConfig
src/lib.rs Declares the new ssrf module
Cargo.toml Adds no-ssrf-protection feature flag
.github/workflows/ci.yml Adds clippy check with no-ssrf-protection feature
docs/spec-ssrf-protection.md New full specification document for SSRF protection
docs/spec-security-model.md Updates threat statuses, adds priority summary table, trims duplicated SSRF detail
tests/e2e/sql/36_ssrf_protection.sql E2E test: blocks metadata endpoint, localhost, file:// scheme; allows public HTTPS

Comment thread src/activities/execute_http.rs
Comment thread src/activities/execute_http.rs
Comment thread docs/spec-ssrf-protection.md Outdated
Comment thread docs/spec-ssrf-protection.md Outdated
Comment thread docs/spec-ssrf-protection.md
Comment thread docs/spec-ssrf-protection.md Outdated
- Disable HTTP redirects to prevent redirect-based SSRF bypass
- Fix df.http() argument order in spec examples (url, method)
- Fix IPv6 link-local mask in spec code sample (& 0xffc0)
- Replace fragile string matching with is_ssrf_block_error() helper
- Simplify feature gate: only gate blocklist contents, not all code
@pinodeca
Pino de Candia (pinodeca) merged commit 7b67602 into main Mar 10, 2026
5 checks passed
@pinodeca
Pino de Candia (pinodeca) deleted the pinodeca/ssrf-sec branch March 10, 2026 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants