Cross site scripting
- Exploit Methods:
- Reflected
- Persistent
- DOM Based + JSON + JQuery
- Data URI – MS WORD
- Hijack links(Script to to turn the links to open WORD document which ll be download to user machine and use user's machine.)
- Dangling Markup –Script less attack
- The attacker injects some URL to the database wit out closing tag. When the page is bound the HTML DOM all are sent to the URL that attacker has out on. In MVC, the attacker can now take the "Request Verification Token" too.
- Solutions:
- Use HTML Encode for Cross site scripting
- Avail user inputs to use tags and use regex to a-z only
- Json.Encode() or Encoder.JavaScriptEncoder() all data supplied to Java script
- Still vulnerable if the text is read from element and used incorrectly
- Audit everywhere where ever the DOM created/altered by user input
- Do not Encode the data to save in database, but Sanitized. Since the data is leading double encoding.
- Use Sanitizer. AntiXss Sanitizer's GetSafeHtml()/GetSafeHtmlFragmant()
- Specify Page Encoding in web.config
- Content Security Policies( Will not allow inline JS and scripts from other websites)
- Response.AddHeader("X-Content-Security-Policy","default-src 'self'");
- Response.AddHeader("X-WebKit-CSP","default-src 'self'");
- Do not expect blacklist to work.
- Consider removing all data: from all stored URIs to exclude data.
- Only allow local urls redirects that starts with "/uri"
- Audit every location data is assigned, ouput and lot of outputs affected by user.
- Ensure it is not used in java script or highly sanitized
- Know your control behavior
- Asp.net Textbox HTMLEncodes, Label does not.
- Test by injecting script. Use fiddler to inspect the behavior
- Be concerned with any place that DOM elements are created/modified
- Use functions such as SetAttribute() and var x= document.CreateElement('div'); rather than document.WriteLine, $(x).html(), element.InnerHtml, eval
- Deprecate IE6 (use IE upgrade redirect)
- Don't turn off (EnableRequestValidation or ValidateRequest)
- MVC apps use [AllowHtml], WebForms more difficult
Comments
Post a Comment