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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 [parameter]#onLoad#.
  20. // TODO Consider an example, Alice, Bob, etc.
  21. Cross-site scripting vulnerabilities are browser dependent, depending on the
  22. situations in which different browsers execute scripting markup.
  23. Therefore, if the content created by one user is shown to other users, the
  24. content must be sanitized. There is no generic way to sanitize user input, as
  25. different applications can allow different kinds of input. Pruning (X)HTML tags
  26. out is somewhat simple, but some applications may need to allow (X)HTML content.
  27. It is therefore the responsibility of the application to sanitize the input.
  28. Character encoding can make sanitization more difficult, as offensive tags can
  29. be encoded so that they are not recognized by a sanitizer. This can be done, for
  30. example, with HTML character entities and with variable-width encodings such as
  31. UTF-8 or various CJK encodings, by abusing multiple representations of a
  32. character. Most trivially, you could input [literal]#++<++# and [literal]#++>++#
  33. with [literal]#++&lt;++# and [literal]#++&gt;++#, respectively. The input could
  34. also be malformed and the sanitizer must be able to interpret it exactly as the
  35. browser would, and different browsers can interpret malformed HTML and
  36. variable-width character encodings differently.
  37. Notice that the problem applies also to user input from a
  38. [classname]#RichTextArea# is transmitted as HTML from the browser to server-side
  39. and is not sanitized. As the entire purpose of the [classname]#RichTextArea#
  40. component is to allow input of formatted text, you can not just remove all HTML
  41. tags. Also many attributes, such as [parameter]#style#, should pass through the
  42. sanitization.