Open Redirect on Aws
How Open Redirect Manifests in Aws
Open Redirect vulnerabilities in Aws applications typically emerge through improper validation of URL parameters that control redirection destinations. In Aws's serverless architecture, these vulnerabilities often appear in Lambda functions handling HTTP events, API Gateway configurations, and application routing logic.
A common pattern in Aws applications involves using query parameters like redirect_uri, next, or returnUrl to send users to external sites after authentication or processing. When developers fail to validate these URLs against an allowlist, attackers can craft malicious links that redirect users to phishing sites or execute further attacks.
// Vulnerable Aws Lambda function
exports.handler = async (event) => {
const redirectUrl = event.queryStringParameters.redirect;
statusCode: 302,
headers: {
Location: redirectUrl
},
body: ''
};
};This Lambda function accepts any URL from the redirect parameter without validation, making it vulnerable to open redirect attacks. An attacker could craft a URL like:
https://myapp.amazonaws.com/auth?redirect=https://phishingsite.comAnother Aws-specific manifestation occurs in API Gateway custom domain configurations where the base path is dynamically constructed from user input. If an application constructs redirect URLs using unvalidated user input combined with Aws-specific domain patterns, it creates exploitable vectors.
Serverless applications using Aws Amplify or Aws Amplify Console can also be vulnerable when client-side routing logic accepts redirect parameters that aren't properly validated. The client-side nature means the validation must happen in the browser or through API Gateway request validation, adding complexity to the security implementation.
Aws-Specific Detection
Detecting open redirect vulnerabilities in Aws environments requires understanding both the application logic and Aws's infrastructure. middleBrick's black-box scanning approach is particularly effective for Aws applications since it tests the actual running endpoints without requiring access to source code or credentials.
When scanning Aws Lambda functions exposed through API Gateway, middleBrick tests common redirect parameter names (redirect, next, returnUrl, url) with both internal and external URLs. The scanner attempts to trigger redirects to controlled domains and verifies if the application honors these redirects without proper validation.
For Aws Amplify applications, middleBrick examines the routing configuration and tests for client-side redirect vulnerabilities. The scanner checks if the application properly validates URLs before performing client-side navigation, which is crucial since Amplify apps often rely on browser-based routing.
middleBrick's LLM/AI security features also detect open redirect patterns in applications using AI/ML services on Aws. The scanner tests for prompt injection scenarios where malicious URLs might be injected into AI model prompts, potentially causing the model to generate or follow dangerous redirects.
The Aws-specific detection includes testing against common Aws domain patterns and infrastructure URLs. middleBrick verifies if applications properly restrict redirects to authorized Aws services versus allowing arbitrary external destinations. This is particularly important for applications that legitimately need to redirect to Aws services like Cognito, S3, or API Gateway endpoints.
middleBrick's scoring system evaluates open redirect severity based on the application's context within Aws. A redirect to an external domain from a financial application receives a higher risk score than a redirect within the same Aws account's resources. The scanner provides specific remediation guidance for Aws environments, such as using Aws WAF for request validation or implementing API Gateway request validation rules.
Aws-Specific Remediation
Remediating open redirect vulnerabilities in Aws applications requires implementing proper URL validation and leveraging Aws's native security features. The most effective approach combines allowlist validation with Aws's request validation capabilities.
For Lambda functions, implement strict URL validation before performing redirects:
const validRedirectDomains = ['https://myapp.com', 'https://aws.amazon.com'];
function isValidRedirect(url) {
try {
const parsed = new URL(url);
return validRedirectDomains.includes(parsed.origin);
} catch (e) {
return false;
}
}
exports.handler = async (event) => {
const redirectUrl = event.queryStringParameters.redirect;
if (redirectUrl && isValidRedirect(redirectUrl)) {
return {
statusCode: 302,
headers: {
Location: redirectUrl
},
body: ''
};
} else {
// Default to safe location
return {
statusCode: 302,
headers: {
Location: 'https://myapp.com/authorized'
},
body: ''
};
}
};For API Gateway, use request validation to prevent malicious URLs from reaching your backend:
// API Gateway request schema validation
{
"type": "object",
"properties": {
"redirect": {
"type": "string",
"pattern": "^(https://myapp\.com|https://aws\.amazonaws\.com|https://myapp\.aws\.amazonaws\.com)"
}
},
"required": ["redirect"]
}Aws WAF can provide additional protection by filtering requests with suspicious URL patterns before they reach your application:
// Aws WAF rule for open redirect protection
{
"Name": "OpenRedirectProtection",
"Priority": 10,
"Action": "BLOCK",
"VisibilityConfig": {
"SampledRequestsEnabled": true,
"CloudWatchMetricsEnabled": true,
"MetricName": "OpenRedirectBlocked"
},
"Statement": {
"ByteMatchStatement": {
"FieldToMatch": {
"UriPath": {}
},
"PositionalConstraint": "CONTAINS",
"SearchString": "redirect=javascript:"
}
}
}For Aws Amplify applications, implement client-side URL validation combined with API Gateway validation:
// Client-side validation in Amplify app
function safeRedirect(url) {
const allowedOrigins = ['https://myapp.com', 'https://aws.amazon.com'];
const parsed = new URL(url);
if (allowedOrigins.includes(parsed.origin)) {
window.location.href = url;
} else {
console.warn('Blocked unsafe redirect:', url);
}
} catch (e) {
console.error('Invalid URL:', url);
}
}middleBrick's Pro plan includes continuous monitoring that can automatically scan your Aws endpoints on a schedule, alerting you if new open redirect vulnerabilities are detected after deployments. This is particularly valuable in Aws environments where infrastructure as code (IaC) deployments can inadvertently introduce security regressions.