Results 1 to 7 of 7

Thread: What is cross-site scripting and how to avoid it?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2004
    Posts
    326

    Question What is cross-site scripting and how to avoid it?

    I haven't been able to find much about this topic so I thought I would ask.

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: What is cross-site scripting and how to avoid it?

    Basically it's when any visitor to your site can add some content (be it a guest book, message board, wiki, whatever) and JavaScript in that content gets executed. It allows the user to pretend to be your site while doing something malicious. The end user, trusting your site, may for example write credit card information, and the attacker, through the injected script, can intercept this information.

    To avoid it, you must make absolutely sure that you've properly validated and sanitized all user input.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2004
    Posts
    326

    Re: What is cross-site scripting and how to avoid it?

    How would you go about validating user input and striping out any potential malicious code?

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: What is cross-site scripting and how to avoid it?

    Depends on what the user input is. The simplest form is to just push it through htmlentities().
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: What is cross-site scripting and how to avoid it?

    A basic rule of thumb is to never directly reflect any input. Always process it first.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2004
    Posts
    326

    Re: What is cross-site scripting and how to avoid it?

    Thanks guys for your responses is there any code out there that you guys think is good for stripping out html and javascript?

  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: What is cross-site scripting and how to avoid it?

    You shouldn't try to strip out HTML and JS like that, it's too troublesome. Just use htmlentities() like CB suggested and angle brackets (among other things) will be converted to < and > so that they are not parsed as code.

Posting Permissions

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



Click Here to Expand Forum to Full Width