Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

What is Serverless?

Serverless means the cloud provider manages the servers. You write a function, upload it, and the provider runs it when a request arrives. You do not provision, patch, or scale any operating system.

AWS Lambda is the compute service. It runs your code in response to events. API Gateway is the front door. It receives HTTP requests from the internet and routes them to your Lambda function.

API Gateway

API Gateway is a managed service that sits between the internet and your Lambda functions. It handles:

  • Routing — maps HTTP methods and paths to Lambda functions
  • Throttling — default 10,000 requests/second per region
  • Authorization — IAM, Cognito, or custom Lambda authorizers
  • Stages — deploy to dev, staging, prod with separate URLs

Two types: REST API (full-featured, WAF support, request validation) and HTTP API (cheaper, faster, fewer features). This workshop uses REST API.

Each deployed endpoint gets a URL like: https://<api-id>.execute-api.<region>.amazonaws.com/<stage>/

Security note: API Gateway does not validate request bodies by default. Input validation is your responsibility in the Lambda code — which is why injection attacks work.

How a Request Flows

flowchart TD
    A[Browser / curl] -->|HTTPS request| B[API Gateway]
    B -->|Invoke| C[AWS Lambda]
    C -->|Execute| D[Your Python code]
    D -->|Return| E[HTTP Response]
    C -.->|IAM role| F[AWS Services<br/>S3, DynamoDB, etc.]

There is no EC2 instance, no Nginx, no Docker container in between. The Lambda function starts, runs, and shuts down automatically.

Lambda Internals

Firecracker microVM

Every Lambda function runs inside a Firecracker microVM — a lightweight virtual machine created by AWS. Firecracker boots in ~125ms and provides hardware-level isolation between functions. Each execution environment is a separate microVM with its own kernel, so one customer’s code cannot access another’s memory or filesystem.

This is why the Lambda sandbox user is sbx_user1051 — you will see this when you run id in the command injection lab.

Invocation

An invocation is one execution of your function. API Gateway receives a request → invokes Lambda → Lambda runs your code → returns the response. Each invocation is billed by duration (in 1ms increments) and memory allocated.

Cold Start vs Warm Start

Cold startWarm start
WhenFirst request, or after idle timeout (~5-15 min)Subsequent requests while environment is alive
What happensDownload code → start microVM → init runtime → run handlerRun handler directly (environment already loaded)
Latency100ms–10s (depends on runtime, package size, VPC)< 10ms overhead

Cold start creates a new execution environment from scratch. Warm start reuses an existing one. The /tmp filesystem persists between warm invocations — which is why our pickle RCE lab can verify file creation with a separate request.

Security implication: Data in /tmp and global variables survive between invocations. If one request writes sensitive data to /tmp, the next request (possibly from a different user) can read it.

Timeout and Limits

LimitValue
Max execution time15 minutes (our app uses default 6s)
Max memory10,240 MB
Max deployment package50 MB (zipped), 250 MB (unzipped)
Max /tmp storage10 GB
Environment variable size4 KB total

If a function hits the timeout, Lambda kills it and API Gateway returns 502 Bad Gateway. You will see this in the ReDoS lab — a single crafted string makes the function run until timeout.

Concurrency

Concurrency = number of invocations running at the same time. Each concurrent request gets its own execution environment (its own Firecracker microVM).

Concurrency limitValue
Default per region1,000 concurrent executions
Can request increaseUp to tens of thousands
Reserved concurrencyGuarantee capacity for a specific function
Provisioned concurrencyPre-warm environments to avoid cold starts

If 100 users hit your API at the same time, Lambda spins up 100 microVMs. If you hit the concurrency limit, additional requests are throttled (429 Too Many Requests).

Security implication: An attacker who triggers many concurrent invocations (e.g., via ReDoS) can exhaust your concurrency limit and deny service to legitimate users across ALL Lambda functions in the account.

Reference: AWS Lambda — How it works

What changes for security?

Traditional servers have a known attack surface: SSH, open ports, unpatched OS libraries. Serverless removes those, but introduces a different set of risks:

Traditional server riskServerless equivalent
Unpatched OSVulnerable third-party packages in your deployment
Open SSH portOverly permissive IAM role attached to the function
Secrets in config files on diskSecrets in plaintext environment variables (visible in console, logs, and printenv)
Web app injection (SQLi, XSS)Same injection flaws — the code still runs user input
Server-side request forgerySSRF can reach the Lambda runtime API at 169.254.100.1:9001
Denial of service (network flood)ReDoS — a single crafted request can exhaust the function timeout

The code vulnerabilities are the same. The infrastructure vulnerabilities are different.

OWASP Serverless Top 10

The OWASP Serverless Top 10 is a list of the most critical security risks in serverless applications. In this workshop we exploit all ten.

#VulnerabilityWhat we will do
SLS-1InjectionInject JavaScript (XSS) and OS commands
SLS-2Broken AuthenticationForge an admin JWT with the None algorithm attack
SLS-3Sensitive Data Exposure / SSRFReach the Lambda runtime API via SSRF
SLS-4Insecure DeserializationExecute arbitrary code via Python pickle
SLS-5Broken Access ControlAbuse an IAM role with s3:* on *
SLS-6Security MisconfigurationReview secrets in environment variables and overpermissive IAM
SLS-7Cross-Site ScriptingReflect unescaped input in the browser
SLS-8Insecure Third-Party ComponentsIdentify outdated packages with known CVEs
SLS-9Insufficient Logging & MonitoringObserve zero alarms and no tracing
SLS-10Event Injection / ReDoSCrash a Lambda with a single regex payload

Next step: Injection