Jump to content

Recommended Posts

Hi!  Please help!

I am going round in circles trying to ensure that my web form is safe from spammers.  I have been researching the subject for some time, and am desperately searching for a simple solution which I suspect does not exist.  Currently I am using the following:

mail ("my_email_address", "Hardcoded subject", "$msg");

Therefore, I think that the only place where headers can be injected by spammers is within the $msg variable, which consists of the entries from several text fields within the form.  I am therefore considering stripping all colons ( : ) from $msg.  Will SMTP headers (e.g.: bcc:) work without the colon?  I have read about solutions using CATPCHAs and stripping line returns, but I would like to avoid using either of these solutions if possible (for accessibility and retaining email formatting respectively).

Any help will be gratefully accepted.  TIA.
Link to comment
https://forums.phpfreaks.com/topic/30376-header-injection-in-mail/
Share on other sites

I think he is referring to someone forcing additional mail headers...for example using his mail line from above:

[code]mail ("my_email_address", "Hardcoded subject", "$msg");[/code]

if the value of $msg is:

[code]Hi from your friend!!!", "-f somemail@address.com[/code]

When the mail is sent by the mail function it would appear to be from somemail@address.com, not from the mail server.
from my understanding, the spammers often use the fact that two line breaks indicates the end of the header. So they will input things such as and email then \r\n \r\n and then their message and it will ignore everything else after. So as part of my thing, I have a function

[code]
function nospam($string){
$string=str_splace("\n","",$string);
$string=str_splace("\r","",$string);
  return $string;
}
//I wrap all input in this
$email=nospam($_POST['email']);
$subject=nospam($_POST['subject']);

[/code]

Now I am not that much of an expert in spamming, or email header formats, this is just what I have read
http://www.jellyandcustard.com/2006/02/24/email-header-injection-in-php/
http://www.nyphp.org/phundamentals/email_header_injection.php
http://www.google.com/search?hl=en&lr=&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&q=PHP+prevent+email+header+injection&btnG=Search
[quote author=Crayon Violent link=topic=118333.msg483506#msg483506 date=1165951053]
wouldn't that remove all occurrances of \n\r, not just 2 occurrances of it?
[/quote]
Yes, but why would anyone ever need to submit any \r or \n in an email or subject field unless they are trying to cheat?
I personally use this function:

[code]<?php

function is_injection($text)
{
$regex = '(content\s*-\s*disposition)|(content\s*-\s*type)|(cc\:)|(content\s*-\s*transfer\s*-\s*encoding)|(mime\s*-\s*version)|(multipart\s*/\s*mixed)|(multipart\s*/\s*alternative)|(multipart\s*/\s*related)|(reply\s*-\s*to)|(x\s*-\s*mailer)|(x\s*-\s*sender)|(x\s*-\s*uidl)';

$text = strtolower($text);

if (eregi($regex,$text))
return true;
else
return false;
}

?>[/code]


Orio.
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.