CVE-2022-22947: SpEL Casting And Evil Beans
The Spring Cloud Gateway actuator allowed unsafe SpEL expressions in route filters, leading to remote code execution. An attacker could create a route with a malicious expression and trigger its evaluation by refreshing the gateway, executing arbitrary OS commands.
Published on web.archive.org
During my analysis of the Spring Cloud Gateway Server jar, which can be used to enable the gateway actuator, I had identified that SpEL was in use. This in itself isn’t necessarily bad, however unsafe input shouldn’t flow to an expression parsed with a StandardEvaluationContext.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
The application used a StandardEvaluationContext to evaluate user-supplied SpEL expressions in route filter arguments, allowing arbitrary method invocation and code execution.
Impact
An attacker could execute arbitrary OS commands on the server, leading to full compromise; the text also notes a denial-of-service via a bean method even after a partial fix.
What the attacker needed
Gateway actuator endpoint exposed; no authentication on actuator
The fix
The fix switched to SimpleEvaluationContext with a restrictive property accessor that maps method calls and variables to null by default, though the text notes a denial-of-service remains if the restrictive accessor is disabled.
How it was found
- Send a POST request to /actuator/gateway/routes/new_route with a JSON body defining a route that includes a RewritePath filter with a SpEL expression in its argument.
- Send a POST request to /actuator/gateway/refresh to force the gateway to reload its configuration.
- The SpEL expression is evaluated during the reload, executing the embedded command.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
Spring Cloud Gateway is a tool that routes web traffic. It had a feature where administrators could add routing rules via a web endpoint. The rules could contain special expressions that the server would evaluate. Because the server used a powerful expression evaluator, an attacker could sneak in code that runs on the server, taking control of it.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.