feat: add SSRF protection for df.http() - #46
Merged
Conversation
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.
Contributor
There was a problem hiding this comment.
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.rsmodule 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 ofsubmitted_by/login_role, and threading of those fields throughHttpConfigand 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 |
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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::ffff:A.B.C.D→ extract and check IPv4)validate_url_host) — reqwest skips DNS resolution for IP literal URLs, so the resolver alone is insufficientSsrfSafeResolver) that checks resolved IPs before TCP connect — prevents DNS rebinding attacksModified:
src/activities/execute_http.rsHTTP BLOCKED (scheme)andHTTP BLOCKED (ip)audit logs withsubmitted_byandlogin_roleModified:
src/orchestrations/execute_function_graph.rssubmitted_byandlogin_rolefromFunctionNodeintoHttpConfigJSONModified:
src/types.rssubmitted_byandlogin_rolefields toHttpConfigModified:
Cargo.tomlno-ssrf-protectionCargo feature to opt out for local dev/testingModified:
.github/workflows/ci.ymlno-ssrf-protectionModified:
docs/spec-ssrf-protection.mdno-ssrf-protectioninversionModified:
docs/spec-security-model.mdNew:
tests/e2e/sql/36_ssrf_protection.sqlfile://scheme, allow legitimate public HTTPSDesign
Two-layer model:
Key decisions:
no-ssrf-protectionis an opt-in escape hatch--no-default-featuresbuilds (e.g., CI) retain SSRF protection