Skip to main content
ESLint Interlace
Plugin: lambda-securityRules

no-unvalidated-event-body

Detect Lambda handlers using event body without validation

Keywords: input validation, event body, injection, CWE-20, Lambda, Zod, Joi, Middy, serverless CWE: CWE-20
OWASP: A03:2021-Injection

Detects Lambda handlers that use event body, query parameters, or path parameters without validation. This rule is part of eslint-plugin-lambda-security and provides LLM-optimized error messages.

🚨 Security rule | 💡 Provides suggestions | ⚠️ Set to error in recommended

Quick Summary

AspectDetails
CWE ReferenceCWE-20 (Input Validation)
CVSS Score8.0 High
Auto-Fix💡 Suggests schema validation
CategorySecurity
Best ForLambda functions processing user input

Vulnerability and Risk

Vulnerability: Using untrusted input from Lambda events without validation can lead to injection attacks, type confusion, and business logic bypasses.

Risk: Unvalidated input enables:

  • NoSQL injection attacks
  • SQL injection in downstream services
  • Command injection via shell commands
  • Business logic manipulation
  • Type confusion vulnerabilities

Rule Details

This rule detects direct usage of these event properties without passing through validation functions:

  • event.body
  • event.queryStringParameters
  • event.pathParameters
  • event.headers
  • event.multiValueQueryStringParameters

Why This Matters

RiskImpactSolution
💉 InjectionDatabase/command injection attacksValidate with schema library
📊 Type ConfusionUnexpected data types break logicUse typed validation
🔓 Auth BypassManipulated fields bypass checksStrict schema enforcement

Configuration

OptionTypeDefaultDescription
allowInTestsbooleantrueAllow in test files
additionalPropertiesstring[][]Additional event properties to check
{
  rules: {
    'lambda-security/no-unvalidated-event-body': ['error', {
      allowInTests: true,
      additionalProperties: ['customProperty']
    }]
  }
}

Examples

❌ Incorrect

Awaiting a tested example. The previous snippet was removed because the rule does not behave as the doc claimed; track the regression in benchmarks/FP_FN_REMEDIATION_TRACKER.md.

✅ Correct with Zod

zod

✅ Correct with Middy Validator

zod

✅ Correct with Joi

zod

Validation Libraries

LibraryType SafetyPerformanceEcosystem
Zod✅ ExcellentGoodTypeScript-first
Joi⚠️ ManualGoodNode.js standard
Yup⚠️ ManualGoodReact forms
Middy⚠️ ManualExcellentLambda middleware
class-validator✅ GoodModerateNestJS

Security Impact

VulnerabilityCWEOWASPCVSSImpact
Input Validation20A03:20218.0 HighInjection attacks
Improper Neutralization74A03:20217.5 HighCommand/query injection

Safe Patterns (Not Flagged)

// Type checking
if (typeof event.body === 'string') { ... }

// Null checking
if (event.body) { ... }

// Optional chaining
const name = event.body?.name;

// Logging (not using the data)
console.log('Received event', event.body);

Further Reading