Insecure Direct Object Reference on Aws
How Insecure Direct Object Reference Manifests in Aws
INSECURE Direct Object Reference (IDOR) in Aws applications often occurs when developers expose internal identifiers like database IDs, object keys, or resource names directly in API endpoints. Aws's ecosystem, with services like DynamoDB, S3, and Lambda, creates unique patterns where IDOR vulnerabilities emerge.
A common Aws-specific pattern involves S3 bucket object access. Consider a file sharing service using S3 for storage:
app.get('/api/files/:fileId', async (req, res) => {
const fileId = req.params.fileId;
const s3 = new AWS.S3();
const params = { Bucket: 'my-app-files', Key: fileId };
const data = await s3.getObject(params).promise();
res.send(data.Body);
});This code directly uses the fileId parameter to access S3 objects without verifying the requesting user's authorization. An attacker can enumerate S3 object keys by guessing common patterns or using tools to discover valid keys, accessing files belonging to other users.
DynamoDB presents another Aws-specific IDOR scenario. When using partition keys as direct identifiers:
app.get('/api/users/:userId', async (req, res) => {
const userId = req.params.userId;
const dynamodb = new AWS.DynamoDB();
const params = { TableName: 'Users', Key: { id: { S: userId } } };
const data = await dynamodb.getItem(params).promise();
res.send(data.Item);
});Without proper authorization checks, any authenticated user can retrieve any user record by changing the userId parameter. Aws's NoSQL nature makes these scans particularly dangerous since there's no SQL injection protection layer.
Lambda functions triggered by API Gateway create additional IDOR risks. When Lambda functions process S3 object keys or DynamoDB partition keys directly:
exports.handler = async (event) => {
const fileId = event.queryStringParameters.fileId;
const s3 = new AWS.S3();
const params = { Bucket: 'my-app-files', Key: fileId };
const data = await s3.getObject(params).promise();
return { statusCode: 200, body: data.Body.toString() };
};The serverless nature means there's no traditional application layer to enforce authorization consistently across all entry points.
Aws-Specific Detection
Detecting IDOR in Aws applications requires understanding Aws-specific attack patterns and scanning methodologies. The Aws ecosystem's distributed nature means vulnerabilities can exist across multiple services that traditional scanners might miss.
middleBrick's Aws-specific detection includes scanning for:
S3 Object Enumeration: Testing for predictable S3 key patterns like UUIDs, timestamps, or sequential IDs. The scanner attempts to access objects using common patterns and analyzes response codes to identify accessible resources.
DynamoDB Key Enumeration: Testing partition key access patterns, especially when keys are exposed in URLs or request bodies. The scanner checks for consistent error responses that might reveal valid keys.
Lambda Authorization Bypass: Testing whether Lambda functions properly validate user context before processing requests. This includes checking for missing IAM role permissions or insufficient resource-level policies.
Aws API Gateway Authorization: Verifying that API Gateway methods have proper authorizer configurations and that Lambda authorizers validate all necessary claims.
Here's how middleBrick detects these issues:
middlebrick scan https://api.example.com --profile aws
# Output includes:
Authentication: C (40/100) - Missing IAM role validation
BOLA/IDOR: B (75/100) - Potential S3 object enumeration
Property Authorization: C (60/100) - Missing DynamoDB authorization checksThe Aws profile enables specific checks for Aws service patterns, including testing for common Aws-specific vulnerabilities like:
- S3 bucket policy misconfigurations
- DynamoDB IAM policy over-permissiveness
- Lambda function execution role misuse
- API Gateway resource policy weaknesses
Manual detection techniques include using Aws CLI to enumerate accessible resources:
aws s3 ls s3://my-app-files/ --recursive
aws dynamodb scan --table-name Users --select COUNTThese commands can reveal whether IAM policies allow excessive access that could lead to IDOR exploitation.
Aws-Specific Remediation
Remediating IDOR in Aws applications requires leveraging Aws's native security features and implementing proper authorization patterns. The key is never trusting client-provided identifiers and always validating access rights.
S3 Authorization Pattern:
app.get('/api/files/:fileId', async (req, res) => {
const fileId = req.params.fileId;
const userId = req.user.id;
// Validate user owns this file
const s3 = new AWS.S3();
const params = { Bucket: 'my-app-files', Key: fileId };
try {
const headData = await s3.headObject(params).promise();
const metadata = headData.Metadata;
if (metadata.ownerId !== userId) {
return res.status(403).json({ error: 'Access denied' });
}
const data = await s3.getObject(params).promise();
res.send(data.Body);
} catch (err) {
if (err.code === 'NotFound') {
return res.status(404).json({ error: 'File not found' });
}
return res.status(500).json({ error: 'Internal server error' });
}
});This pattern uses S3 object metadata to store ownership information, ensuring users can only access files they own.
DynamoDB Authorization Pattern:
app.get('/api/users/:userId', async (req, res) => {
const requestedUserId = req.params.userId;
const currentUserId = req.user.id;
if (requestedUserId !== currentUserId) {
return res.status(403).json({ error: 'Access denied' });
}
const dynamodb = new AWS.DynamoDB();
const params = { TableName: 'Users', Key: { id: { S: requestedUserId } } };
try {
const data = await dynamodb.getItem(params).promise();
if (!data.Item) {
return res.status(404).json({ error: 'User not found' });
}
res.send(data.Item);
} catch (err) {
return res.status(500).json({ error: 'Internal server error' });
}
});Aws IAM Policy Hardening:
{
Related CWEs: bolaAuthorization
| CWE ID | Name | Severity |
|---|---|---|
| CWE-250 | Execution with Unnecessary Privileges | HIGH |
| CWE-639 | Insecure Direct Object Reference | CRITICAL |
| CWE-732 | Incorrect Permission Assignment | HIGH |