Skip to content

[AWS WAF] How to block email domains using regular expression?

0

Hi, I am using the following regular expression to block email domains test.com or email.com, but it doesn't work as expected — it blocks all email domains. Here is my regular expression: ^[^@]+@(test.com|email.com)$ Enter image description here

Enter image description here

How to fix this? Thanks.

asked a year ago252 views

1 Answer
0

Hi. Your regex looks fine and I gave it a quick test in my lab and it's blocking the correct email domains for me. I would suggest taking a systematic approach to rule out other issues, i.e. start with the setting for "How AWS WAF should handle the request if the JSON in the request body is invalid", and set that to "No Match" and see if the behaviour changes. Following that, try the same for the Oversize handling configuration. Failing that, I would guess that something else in the body of the request may be matching the regex - how complex/lage is the full body of the request?

AWS

answered a year ago

  • Thank you for looking into this. I have determined that my data was submitted from a <form>, so the original approach didn't work. I made a small update to my regex by adding email= (e.g., email=[^&]+@(test.com|example....)), and it worked.

  • Great! Glad you got it working.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.