📄 Host-Based WAF Rule for ALB
🎯 Objective
Block unwanted or bot traffic hitting the ALB directly via its AWS DNS name or public IP, while only allowing requests that use the valid application domain (solutions.example.co.in).
Benefits:
- Reduces 4XX noise in CloudWatch
- Protects the application from direct scanning attempts
🔧 Approach
- Use AWS WAF v2 Web ACL attached to the ALB.
- Create a ByteMatch rule that inspects the
Hostheader. - Allow requests only if the
Hostheader exactly matchessolutions.example.co.in. - Block everything else by setting the Web ACL default action to
Block.
✅ Rule Definition (JSON)
⚙️ Configuration Steps
- Navigate to AWS WAF → Web ACLs.
- Edit the Web ACL attached to your ALB.
- Add a new Rule → Rule builder → Custom request rule.
- Paste the JSON above or configure equivalent settings in the console.
- Set the Web ACL default action to
Block. - Place this rule at a higher priority than any managed rules.
- (Optional) Add additional Allow rules for other valid domains (e.g.,
api.example.co.in).
🛡️ Best Practices
- Start in COUNT mode before enforcing to ensure no valid traffic is accidentally blocked.
- If using multiple domains, define an OR condition or add separate rules for each.
- Retain AWS Managed Rules (e.g.,
AWSManagedRulesCommonRuleSet) after the Host header rule for additional protection. - Monitor CloudWatch metrics for this rule to verify effectiveness.
🔍 Validation
Run test requests:- Query Athena ALB logs post-deployment to confirm only valid Host requests pass through.
🎯 Expected Outcome
- Bots and scanners hitting the ALB via IP or AWS-assigned DNS are blocked at the WAF layer.
- Only legitimate traffic using
solutions.example.co.inis processed. - CloudWatch 4XX error alarms show reduced false positives from bot noise.
