Module 12 · AWS Lambda & Serverless Attack Surface

Manish Garg
Manish Garg Associate of (ISC)² · RingSafe
Apr 27, 2026
4 min read
Read as

Last updated: April 29, 2026

100% Free

No signup. No paywall. No catch. One of our 10 most-requested practitioner modules — published in full so anyone can learn for free. We earn through consulting, not by gating knowledge.

See all 10 free modules →

Why this module exists. Serverless is “no server to harden” — and a new attack surface that most security teams don’t review with the same rigour as VMs.

Why this module exists. Serverless is “no server to harden” — and a new attack surface that most security teams don’t review with the same rigour as VMs. Lambda functions, Cloud Functions, Azure Functions all share patterns: event-triggered execution, IAM-defined permissions, ephemeral compute, third-party dependencies. Each is an attack vector.

The Lambda attack surface — what’s different

  • Event sources are inputs. S3 PUT events, API Gateway requests, SQS messages, Kinesis records — all attacker-influenceable. Same OWASP injection patterns apply.
  • Execution role = permissions. Lambda doesn’t run as “the user” — it runs as its execution role. If that role is over-permissioned, every Lambda invocation has those permissions.
  • Cold start vs warm start. Same underlying micro-VM may serve multiple invocations sequentially. Globals persist. Bugs in init code affect all subsequent calls.
  • Dependencies. npm packages, pip wheels, layers — supply chain.

Attack 1: event injection

API Gateway → Lambda is a common pattern. Attacker controls the request body. Lambda parses it, passes to backend services. SQL injection, command injection, NoSQL injection — all the classic web-app bugs, just with a different runtime.

Worse: Lambda’s event object can contain headers like multiValueHeaders. A function expecting a string but receiving an array can break unpredictably:

// Vulnerable
const userId = event.queryStringParameters.userId;
db.query("SELECT * FROM users WHERE id = ?", userId);

// If attacker sends ?userId=1&userId=2:
// queryStringParameters.userId = "2"  (last wins)
// multiValueQueryStringParameters.userId = ["1","2"]
// Logic that uses one and not the other can be inconsistent

Attack 2: over-privileged execution role

Common pattern: developer creates a Lambda for “fetch from S3 bucket X.” Attaches the role AmazonS3FullAccess. Now every Lambda invocation has read/write/delete on every S3 bucket in the account.

If the Lambda is exploitable (even via subtle event-injection), the attacker gets the role’s permissions. Capital One repeated for every Lambda.

Worse: developers add IAM permissions iteratively. s3:* first, narrow it later — but “later” never happens.

Attack 3: cold-start state contamination

Lambdas reuse the same micro-VM for multiple invocations. Variables outside the handler are global state. If a previous invocation set sensitive data in a global, the next invocation can read it.

let lastUserData = null;  // Global

exports.handler = async (event) => {
    if (lastUserData) {
        // Bug: previous user's data leaks to current request
        console.log("Returning cached:", lastUserData);
        return lastUserData;
    }
    lastUserData = await fetchUser(event.userId);
    return lastUserData;
};

This is artificial; real bugs are subtler. But the pattern — “global state across invocations” — has caused multi-tenant data leaks in production.

Attack 4: dependency confusion / typosquatting

Lambda’s deployment artifact bundles dependencies. If the build pulls from npm/PyPI without integrity pinning, an attacker can publish a typosquat (requests-2 instead of requests) or hijack an internal package via dependency confusion.

2021 Snyk research: 35+ companies were vulnerable to dependency confusion in their Lambda deployments. Including AWS itself initially.

Attack 5: Lambda layer poisoning

Layers are shared dependencies across functions. If an attacker compromises a layer (via build pipeline access), every Lambda using that layer becomes compromised. Single point of failure with broad blast radius.

Real-world cases

  • Capital One 2019 — already covered, but the same SSRF→IMDS→IAM chain works against Lambda execution roles.
  • 2021 dependency confusion research — researcher Alex Birsan published, AWS / Apple / Microsoft / Tesla / Yelp / Shopify all confirmed exposure.

Try this yourself

# Audit Lambda execution roles
aws lambda list-functions --query 'Functions[*].[FunctionName,Role]' --output table

# For each role, check what it can do
aws iam list-attached-role-policies --role-name LAMBDA-ROLE
aws iam list-role-policies --role-name LAMBDA-ROLE

# Test cold-start contamination
# Deploy a function with a global, invoke twice with different inputs
# Verify the second invocation doesn't see first's data

# Audit dependencies for known-vulnerable
npm audit                      # Node
pip-audit                      # Python
trivy fs ./lambda-package/     # All

Defender’s checklist

  • Least-privilege execution roles. Each function gets its own role with only the permissions it needs. Never reuse a role across functions with different needs.
  • Input validation at the function entry. JSON Schema for the event payload. Reject unexpected fields.
  • Avoid global state for per-request data. Initialise per-invocation. Globals only for connection pools, configs.
  • Pin dependencies with integrity hashes (npm package-lock.json, pip requirements.txt with hashes).
  • Use managed scoped credentials for downstream services (e.g., DynamoDB-specific roles, KMS-specific permissions).
  • SCP / Org Policy at the AWS Org level: prevent Lambda functions from being created with * permissions.
  • Detection: CloudWatch metrics for Lambda errors, throttles. Alert on Lambda invocations from unexpected source IPs (via API Gateway access logs).
🧠
Check your understanding

Module Quiz · 6 questions

Pass with 80%+ to mark this module complete. Unlimited retries. Each question shows an explanation.

Want this for your team?

Custom team training + practitioner advisory

Beyond the free academy — we run private workshops, vCISO advisory, and red-team exercises tailored to your stack. For Indian SMBs scaling past their first hire.

Book team training call Replies in 4 working hrs · India-only · Senior consultants