Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6697537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:28:16+00:00 2026-05-26T06:28:16+00:00

I have a web application built on JSF with MySQL as DB. I have

  • 0

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 JSF, I guess I don’t have to handle XSS attack as it is already handled by UIComponent. I am not using any JavaScript in any of the view pages. Even if I use do I really need to implement code to prevent XSS attacks?

For DB we are using prepared statements and stored procedures in all DB interactions.

Is there anything else needs to be handled for preventing these 3 common attacks?
I have already been through the OWASP site and their cheat sheets.

Do I need to take care of any other potential attack vectors?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:28:17+00:00Added an answer on May 26, 2026 at 6:28 am

    XSS

    JSF is designed to have builtin XSS prevention. You can safely redisplay all user-controlled input (request headers (including cookies!), request parameters (also the ones which are saved in DB!) and request bodies (uploaded text files, etc)) using any JSF component.

    <h:outputText value="#{user.name}" />
    <h:outputText value="#{user.name}" escape="true" />
    <h:inputText value="#{user.name}" />
    etc...
    

    Note that when you’re using JSF 2.0 on Facelets, then you can use EL in template text like so:

    <p>Welcome, #{user.name}</p>
    

    This will also implicitly be escaped. You don’t necessarily need <h:outputText> here.

    Only when you’re explicitly unescaping user-controlled input using escape="false":

    <h:outputText value="#{user.name}" escape="false" />
    

    then you’ve a potential XSS attack hole!

    If you’d like to redisplay user-controlled input as HTML wherein you would like to allow only a specific subset of HTML tags like <b>, <i>, <u>, etc, then you need to sanitize the input by a whitelist. The HTML parser Jsoup is very helpful in this.

    itemLabelEscaped bug in Mojarra < 2.2.6

    Older Mojarra versions before 2.2.6 had the bug wherein <f:selectItems itemLabel> incorrectly renders the label unescaped when provided a List<T> via <f:selectItems var> instead of List<SelectItem> or SelectItem[] as value (issue 3143). In other words, if you’re redisplaying user-controlled data as item labels via a List<T>, then you’ve a potential XSS hole. If upgrading to at least Mojarra 2.2.6 is not an option, then you need to explicitly set itemLabelEscaped attribute to true to prevent that.

    <f:selectItems value="#{bean.entities}" var="entity" itemValue="#{entity}"
        itemLabel="#{entity.someUserControlledProperty}" itemLabelEscaped="true" />
    

    CSRF

    JSF 2.x has already builtin CSRF prevention in flavor of javax.faces.ViewState hidden field in the form when using server side state saving. In JSF 1.x this value was namely pretty weak and too easy predictable (it was actually never intended as CSRF prevention). In JSF 2.0 this has been improved by using a long and strong autogenerated value instead of a rather predictable sequence value and thus making it a robust CSRF prevention.

    In JSF 2.2 this is even be further improved by making it a required part of the JSF specification, along with a configurable AES key to encrypt the client side state, in case client side state saving is enabled. See also JSF spec issue 869 and Reusing ViewState value in other session (CSRF). New in JSF 2.2 is CSRF protection on GET requests by <protected-views>.

    Only when you’re using stateless views as in <f:view transient="true">, or there’s somewhere a XSS attack hole in the application, then you’ve a potential CSRF attack hole.


    SQL injection

    This is not JSF’s responsibility. How to prevent this depends on the persistence API you’re using (raw JDBC, modern JPA or good ol’ Hibernate), but all boils down that you should never concatenate user-controlled input into SQL strings like so

    String sql = "SELECT * FROM user WHERE username = '" + username + "' AND password = md5(" + password + ")";
    String jpql = "SELECT u FROM User u WHERE u.username = '" + username + "' AND u.password = md5('" + password + "')";
    

    Imagine what would happen if the enduser chooses the following name:

    x'; DROP TABLE user; --
    

    You should always use parameterized queries where applicable.

    String sql = "SELECT * FROM user WHERE username = ? AND password = md5(?)";
    String jpql = "SELECT u FROM User u WHERE u.username = ?1 AND u.password = md5(?2)";
    

    In plain JDBC you need to use PreparedStatement to fill the parameter values and in JPA (and Hibernate), the Query object offers setters for this as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web application built with jQuery Mobile and PHP (CodeIgniter framework). Now
All, I have a PHP Web application built using Zend Framework and MVC with
I have a PHP web application built with CodeIgniter MVC framework. I wish to
I have a web application built in the asp.net 2.0 MVC pattern. Now the
I have a Java Tomcat web application built in IntelliJ that calls code in
We have a web application that has been built using MySQL / PHP /
I have a web application built on ASP.NET MVC framework which requires a service
I have a web application built in Asp.net framework 3.5 (.Net 2008), and I
I'm early in development on a web application built in VS2008. I have both
We have built a web application that accepts SOAP messages, does some processing, calls

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.