Solved

HTML encoding with MVC2?

Posted on 2010-09-24
6
800 Views
Last Modified: 2012-05-10
In the Nerd Dinner Chapter 1 I read "You should be careful to always HTML-encode any user-entered values to avoid HTML and JavaScript injection attacks"

Please explain how HTML encoding works and what tools are avilable.  Also, a simple example of what an HTML or JavaScript injection attack would be great.

Thanks,
newbieweb
0
Comment
Question by:newbieweb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 40

Assisted Solution

by:gurvinder372
gurvinder372 earned 150 total points
ID: 33752946
http://robin.mytechtip.com/2009/02/04/encode-decode-html-in-java/

see the thing is, if my response/request is having javascript in it, and my code is evaluating the string somewhere (say using eval() method), then it can possibly lead to security lapse and other surprising behaviors (hope you understood :))
http://www.w3schools.com/jsref/jsref_eval.asp
0
 

Author Comment

by:newbieweb
ID: 33752981
Is there any way you could give me a tiny example of bad HTML that gets "fixed" by some encoder?  I don't yet understand what an eval() method would look for or change to solve the problem.
0
 
LVL 40

Assisted Solution

by:gurvinder372
gurvinder372 earned 150 total points
ID: 33753013
0
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 20

Accepted Solution

by:
ChristoferDutz earned 350 total points
ID: 33753026
Encoding replaces any special characters with codes. This allows the user to send complex content using simple ASCII charset. For example there is URL-Encoding in which characters that are not allowed in URLs with codes ... " " --> "%20" (Spaces are replaced by "%20" ... the % sign indicates the beginning of a code followed by two chars defining the encoded value). Another conversion is the conversion of HTML entites (The "<" char is escaped by "<" (The & char indicating the beginning of a code and the ";" indicating the end of it).

By encoding a string, you can "disable" its meaning (In Xml for example the "<" and ">" signs are special as they indicate tags. By escaping them to "<" and ">" the browser can treat them as normal text.

This is where JavaScript injection can become dangerous: .. immagine you have a login screen and if the login fails you display "Login: {here comes the value you entered} invalid!" (You output the text entered in the response. If somebody enters "Paul" and the user was invalid then it outputs "Login: Paul invalid!" ... but if an evil person enters "Paul
0
 
LVL 20

Assisted Solution

by:ChristoferDutz
ChristoferDutz earned 350 total points
ID: 33753041
Grrrrr ... good example of escaping ;-) ... the sencance should be:
"By encoding a string, you can "disable" its meaning (In Xml for example the "<" and ">" signs are special as they indicate tags. By escaping them to "& l t ;" and "& g t ;" the browser can treat them as normal text."
0
 

Author Closing Comment

by:newbieweb
ID: 33753079
Thanks. That helps.
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question