Tel Map


PrimeFaces Expression Language Remote Code Execution Fix

This post describes how to fix the PrimeFaces Expression Language Remote Code Execution bug (CVE-2017-1000486) when an update to the latest / fixed PrimeFaces version is not easily possible. This solution also needs no patching of the PrimeFaces library itself.

The preferred / advised solution for fixing the issue is of course to do the update. The bug was already fixed over a year ago. However, only recently (beginning of 2018), more details and public exploits for this vulnerability have been published.


In one of our projects we build a set of own components with custom design based on Primefaces. An update to the latest version would have taken a couple of weeks to implement. Therefore we needed an easy quick solution to fix this vulnerability. We also could not use the solution described in the article above (disabling dynamic content), because we rely on that functionality.

The examples in this article are based on PrimeFaces 4, but can also be applied to later versions.


PrimeFaces uses links like below to load dynamic resources.

The problem here is the GET parameter pfdrid

This is an encrypted Expression Language value.  When PrimeFaces receives this, it will be decrypted and executed. There is no check what value expression is in there and unfortunately the encryption password is hardcoded into PrimeFaces.

So if you construct a value expression shellcode and encrypt it with the hardcoded password and pass it via this parameter it will be executed on the server.

How to fix this

Step 1: Change the hardcoded password

The password for the encryption / decryption can be set via a configuration property in the web.xml.

Since the attacker does not know this new password, he cannot correctly encrypt arbitrary expression language values, so that they will be executed on the server.

Remarks: The fix described here only works for closed source projects. Everyone who knows the new password, still is able to execute arbitrary code. Luckily for us, this was no problem.

Step 2: Fixing the Padding Oracle

Even when the attacker does not know the encryption password, there still is a problem. PrimeFaces is vulnerable to a so called padding oracle attack.

The short version…

Many cryptographic algorithms use fixed size blocks for encryption. If the text is not of that exact size the last block is “filled” with additional bytes (padded).

If you change specific bytes in the vulnerable parameter, in my example, sometimes the result will be an empty page, but other times result in the following exception and therefore in an Internal Server Error page.

javax.crypto.BadPaddingException: Given final block not properly padded

These 2 different responses are enough to decrypt the parameter and even re-encrypt new expression language values by doing a couple of thousand requests to the server.

For more information see:


To demo this i will use a tool called padbuster. This tool can decrypt and re-encrypt parmeters like described above without knowing the password.

First parameter is the url, second parameter the value to attack, third the block size.


The important thing here is that padbuster detected, that there are 2 different responses from the server by changing the encrypted parameter (Status 500 internal server error, status code 200 empty response).

If you continue this:

It will not be able to decrypt the first block since PrimeFaces also uses an initialization vector for the encryption, but this can be broken as well. I won’t go into how to do this here.

The same way new expression language values can be encrypted using this tool without knowing the encryption password.

So in order to fix this, we must make sure, the server response is the same when nothing can be decrypted or if the padding is incorrect.

Implementing a Custom ResourceHandlerWrapper

Adding the new ResourceHandlerWrapper to faces-config.xml

Unfortunately we cannot catch the BadPaddingException in the handler, because it is internally caught in PrimeFaces. Therefore we unfortunately have to catch IOException. You can adjust this to your needs if you need more fine-grained control over error handling here.

So after putting this new resource handler in, let’s take a look at the output of Padbuster again:

As you can see, all response are the same now and padbuster cannot attack the padding oracle vulnerability any more 🙂

So since we changed the password and we fixed the padding oracle, this vulnerability is not exploitable any more.

Hope this article helps to understand this vulnerability and maybe saves someone from actually having to update to a newer PrimeFaces version (but only if this is no option for you).

If you have any questions or comments please leave a message below.




Leave a Reply

Your email address will not be published. Required fields are marked *