- Newest
- Most votes
- Most comments
This behavior you're experiencing is unusual and concerning. The fact that you're seeing GET requests from an EC2 IP address (3.75.50.42) in the eu-central-1 region, rather than from CloudFront's edge locations, suggests that these requests are bypassing your CloudFront distribution and directly hitting your API Gateway Regional Endpoint.
There are a few potential explanations and steps you can take to address this:
-
API Gateway Endpoint Exposure: Even though your API Gateway endpoint is behind CloudFront, it might still be publicly accessible. This could allow direct requests to bypass CloudFront.
-
Security Group and Network ACL Settings: Check your API Gateway's VPC settings, security groups, and network ACLs to ensure they're not inadvertently allowing traffic from unexpected sources.
-
CloudFront Distribution Configuration: Verify that your CloudFront distribution is correctly set up to forward all requests to your API Gateway. Ensure that the origin settings are correct and that there are no misconfigured behaviors allowing direct access.
-
API Gateway Resource Policy: Implement or review your API Gateway resource policy to explicitly deny access from sources other than your CloudFront distribution. This can help prevent direct access to your API.
-
Custom Header for Origin Verification: Consider adding a custom header in CloudFront that your API Gateway can verify. This can help ensure that requests are coming through CloudFront.
-
WAF Rules: If you're using AWS WAF, you could set up rules to block requests that don't come from CloudFront IP ranges.
-
Logging and Monitoring: Enhance your logging and set up alerts for unexpected access patterns to quickly identify and respond to similar issues in the future.
The fact that these requests stop when you remove API Gateway from the CloudFront origins is intriguing. This could indicate a misconfiguration in how CloudFront is interacting with API Gateway, or it could be related to how your API Gateway endpoint is exposed.
Given the nature of the requests (trying to access a .env file), it appears these might be automated scans or potential security probes. It's crucial to lock down access to your API Gateway to ensure only legitimate traffic through your CloudFront distribution is allowed.
I recommend thoroughly reviewing your CloudFront and API Gateway configurations, implementing stricter access controls, and potentially reaching out to AWS Support for a more in-depth investigation of these unexpected requests.
Sources
Restrict API Gateway HTTP API access through CloudFront | AWS re:Post
Cors policy with cloudfront + Api Gateway (VPC Links) | AWS re:Post
API Gateway/Cloudfront and Shield Advanced Configuration | AWS re:Post
Relevant content
asked 3 years ago
- AWS OFFICIALUpdated a year ago
