Remember to use HtmlEncode

by Codewiz51 July 03, 2009 15:03

It's easy to forget about conditioning data when you are in the midst of getting a product out the door.  This is particularly true of web projects.  Even Intranet web sites get hacked.

The moral is, don't forget to condition input text.  One of the easiest steps you can take is using HTMLEncode:

   // Don't do something like this before processing text.

   string body = this.Message.Text + "\n";

   // Instead, process the message to remove tags like < or >
   // with &lt; and &gt;  See msdn for a list of characters that are encoded.

   string body = Server.HtmlEncode(this.Message.Text + "\n");

This simple change might prevent someone from embedding script in a text control which might run amuck on your web server.

Comments are closed

Powered by BlogEngine.NET 1.6.0.0
Theme by Mads Kristensen | Modified by Mooglegiant


Disclaimer

This blog represents my personal hobby, observations and views. It does not represent the views of my employer, clients, especially my wife, children, in-laws, clergy, the dog, the cats or my daughter's horse. In fact, I am not even sure it represents my views when I take the time to reread postings.

All comments are moderated for content.

© Copyright 2008-2010