Trust Boundaries and Data Flow
What you'll learn: You'll learn how to identify where untrusted data crosses into trusted parts of your application, and why these crossing points require validation.
What Is a Trust Boundary?
A trust boundary is an invisible line in your application where data moves from an untrusted source (user input, external APIs, URL parameters) into a trusted context (your database, server logic, internal systems). Think of it like airport security: passengers (data) from outside (untrusted) must pass through checkpoints before entering secure areas (trusted zones).
Every time data crosses a trust boundary, you must validate and sanitize it. The boundary itself is the critical defense point.
Common Trust Boundaries in Web Applications
- Browser → Server: Form submissions, HTTP headers, cookies
- URL → Application: Query strings, path parameters
- External API → Your Backend: Third-party API responses
- Database → Application Logic: Even data retrieved from your own database if it originally came from users
- User File Upload → Server Storage: File names, content, metadata
Why This Matters
Attackers inject malicious data at untrusted sources. If your code treats that data as safe once it crosses into "your" system without validation, you're vulnerable to injection attacks (SQL injection, XSS, command injection).
The key principle: Never trust data simply because it's "inside" your application now. Validate at the boundary where it enters each trusted context.
Mapping Data Flow
Trace how data moves through your application:
- Identify entry points (forms, APIs, file uploads)
- Mark trust boundaries where validation must occur
- Track where data goes next (database, rendered in HTML, executed as code)
- Validate before each sensitive operation
Key Takeaway: Trust boundaries exist wherever untrusted data enters trusted contexts—always validate and sanitize at these crossing points to prevent injection attacks.