tags:

views:

96

answers:

6

When a user enters a web url in a comment, that url becomes a link.

How do I prevent attacks from those links? any measures I can take?

thanx

+3  A: 

There is nothing you can do except moderation. There is no way for a computer to determine if a link is sane or not. You can check against blacklists, you can check for some words in the domain, but other than that there's not much you can do, sorry...

Franz
P.S.: You could disallow links ;)
Franz
This is true, there is no system that absolutely filters out everything, but you can at least put measures in place to slow down the majority of the problems. It's like putting in a fence to keep burglars out: it wont stop all burglars, but it will stop a midget burglar.
Jeremy Morgan
+2  A: 
  1. You can write your own filtering system that flags posts based on spam words, and checks links for spam or adult related stuff

  2. Use a 3rd party tool like Aksimet that checks for you

  3. Use a moderation system so that any post with a link has to be approved by you.

  4. All of the above. You could even throw a CAPTCHA in there as well to slow down bots.

Jeremy Morgan
+1  A: 

don't allow link tags in comments? use the php strip_tagsfunction to remove html tags from submitted comments (you can add a list of tags that are allowed to the function, too).

Zenon
+1  A: 

You could use a blacklist (which is not going to catch most things), a whitelist (which is going to block most non-harmful links), or a redirect screen that warns the user "Don't be an idiot, this link might be malicious" (which doesn't prevent the links, but lets you say you warned the user and it's their own fault). Pick your poison.

Brian Schroth
+1  A: 

This will sanitize your URL locally but will have zero impact on malicious external sites if the user clicks the link:

$url = "http://www.mytesturl.com";
$url = filter_var($var, FILTER_SANITIZE_URL);

The filter will remove all characters, except letters, digits and $-.+!'(),{}|\\^~[]`<>#%";/?:@&=

cballou
A: 

Check out mollom.com, this 3rd-party service will prompt the user for CAPTCHA only if it appears as spam.

jwhat