Results 1 to 6 of 6

Thread: a safe comment form

  1. #1
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default a safe comment form

    Not sure if this is the right place for this question, but I am considering designing a comment page for my site. I could add limits to


    • disable or limit the size of images
    • limit and truncate the size of submitted content
    • another to prevent rapid submissions
    • diable the '<'
    • and record the user's ip address in case I need to block them


    Does that sound about right?

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    those are all good thoughts.

    instead of disabling the html elements, my suggestion is that you just escape them or replace them with their character code equivalent...
    Code:
    < character code is &lt;

  3. #3
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    I was planning on replacing < with its code equivalent, but I did not know you could escape it. What would the code for that look like? echo"\<img src='www.site.com/image.jpg>"; will still output an image.
    Last edited by james438; 09-15-2008 at 08:34 PM.

  4. #4
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    i meant escaping for all injection. Some are listed below

    strip_tags()
    htmlentities()
    mysql_real_escape_string()
    addslashes()

  5. #5
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    hehe, I have not used strip_tags() in so long I forgot all about that one thanks

  6. #6
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Instead of allowing HTML markup on my comment forms, I generally always only allow Markdown.

    Those that know how to use it are generally knowledgeable enough to know the purpose of HTML markup. Otherwise, I don't think HTML is really necessary (or safe) in comment forms.

    You've got a fairly comprehensive list of precautions you could take to ensure a safe form. You might also limit the number of links. Often spammers post somewhat coherent comments riddled with links. That gets into the realm of moderating/censoring content which you may/may not want to get into.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •