On March 30, 2022, a critical remote code execution (RCE) vulnerability was found in the Spring Framework. More specifically, it is part of the spring-beans
package, a transitive dependency in both spring-webmvc
and spring-webflux
. This vulnerability is another example of why securing the software supply chain is important to open source.
Security resources like Lunasec, Rapid7 and Praetorian confirmed that the vulnerability is real, and in the meantime, Spring has already released a new version that mitigates this problem, so we recommend updating. While Spring4Shell does not appear to have the same impact as the recent Log4Shell vulnerability, it should still be evaluated and prioritized by every organization using the Spring Framework. In this post, we’ll explore how the RCE works.
Explaining Spring4Shell
If we have a controller with a request mapping loaded into memory, we are already vulnerable to this issue. Below, you see our GreetingController
with a PostMapping
to /greeting
. When we call our application in, for instance, Tomcat at https://mydomain/myapp/greeting
it tries to transform the input to a POJO (Plain Old Java Object) which, in our case, is the Greeting
object.
@Controller public class GreetingController { @PostMapping("/greeting") public String greetingSubmit(@ModelAttribute Greeting greeting, Model model) { model.addAttribute("greeting", greeting); return "result"; } }
However, because Spring uses serialization under the hood to map these values to the Java object, it is possible to also set other values. After some exploration, it turns out that you are able to set the properties of a class. This is interesting if you run on Tomcat.
...