📋 What Is It?
Function Event-Data Injection is the serverless form of the classic injection flaw: untrusted data reaches an interpreter (SQL engine, shell, eval, XML parser, outbound HTTP client, or log sink) and is treated as instructions instead of data. What makes it distinct is where the data comes from. A web app takes input almost entirely through the HTTP request; a Lambda can be triggered by a dozen event sources - S3, SNS, SQS, DynamoDB Streams, EventBridge, SES, Kinesis, IoT - and every field of every event can carry attacker-influenced data. The core mistake is treating the event object as trusted platform plumbing. The platform delivers the event; it does not sanitise it.
⚠️ Common Exploits
- SQL / NoSQL Injection: S3 key or message body concatenated into a query
- Command Injection: filename/subject passed to
exec,os.system, spawned CLI - Code Injection:
eval,Function(), dynamicrequire/importof an event field - Path Traversal: S3 keys / attachment names building file paths (
../../) - XXE: XML from an upload, queue body, or email parsed with entities enabled
- SSRF: event URL fetched, reaching internal endpoints or the metadata service
- Log Injection: newlines in event fields forging downstream log records
🔴 Attack Flow
↓
2. Platform wraps it in an event object (S3/SNS/DynamoDB record)
↓
3. Handler reads a field and trusts it (key, body, attribute)
↓
4. Field flows into an interpreter without safe construction
↓
5. IMPACT: Injection fires with the function's IAM role attached!
❌ Vulnerable Code
✅ Secure Code
✓ Prevention Checklist
- Validate every event against a strict per-source schema first
- Use positive allow-lists over deny-lists for field content
- Parameterise all SQL/NoSQL - never concatenate event fields
- Coerce scalars for NoSQL; reject raw JSON objects as filters
- Never
eval/ dynamicrequire/ shell event data - Pass CLI arguments as arrays; set
shell=False - Canonicalise paths and confirm they stay in the base dir
- Allow-list outbound URLs; block link-local/metadata ranges
- Disable external entities on every XML parser
- Scope each function's execution role to least privilege
- Remember: a WAF never sees non-HTTP triggers
- Monitor injection signatures across all event sources
🔍 Detection & Tools
Validation & Safe APIs:
Scanning & Runtime:
How to Test:
- Map every trigger that invokes the function, not just HTTP
- Upload objects with crafted keys (quotes,
;,../) - Publish messages / write rows carrying injection payloads
- Send inbound email with payloads in subject and attachment names
- Check whether event fields reach a sink without validation
- Watch for outbound calls to
169.254.169.254
🌍 Real-World
These are documented incident classes - recurring architectural patterns, not specific CVEs.
- Trusting the upload pipeline: HTTP upload endpoint is hardened, but the S3
ObjectCreatedprocessor behind it trusts the attacker-chosen object key in a shell or SQL sink. - Poisoned asynchronous messages: a public producer feeds SNS/SQS/Kinesis; the consumer interpolates the body - executing off the HTTP path with no request in the logs to correlate.
- Stream and table injection: any code path that writes to a DynamoDB table becomes an injection vector for the stream consumer's downstream query.
- Inbound email as an injection channel: SES delivers fully attacker-controlled subject/headers/attachment names into queries, commands, or XML parsers.
- SSRF to metadata theft: an event URL field fetched by the function reaches
169.254.169.254and lifts the execution role's temporary credentials.
📌 Quick Tips
- DO NOT trust the event because "it came from AWS"
- DO NOT concatenate event fields into queries or commands
- DO NOT
evalor dynamically require event data - DO validate every event against a strict schema
- DO parameterise and use safe, structured APIs
- DO scope the execution role to least privilege
- DO monitor all triggers, not just HTTP
📜 Compliance
Related Standards:
- OWASP Serverless Top 10 - SAS-1
- CWE-89 SQL Injection
- CWE-78 OS Command Injection
- CWE-94 Code Injection
- CWE-611 XML External Entity (XXE)