Cloud Security
Serverless
AWS Lambda
Azure Functions
Cloud Security
+2 more

Serverless Security: Securing AWS Lambda, Azure Functions & Cloud Functions

SCR Security Research Team
January 21, 2026
17 min read
Share

The Serverless Security Paradox

Serverless computing eliminates the patching burden — no servers to manage, no OS to update. But it doesn't eliminate security. It shifts the responsibility from infrastructure security to application and configuration security.

Key Shift: In serverless, you don't manage the server, but you still own the code, the configuration, the IAM permissions, and the data flow. These are where 90% of serverless vulnerabilities live.


Serverless Threat Model

ThreatDescriptionTraditional RiskServerless Risk
OS/Kernel exploitsAttacking the server operating systemHighMinimal (provider manages)
Injection attacksSQLi, NoSQLi, command injectionHighHigh (your code, your problem)
Over-privileged IAMFunction has more permissions than neededHighVery High (most common issue)
Event injectionMalicious payloads via event sourcesN/AHigh (new attack vector)
Dependency vulnerabilitiesVulnerable libraries in functionHighHigh (still your deps)
Data exposureSensitive data in environment varsMediumHigh (common anti-pattern)
Denial of walletAttacker triggers massive invocationsN/AHigh (pay-per-invocation)

The #1 Serverless Vulnerability: Over-Privileged IAM

Most Lambda functions are deployed with far more permissions than they need:

// BAD — Overly permissive policy (common anti-pattern)
{
  "Effect": "Allow",
  "Action": "*",
  "Resource": "*"
}

// GOOD — Minimum required permissions
{
  "Effect": "Allow",
  "Action": [
    "dynamodb:GetItem",
    "dynamodb:PutItem"
  ],
  "Resource": "arn:aws:dynamodb:us-east-1:123456789:table/UserProfiles"
}

IAM Least-Privilege Rules for Serverless:

  1. One IAM role per function (not shared across functions)
  2. Specify exact actions (not dynamodb:*)
  3. Specify exact resource ARNs (not *)
  4. Use conditions (time-based, IP-based, MFA-required where applicable)
  5. Audit permissions quarterly with IAM Access Analyzer

Event Injection Attacks

Serverless functions are triggered by events from many sources — each one is an input that must be validated:

Event SourceInjection RiskExample Attack
API GatewaySQL/NoSQL injection, XSSMalicious query parameters
S3 BucketPath traversal, code executionMalicious filename in event
SNS/SQSDeserialization, injectionPoisoned message payload
DynamoDB StreamsData manipulationModified record triggers bad logic
CloudWatch EventsNone (trusted source)Minimal risk
// VULNERABLE — Trusting S3 event data without validation
export const handler = async (event: S3Event) => {
  const key = event.Records[0].s3.object.key;
  const command = `convert /tmp/${key} /tmp/output.png`;
  exec(command);  // If key = "file; rm -rf /", command injection!
};

// SECURE — Validate and sanitize event data
export const handler = async (event: S3Event) => {
  const key = event.Records[0].s3.object.key;

  // Validate the key matches expected pattern
  if (!/^uploads\/[a-zA-Z0-9_-]+\.(jpg|png|gif)$/.test(key)) {
    throw new Error("Invalid file key");
  }

  // Use safe API instead of shell command
  await sharp(`/tmp/${path.basename(key)}`)
    .resize(800, 600)
    .toFile("/tmp/output.png");
};

Serverless Security Best Practices

PracticeImplementation
Least-privilege IAMOne role per function, exact actions + resources
Input validationValidate ALL event source data (API, S3, SQS, etc.)
Environment variablesUse Secrets Manager, not plaintext env vars for secrets
Dependency securitynpm audit / Snyk in CI/CD, minimize dependencies
Function timeoutSet minimum timeout (prevent infinite loops)
Concurrency limitsSet per-function concurrency to prevent denial-of-wallet
VPC isolationPlace functions accessing sensitive data in VPC
MonitoringCloudWatch + X-Ray for full invocation tracing

Denial-of-Wallet Attacks

Unlike traditional DDoS (denial of service), serverless enables denial-of-wallet — attackers trigger massive function invocations to run up your cloud bill.

Prevention:

  • Set concurrent execution limits per function
  • Set AWS account-level concurrency limits
  • Implement budget alerts and auto-shutdown at cost thresholds
  • Use WAF with rate limiting on API Gateway
  • Monitor invocation anomalies (> 10x baseline = alert)

Further Reading

Advertisement