views:

33

answers:

3

If I have fields that will only ever be displayed to the user that enters them, is there any reason to sanitize them against cross-site scripting?

Edit: So the consensus is clear, that it should be sanitized. What I'm trying to understand is why? If the only user that can ever view the script they insert into the site is the user himself, then the only thing he can do is execute the script himself, which he could already do without my site being involved. What's the threat vector here?

A: 

Yes, always sanitize user input:

  1. Never trust user input
  2. It does not take a lot of effort to do so.

The key point being 1.

ChristopheD
+1  A: 

Just because you don't display a field to someone, doesn't mean that a potential Black Hat doesn't know that they're there. If you have a potential attack vector in your system, plug the hole. It's going to be really hard to explain to your employer why you didn't if it's ever exploited.

A: 

If the script, or service, that the form submits the values to is available via the internet then anyone, anywhere, can write a script that will submit values to it. So: yes, sanitize all inputs received.

The most basic model of web-security is pretty simple:

Do not trust your users

It's also worth linking to my answer in another post (Steps to become web-security savvy): http://stackoverflow.com/questions/1704333/steps-to-become-web-security-savvy/1705146#1705146.

I can't believe I answered without referring to the title-question:

Is there any reason to sanitize user input to prevent them from cross site scripting themself?

You're not preventing the user's being cross-site scripted, you're protecting your site (or, more importantly, you're client's site) from being the victim of cross-site scripting. If you don't close known security holes because you couldn't be bothered it will become very hard to get repeat business. Or good word-of-mouth advertising and recommendation from previous clients.

Think of it less as protecting your client, think of it -if it helps- as protecting your business.

David Thomas