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'{
"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.
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/prodAWS API Gateway Security Card • Toc Consulting
Always obtain proper authorization before testing
Toc Consulting: AWS Security & Cloud Architecture
Our team helps engineering teams secure and architect AWS the right way: assessment in week one, a prioritized action plan in week two.