Course contentsShow
← Security
Lesson 1960 of 3,05239. Cloud Security - Compute and ServerlessFree lesson

Injection Vulnerabilities in Serverless

Exploring command injection, SQL injection, and NoSQL injection risks in serverless functions and their unique attack surfaces.

Injection Vulnerabilities in Serverless

What You'll Learn

You'll discover how command injection, SQL injection, and NoSQL injection attacks exploit serverless functions through their unique event-driven attack surfaces.

The Serverless Injection Problem

Serverless functions process inputs from diverse event sources—API Gateway requests, S3 events, SNS messages, database streams. Each input type creates an injection opportunity if data flows unsafely into commands, queries, or system calls.

Unlike traditional servers where you control the entire stack, serverless functions often execute untrusted data directly against databases, operating systems, or other services within seconds of deployment—making injection vulnerabilities particularly dangerous.

Three Core Injection Types

Command Injection

Functions that shell out to OS commands using event data are vulnerable. If a Lambda function processes filenames from S3 events and passes them to subprocess or exec(), attackers controlling object names can inject shell commands.

SQL Injection

When functions build SQL queries by concatenating event parameters directly into query strings, classic SQL injection emerges. API Gateway body parameters flowing into unparameterized database queries allow attackers to manipulate queries.

NoSQL Injection

DynamoDB, MongoDB, or Cosmos DB queries constructed from event data without validation enable NoSQL injection. JSON payloads from API requests might manipulate query operators ($where, $ne) to bypass authentication or extract unauthorized data.

The Unique Serverless Twist

The attack surface differs because:

  • Event variety: Inputs arrive from HTTP, queues, storage events—not just web forms
  • Rapid execution: Functions fire and complete quickly, making detection harder
  • Stateless context: Each invocation starts fresh, complicating rate limiting
  • Multiple downstream targets: A single function might query databases, invoke APIs, and execute commands

Key Takeaway: Serverless injection vulnerabilities exploit the same fundamental flaws as traditional injection attacks, but the event-driven nature and diverse input sources create numerous entry points where untrusted data can flow into dangerous operations—requiring strict input validation at every event trigger point.