Jump to content

Blocking email injection, why wont this SIMPLE RegEx work?


gtzpower

Recommended Posts

can anyone help me with this simple RegEx test?

 

Here's my code:

	
if (eregi("(\r|\n)", $_POST['email'])) {
    	// block email injection attacks
   	die("An error has occurred.  Please verify that you have submitted a valid email address.");
} else {
echo $_POST['email'];
}

 

the resulting page shows \r\n (when I submit \r\n for the email address).  I can't get the die to execute!  However, if I do this:

if (eregi("(\r|\n)", "\r\n")) {   //Note the elimination of the POST var

 

the evaluation is true.  Any hints?

Link to comment
Share on other sites

still have the same issue even with that one.

 

I think it has something to do with the POST var holding a literal value.  For example, if I run:

	if($_POST['email'] == "\r\n")
{
	echo "dub";
}
if($_POST['email'] == '\r\n')
{
	echo "sin";
}

 

'sin' is echoed.  So, my "" around the regEx is looking for a whitespace character of carriage return\new line, while I am giving it the literal of '\r\n'.  I still don't know how to get around this though :(

Link to comment
Share on other sites

Thanks!  That works for \r or \n, but unfortunately it won't work for %0A, etc..  I guess what I am really asking is why is it that the regular expressions for testing this stuff that I can find on umpteen billion sites are not working on mine?  Is there a php setting for post vars that needs changed or something?  I would ideally like to search for the whitespace character rather than searching for every possible way of creating the whitespace character

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.