API Gateway is the front door to AWS applications, proxying requests to Lambda, EC2, and other services. Attackers target misconfigured authorization, exposed endpoints, and information disclosure to access backend systems and exfiltrate data.
API Gateway offers REST APIs (v1), HTTP APIs (v2), and WebSocket APIs. REST APIs provide the most features including VTL request/response transforms, resource policies, and caching. HTTP APIs are simpler and cheaper. WebSocket APIs maintain persistent connections.
Attack note: REST APIs with VTL mapping templates can be exploited for server-side template injection if user input reaches the template
Endpoints can use NONE, IAM, Cognito, or Lambda authorizers. API keys are NOT authorization - they only control usage plans and rate limiting. Many developers mistakenly treat API keys as authentication, leaving endpoints effectively unprotected.
Attack note: Lambda authorizers with flawed logic (e.g., only checking token format, not signature) are a common bypass vector
API Gateway is often internet-facing by default, making misconfigurations directly exploitable. Missing or weak authorization allows unauthorized access to backend Lambda functions and services.
aws apigateway get-rest-apisaws apigatewayv2 get-apisaws apigateway get-resources \
--rest-api-id <api-id>aws apigateway get-method \
--rest-api-id <api-id> \
--resource-id <id> --http-method GETaws apigateway get-api-keys --include-valuesTool reference: Use CloudFox to enumerate API Gateway configurations and find unprotected endpoints across multiple AWS accounts. Pacu module apigateway__enum maps all APIs and authorization types.
aws apigateway get-resources --rest-api-id <api-id> | \
jq '.items[] | select(.resourceMethods) |
{path: .path, methods: (.resourceMethods | keys)}'aws apigateway get-method \
--rest-api-id <api-id> --resource-id <id> \
--http-method GET --query 'authorizationType'aws apigateway get-api-keys --include-values --query 'items[*].[name,value]'aws apigateway update-rest-api \
--rest-api-id <api-id> \
--patch-operations op=replace,path=/policy,value='{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":"*","Action":"execute-api:Invoke","Resource":"*"}]}'aws apigateway get-stages --rest-api-id <api-id>aws apigateway get-stage \
--rest-api-id <api-id> --stage-name dev \
--query 'variables'VTL (Velocity Template Language) mapping templates transform requests/responses. Weak Lambda authorizers can be bypassed with crafted tokens. Both are common attack vectors in REST APIs.
## Vulnerable VTL mapping template:
#set($input = $input.path('$.username'))
{"query": "SELECT * FROM users WHERE name='$input'"}
## Attacker sends:
{"username": "' OR '1'='1"}
## Resulting query:
SELECT * FROM users WHERE name='' OR '1'='1'
## Stage variable injection:
## If template uses: $stageVariables.dbHost
## Attacker modifies stage variable to point
## to attacker-controlled database# Common flaws in Lambda authorizers:
# 1. Only checks token format, not signature
curl -H "Authorization: Bearer eyJhbGci..." \
https://api.example.com/admin
# 2. Caching returns same policy for diff users
# First request with valid token caches "Allow"
# Subsequent requests with ANY token get cached Allow
# 3. Authorizer returns wildcard resource
# {"principalId":"user","policyDocument":{
# "Statement":[{"Effect":"Allow",
# "Action":"execute-api:Invoke",
# "Resource":"*"}]}}WebSocket APIs maintain persistent connections. Attackers can inject messages, hijack sessions, and use WebSocket connections for stealthy command-and-control channels that bypass HTTP-focused detection.
Weak authorizer on $connect route allows persistent unauthorized access
Inject malicious payloads via custom routes to backend Lambda
Send action payloads to discover hidden routes and admin functions
Use WebSocket for C2 that blends with legitimate application traffic
@connections API can send messages to other users' connections
Stream stolen data out via WebSocket to avoid HTTP logging
{
"authorizationType": "NONE",
"apiKeyRequired": false
}
// Anyone on the internet can call this endpointNo authorization - anyone with the URL can invoke the API endpoint
{
"authorizationType": "AWS_IAM",
"apiKeyRequired": false
}
// Requires AWS SigV4 signed requestsRequires valid IAM credentials with execute-api:Invoke permission
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": "*",
"Action": "execute-api:Invoke",
"Resource": "arn:aws:execute-api:*:*:*/*/*/*"
}]
}Allows any principal to invoke any method on any resource - no IP or VPC restrictions
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": "*",
"Action": "execute-api:Invoke",
"Resource": "arn:aws:execute-api:*:*:*/prod/GET/*",
"Condition": {
"IpAddress": {"aws:SourceIp": "10.0.0.0/8"}
}
}]
}Only allows GET requests from internal IP ranges on production stage
Never deploy APIs with NONE authorization. Use IAM, Cognito, or Lambda authorizers.
authorizationType: "AWS_IAM" | "COGNITO_USER_POOLS" | "CUSTOM"Log all API invocations to CloudWatch for security monitoring and forensics.
aws apigateway update-stage --rest-api-id <id> \
--stage-name prod --patch-operations \
op=replace,path=/accessLogSettings/destinationArn,value=<log-group-arn>Configure specific allowed origins. Never allow credentials with wildcard origin.
Access-Control-Allow-Origin: https://app.example.comImplement IP restrictions or VPC-only access using resource policies.
"Condition": {"IpAddress": {
"aws:SourceIp": ["10.0.0.0/8", "192.168.1.0/24"]
}}Reject malformed requests before they reach backend integrations.
aws apigateway update-method \
--rest-api-id <id> --resource-id <rid> \
--http-method POST --patch-operations \
op=replace,path=/requestValidatorId,value=<validator-id>Protect against SQL injection, XSS, and rate limiting with WAF rules.
aws wafv2 associate-web-acl \
--web-acl-arn <waf-arn> \
--resource-arn arn:aws:apigateway:region::/restapis/<id>/stages/prodList APIs, stages, resources, methods, authorizers, and export OpenAPI specs
Check for NONE auth methods, test API keys, examine VTL templates and resource policies
Bypass authorizers, inject via VTL templates, abuse CORS, or modify integrations directly
AWS API Gateway Security Card • Toc Consulting
Always obtain proper authorization before testing