CSRF, XSS and SQL Injection attack prevention in JSF

前端 未结 3 1387
天涯浪人
天涯浪人 2020-11-22 01:44

I have a web application built on JSF with MySQL as DB. I have already implemented the code to prevent CSRF in my application.

Now since my underlying framework is J

3条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 02:32

    I am not using any JavaScript in any of the view pages. Even if I use do I really need to implement code to bypass XSS Attack.

    You can be vulnerable to XSS even if you don't use JavaScript in your pages. XSS occurs when you incorporate content controlled by an attacker without properly encoding it.

    Anytime you do something like

    response.write("" + x + "")
    

    where an attacker can cause x to contain HTML that contains JavaScript, then you are vulnerable to XSS.

    The solution is usually not to write large amounts of code. Typically the solution is to encode $x and any other values controlled by an attacker before including them in the HTML you generate.

    response.write("" + escapePlainTextToHtml(x) + "")
    

    Filtering or sanitizing inputs can help provide an additional layer of protection.

    You can also use a template language that encodes output automatically to protect against XSS.

    Closure Template is one such option for Java.

    Contextual autoescaping works by augmenting Closure Templates to properly encode each dynamic value based on the context in which it appears, thus defending against XSS vulnerabilities in values that are controlled by an attacker.

    EDIT

    Since you are using JSF you should read up on XSS mitigation in JSF:

    Escape output text

    and by default has the escape attribute set to True. By using this tag to display outputs, you are able to mitigate majority of the XSS vulnerability.

    SeamTextParser and

    If you would like to allow users to utilise some of the basic html tags to customise their inputs, JBoss Seam provides a tag that allows some basic html tags and styles specified by users.

提交回复
热议问题