You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

advanced-security.asciidoc 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. ---
  2. title: Common Security Issues
  3. order: 8
  4. layout: page
  5. ---
  6. [[advanced.security]]
  7. = Common Security Issues
  8. [[advanced.security.sanitizing]]
  9. == Sanitizing User Input to Prevent Cross-Site Scripting
  10. You can put raw HTML content in many components, such as the [classname]#Label#
  11. and [classname]#CustomLayout#, as well as in tooltips and notifications. In such
  12. cases, you should make sure that if the content has any possibility to come from
  13. user input, you must make sure that the content is safe before displaying it.
  14. Otherwise, a malicious user can easily make a
  15. link:http://en.wikipedia.org/wiki/Cross-site_scripting[cross-site scripting
  16. attack] by injecting offensive JavaScript code in such components. See other
  17. sources for more information about cross-site scripting.
  18. Offensive code can easily be injected with [literal]#++<script>++# markup or in
  19. tag attributes as events, such as
  20. [parameter]#onLoad#.////
  21. TODO Consider an example, Alice, Bob,
  22. etc.
  23. ////
  24. Cross-site scripting vulnerabilities are browser dependent, depending on the
  25. situations in which different browsers execute scripting markup.
  26. Therefore, if the content created by one user is shown to other users, the
  27. content must be sanitized. There is no generic way to sanitize user input, as
  28. different applications can allow different kinds of input. Pruning (X)HTML tags
  29. out is somewhat simple, but some applications may need to allow (X)HTML content.
  30. It is therefore the responsibility of the application to sanitize the input.
  31. Character encoding can make sanitization more difficult, as offensive tags can
  32. be encoded so that they are not recognized by a sanitizer. This can be done, for
  33. example, with HTML character entities and with variable-width encodings such as
  34. UTF-8 or various CJK encodings, by abusing multiple representations of a
  35. character. Most trivially, you could input [literal]#++<++# and [literal]#++>++#
  36. with [literal]#++&lt;++# and [literal]#++&gt;++#, respectively. The input could
  37. also be malformed and the sanitizer must be able to interpret it exactly as the
  38. browser would, and different browsers can interpret malformed HTML and
  39. variable-width character encodings differently.
  40. Notice that the problem applies also to user input from a
  41. [classname]#RichTextArea# is transmitted as HTML from the browser to server-side
  42. and is not sanitized. As the entire purpose of the [classname]#RichTextArea#
  43. component is to allow input of formatted text, you can not just remove all HTML
  44. tags. Also many attributes, such as [parameter]#style#, should pass through the
  45. sanitization.