Question

I am trying to figure out how to encrypt the viewstate using JSF 1.2 and Mojarra. The odd thing is that it seems to be encrypted by default on some servers, but not on others. For example, on my localhost I see the following:

<input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="-40233784603124937:-3413182513789758151" autocomplete="off" />

But on our Test environment servers I get:

<input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="j_id4:j_id5" />

You'll notice two differences between those two:

  1. The first has autocomplete="off"
  2. The first has the viewState value encrypted, whereas the second does not

The problem is that I cannot figure out for the life of me why the two are different. The codebase is the same on my localhost as on the server. There are no configuration options specified in my web.xml, so I would have assumed that my localhost would not be encrypted (as that is the default, right?).

Per the Mojarra documentation I should add:

<env-entry>
 <env-entry-name>com.sun.faces.ClientStateSavingPassword</env-entry-name>
 <env-entry-type>java.lang.String</env-entry-type>
 <env-entry-value>[SOME VALUE]</env-entry-value>
</env-entry>

But that seems to be specifically for client state saving, not server side state saving. And unless I'm misunderstanding things, I'm using server side state saving (at least, I can't find anywhere that we have configured javax.faces.STATE_SAVING_METHOD.

So, my questions:

  1. Why would my configuration be different between localhost and the server? Is there somewhere else options could be specified other than web.xml?
  2. How do I enable viewState encryption (like on my localhost) on all our servers?

Configuration:

  • Jboss 5.1.0.GA
  • Mojarra 1.2_12-b01-FCS
  • Seam 2.2.0.GA
Was it helpful?

Solution

The autocomplete="off" in the view state hidden field was introduced in Mojarra 1.2_13 as per issue 1129. The different view state ID algorithm (which is less CSRF attack sensitive) was introduced in Mojarra 1.2_14 (I can't find the corresponding issue report, all I know is that it was specified for JSF 2.0 for the first time and later backported to Mojarra 1.2).

Given the symptoms, it look like that your test environment is actually running at least Mojarra 1.2_14. Align out your JSF versions. Mojarra 1.2 is currently already at 1.2_16. Note that JBoss ships by default with Mojarra bundled.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top