Improper Privilege Management in Grails Spring Security Core <= 5.1.0 CVE202241923
The Grails Spring Security Core plugin incorrectly parsed request URIs by stripping everything after the first semicolon, so an authenticated low-privileged user could bypass role requirements by inserting a semicolon in the path. This allowed access to restricted controller actions that should have required higher privileges.
Published on synacktiv.com
Improper Privilege Management in Grails Spring Security Core <= 5.1.0 CVE-2022-41923 2023.03.21
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.
Context
Grails is an open source web framework built on the Groovy programming language and supported by the Grails Foundation. Its core is highly extensible, and a large ecosystem of plugins adds features on top of it. One of those plugins, Grails Spring Security Core, integrates Spring Security into Grails applications and provides default configuration with many options for customisation. Nearly everything in the plugin, and in Spring Security itself, is configurable or replaceable, which is possible because Spring Security makes extensive use of interfaces.
The plugin lets an application developer attach role requirements to each web application controller. Synacktiv found that the plugin parsed resource URIs improperly in its authorization system, which allowed an authenticated user to bypass some applications' authorization requirements. The issue is tracked as CVE-2022-41923 and affects Grails Spring Security Core up to and including 5.1.0.
Setup
The demonstration uses a small Grails application with two roles, ROLE_USER and ROLE_ADMIN, corresponding to two different levels of privilege. A SecureController exposes a /secure path that routes to the default index action and requires ROLE_USER, and a /secure/admin path that requires ROLE_ADMIN:
$ cat SecureController.groovy
@Secured('ROLE_USER')
class SecureController {
def index() {
render 'User access only'
}
@Secured('ROLE_ADMIN')
def admin() {
render 'Admin access only'
}
}
The tests are made with curl against a local instance on port 8080, authenticated with a JSESSIONID session cookie. The fixed version used to confirm the patch is 5.1.1.
Finding it
With a session authenticated as ROLE_USER, a request to the admin page is correctly denied:
$ curl -i http://localhost:8080/secure/admin -H 'Cookie: JSESSIONID=[...]'
HTTP/1.1 403
<div class="errors">Sorry, you're not authorized to view this page.</div>
However, inserting a semicolon (;) at a specific position in the path allows access to the restricted page, bypassing the role requirement:
$ curl -i 'http://localhost:8080/secure;/admin' -H 'Cookie: JSESSIONID=[...]'
HTTP/1.1 200
[...]
Admin access only
The semicolon before the /admin endpoint caused the endpoint's authorization requirements to be bypassed, and the request instead inherited the ROLE_USER requirement configured for the /secure endpoint.
Exploitation
Step 1: confirm the baseline denial
Request the restricted action with a low-privileged session. The plugin evaluates the URI against the configured role requirements and returns 403 with the message Sorry, you're not authorized to view this page. This establishes that the ROLE_ADMIN requirement on /secure/admin is enforced normally.
Step 2: insert a semicolon before the restricted segment
Send the same request with the path /secure;/admin:
$ curl -i 'http://localhost:8080/secure;/admin' -H 'Cookie: JSESSIONID=[...]'
HTTP/1.1 200
[...]
Admin access only
The server returns 200 and the content of the admin action. The plugin only applied the authorization rule of the first part of the URI (/secure, which requires ROLE_USER) while the Grails Framework still served the privileged /secure;/admin page.
Root cause
When used with some containers, the request URL received by the Grails Framework may include a semicolon to pass the jsessionid parameter, for example:
http://mywebsite.com/context/foo;jsessionid=A3294FBE42?a=b
This notation is called Matrix Parameters. A Matrix URI is written using semicolons to delimit the path resources:
/context/foo;f1=WWW/bar;s1=1;s2=2/index.html;i1=1;i2=2
The top-level resource may contain parameters that do not apply to the sub-level resources. To handle the case where a container passes the jsessionid parameter, the plugin stripped everything after the first semicolon when extracting the context path of the request:
File: plugin/src/main/groovy/grails/plugin/springsecurity/web/access/intercept/ AbstractFilterInvocationDefinition.groovy@77132c1
176: protected String calculateUri(HttpServletRequest request) {
177: String url = request.requestURI.substring(request.contextPath.length())
178: int semicolonIndex = url.indexOf(';')
179: semicolonIndex == -1 ? url : url.substring(0, semicolonIndex)
180: }
The resulting url variable is then used to decide whether the user has the right to access it. When an attacker includes a semicolon in the request's path, the controller authorization therefore applies only to the first part of the URI instead of the whole path. A request to /secure;/admin is parsed by the plugin as a request to /secure, which in this application is configured to be accessible by an unprivileged user, while the Grails Framework itself serves the privileged /secure;/admin page. The plugin therefore evaluates only the first part of the URI when deciding access.
Impact
An attacker with a valid, low-privileged account on a web application using the plugin could use this vulnerability to bypass its privilege requirements. Exploiting it grants the user access to all methods of a given controller, provided that they are authorised to access the controller's default action endpoint, which by default is the index action. The bypass therefore depends on the attacker being authorised to access the controller's default action endpoint.
Fix
Upgrade to one of the following plugin versions: 3.3.2, 4.0.5 or 5.1.1. The affected versions are 1.x, 2.x, >=3.0.0 <3.3.2, >=4.0.0 <4.0.5 and >=5.0.0 <5.1.1.
The patches were committed on the following dates and included in the corresponding releases:
| Date | Release | Commit |
|---|---|---|
| 11/10/2022 | 5.1.1 | https://github.com/grails/grails-spring-security-core/pull/806/commits/[redacted] |
| 11/13/2022 | 4.0.5 | https://github.com/grails/grails-spring-security-core/pull/824/commits/[redacted] |
| 11/17/2022 | 3.3.2 | https://github.com/grails/grails-spring-security-core/pull/837/commits/[redacted] |
The code now uses the getRequestUri method of the urlPathHelper class from the Spring Framework library:
File: plugin/src/main/groovy/grails/plugin/springsecurity/web/access/intercept/ AbstractFilterInvocationDefinition.groovy@890ebac
18: import org.springframework.web.util.UrlPathHelper
[...]
96: protected String determineUrl(FilterInvocation filterInvocation) {
97: final HttpServletRequest request = filterInvocation.request
98: lowercaseAndStripQuerystring stripContextPath(urlPathHelper.getRequestUri(request), request)
99: }
That method states in its documentation that "some containers [...] include ";" strings like ";jsessionid" in the URI. This method cuts off such incorrect appendices." Reproducing the earlier request against version 5.1.1 confirms the fix:
$ curl -i 'http://localhost:8080/secure;/admin' -H 'Cookie: JSESSIONID=[...]'
HTTP/1.1 403
[...]
<div class="errors">Sorry, you're not authorized to view this page.</div>
Timeline
| Date | Description |
|---|---|
| 2022.11 | Advisory sent to Grails Foundation |
| 2022.11.10 | Patches deployed on GitHub.com |
| 2022.11.22 | Advisory published on the Grails Framework blog: https://grails.org/blog/2022-11-22-ss-plugin-auth-cve.html |
| 2023.03.21 | Public release |
- Semicolon before a restricted path segment. On an application where a controller's default action is reachable by a low-privileged role, request a privileged action as
/controller;/privileged-action. A positive result is a200with the privileged content where the plain path returns403. - Semicolon with a matrix parameter. Try
/controller;jsessionid=anything/privileged-actionand/controller;x=1/privileged-action. A positive result is the same mismatch: the authorization layer evaluates only/controllerwhile the framework routes to the privileged action. - Other path-parsing delimiters. Where the authorization layer and the router disagree on how a URI is split, test encoded and unencoded separators in the same position. A positive result is any request that the authorization layer maps to a permitted URI but the framework maps to a restricted one.
- Different containers. The semicolon notation exists because some containers pass
jsessionidin the path. Test the same payloads behind different servlet containers to see whether the mismatch appears or disappears depending on how the container forwards the URI.
Synacktiv thanked the Grails Foundation team for their quick response to the vulnerability and their feedback for the advisory.
What happened, in plain words
A security company called Synacktiv found a bug in a piece of software that many web applications use to decide who is allowed to see what. The bug let a logged-in user with low privileges reach pages that were meant only for administrators, simply by putting a semicolon (;) in the right place in the web address. The problem was fixed in newer versions of the software, with patches deployed in November 2022. This article walks through what the software does, how the bug was found, why it worked, and how it was repaired, in the same order as the original advisory.
Background: what Grails and the plugin are
Grails is an open source web framework. A framework is a set of ready-made building blocks that programmers use to build a website or web application faster, instead of writing everything from scratch. Grails is built on the Groovy programming language and is supported by the Grails Foundation. Its core is designed to be extended: a large ecosystem of plugins adds features on top of it. A plugin is a small add-on package that plugs into a larger program, a bit like an extension you install in a browser.
One of those plugins is Grails Spring Security Core. It integrates Spring Security, a widely used security library, into Grails applications. It ships with sensible default settings and many options for customisation. Nearly everything in the plugin, and in Spring Security itself, can be configured or replaced, which is possible because Spring Security makes extensive use of interfaces. An interface, in programming, is a contract that says which operations a piece of code must offer, without saying how it does them; that is what makes swapping one implementation for another easy.
The plugin lets the developer of an application attach role requirements to each web application controller. A controller is the part of a web application that handles a particular group of pages or actions. A role is a label such as ROLE_USER or ROLE_ADMIN that says what level of privilege an account has. The plugin checks the role before letting a request reach a controller action.
Synacktiv found that the plugin parsed resource URIs improperly in its authorization system. A URI (Uniform Resource Identifier) is the technical name for the address of something on the web; in practice, for a website, it is the path part of the URL you type in the browser. Parsing means reading that address and breaking it into pieces the program can reason about. Because the plugin read the address incorrectly, an authenticated user could bypass some applications' authorization requirements. Authenticated means the user has logged in and has a valid session. The issue is tracked as CVE-2022-41923. A CVE is a public identifier assigned to a known security vulnerability so that people can refer to it unambiguously. The affected versions are Grails Spring Security Core up to and including 5.1.0.
The demonstration application
The demonstration uses a small Grails application with two roles, ROLE_USER and ROLE_ADMIN, corresponding to two different levels of privilege. A SecureController exposes a /secure path that routes to the default index action and requires ROLE_USER, and a /secure/admin path that requires ROLE_ADMIN:
$ cat SecureController.groovy
@Secured('ROLE_USER')
class SecureController {
def index() {
render 'User access only'
}
@Secured('ROLE_ADMIN')
def admin() {
render 'Admin access only'
}
}
Line by line:
$ cat SecureController.groovyis a shell command that prints the contents of a file.catis a standard command on Linux and macOS that shows a file's text. The$is the shell prompt, not part of the command.@Secured('ROLE_USER')is an annotation placed on the class. An annotation is a label attached to code that the framework reads at runtime. Here it says: to use anything in this controller, you must have theROLE_USERrole.class SecureController {starts the definition of the controller.def index() { render 'User access only' }defines the default action, calledindex. When someone visits/securewithout naming a specific action, this is what runs.rendersends text back to the browser, here the wordsUser access only.@Secured('ROLE_ADMIN')on theadminaction overrides the class-level rule for that one action: it now requiresROLE_ADMIN.def admin() { render 'Admin access only' }defines the privileged action, reachable at/secure/admin, which returns the wordsAdmin access only.
The tests are made with curl against a local instance on port 8080, authenticated with a JSESSIONID session cookie. curl is a command-line tool that sends HTTP requests, the same kind of requests a browser sends, and prints the response. A cookie is a small piece of data that a website asks the browser to store and send back on every subsequent request; a session cookie identifies the logged-in session, so the server knows who is asking. JSESSIONID is the conventional name Java web servers give to that session cookie. Port 8080 is simply the network port the local test server listens on. The fixed version used to confirm the patch is 5.1.1.
Finding the bug
With a session authenticated as ROLE_USER, a request to the admin page is correctly denied:
$ curl -i http://localhost:8080/secure/admin -H 'Cookie: JSESSIONID=[...]'
HTTP/1.1 403
<div class="errors">Sorry, you're not authorized to view this page.</div>
What each part does:
curl -isends a request and asks curl to include the response headers in the output. Headers are the metadata lines a server sends before the body, such as the status code.http://localhost:8080/secure/adminis the address being requested.localhostmeans this computer, and8080is the port.-H 'Cookie: JSESSIONID=[...]'adds a request header namedCookiecarrying the session identifier. The[...]stands for the actual value, which is a secret and is not shown.HTTP/1.1 403is the status line.403means forbidden: the server understood the request but refuses to authorise it.- The
<div class="errors">...</div>line is the HTML body the application returns, telling the user they are not authorised.
This step matters because it establishes the normal behaviour: the ROLE_ADMIN requirement on /secure/admin is enforced as intended.
However, inserting a semicolon (;) at a specific position in the path allows access to the restricted page, bypassing the role requirement:
$ curl -i 'http://localhost:8080/secure;/admin' -H 'Cookie: JSESSIONID=[...]'
HTTP/1.1 200
[...]
Admin access only
Here the only change is the address: /secure;/admin instead of /secure/admin. The single quotes around the address are there because the shell treats ; as a command separator; quoting tells the shell to pass the whole string to curl as one argument. The response is now 200, which means OK, and the body contains Admin access only. The [...] marks output that was omitted.
The semicolon before the /admin endpoint caused the endpoint's authorization requirements to be bypassed, and the request instead inherited the ROLE_USER requirement configured for the /secure endpoint. In other words, the security check looked only at the part before the semicolon, while the application still delivered the page after it.
Exploitation, step by step
Step 1: confirm the baseline denial
Request the restricted action with a low-privileged session. The plugin evaluates the URI against the configured role requirements and returns 403 with the message Sorry, you're not authorized to view this page. This establishes that the ROLE_ADMIN requirement on /secure/admin is enforced normally. Doing this first is good practice: you need to know what a correct refusal looks like before you can recognise a bypass.
Step 2: insert a semicolon before the restricted segment
Send the same request with the path /secure;/admin:
$ curl -i 'http://localhost:8080/secure;/admin' -H 'Cookie: JSESSIONID=[...]'
HTTP/1.1 200
[...]
Admin access only
The server returns 200 and the content of the admin action. The plugin only applied the authorization rule of the first part of the URI (/secure, which requires ROLE_USER) while the Grails Framework still served the privileged /secure;/admin page. The plugin evaluated only the part of the URI before the semicolon, while the Grails Framework served the privileged page.
Root cause
When used with some containers, the request URL received by the Grails Framework may include a semicolon to pass the jsessionid parameter, for example:
http://mywebsite.com/context/foo;jsessionid=A3294FBE42?a=b
A container, in this context, is the server software that runs the application and passes requests to it. Some containers have historically carried the session identifier inside the path, after a semicolon, rather than only in a cookie. This notation is called Matrix Parameters. A Matrix URI is written using semicolons to delimit the path resources:
/context/foo;f1=WWW/bar;s1=1;s2=2/index.html;i1=1;i2=2
In this example, foo, bar and index.html are path segments, and the ;name=value pieces after each one are parameters attached to that segment. The top-level resource may contain parameters that do not apply to the sub-level resources. The important point is that a semicolon is a legitimate part of a path, not a typo.
To handle the case where a container passes the jsessionid parameter, the plugin stripped everything after the first semicolon when extracting the context path of the request:
File: plugin/src/main/groovy/grails/plugin/springsecurity/web/access/intercept/ AbstractFilterInvocationDefinition.groovy@77132c1
176: protected String calculateUri(HttpServletRequest request) {
177: String url = request.requestURI.substring(request.contextPath.length())
178: int semicolonIndex = url.indexOf(';')
179: semicolonIndex == -1 ? url : url.substring(0, semicolonIndex)
180: }
Line by line:
- The
File:line names the source file and the commit identifier@77132c1, so a reader can find the exact code. protected String calculateUri(HttpServletRequest request) {declares a method that takes an incoming HTTP request and returns a string, the URI to check.HttpServletRequestis the object a Java web application uses to represent an incoming request.String url = request.requestURI.substring(request.contextPath.length())takes the full request URI and removes the leading context path, the prefix under which the application is deployed, leaving just the part inside the application.int semicolonIndex = url.indexOf(';')finds the position of the first semicolon in that string, or-1if there is none.semicolonIndex == -1 ? url : url.substring(0, semicolonIndex)is a conditional expression: if there is no semicolon, keep the whole string; otherwise keep only the part before the semicolon.
The resulting url variable is then used to decide whether the user has the right to access it. When an attacker includes a semicolon in the request's path, the controller authorization therefore applies only to the first part of the URI instead of the whole path. A request to /secure;/admin is parsed by the plugin as a request to /secure, which in this application is configured to be accessible by an unprivileged user, while the Grails Framework itself serves the privileged /secure;/admin page. The plugin therefore evaluates only the first part of the URI when deciding access. A useful comparison: it is as if a receptionist checks your badge for room 1 and waves you through, but the corridor behind them actually leads to room 1 and room 2, and nobody checks room 2.
Impact
An attacker with a valid, low-privileged account on a web application using the plugin could use this vulnerability to bypass its privilege requirements. Exploiting it grants the user access to all methods of a given controller, provided that they are authorised to access the controller's default action endpoint, which by default is the index action. The bypass therefore depends on the attacker being authorised to access the controller's default action endpoint.
Fix
Upgrade to one of the following plugin versions: 3.3.2, 4.0.5 or 5.1.1. The affected versions are 1.x, 2.x, >=3.0.0 <3.3.2, >=4.0.0 <4.0.5 and >=5.0.0 <5.1.1. The notation >=3.0.0 <3.3.2 means every version from 3.0.0 up to, but not including, 3.3.2.
The patches were committed on the following dates and included in the corresponding releases:
| Date | Release | Commit |
|---|---|---|
| 11/10/2022 | 5.1.1 | https://github.com/grails/grails-spring-security-core/pull/806/commits/[redacted] |
| 11/13/2022 | 4.0.5 | https://github.com/grails/grails-spring-security-core/pull/824/commits/[redacted] |
| 11/17/2022 | 3.3.2 | https://github.com/grails/grails-spring-security-core/pull/837/commits/[redacted] |
The code now uses the getRequestUri method of the urlPathHelper class from the Spring Framework library:
File: plugin/src/main/groovy/grails/plugin/springsecurity/web/access/intercept/ AbstractFilterInvocationDefinition.groovy@890ebac
18: import org.springframework.web.util.UrlPathHelper
[...]
96: protected String determineUrl(FilterInvocation filterInvocation) {
97: final HttpServletRequest request = filterInvocation.request
98: lowercaseAndStripQuerystring stripContextPath(urlPathHelper.getRequestUri(request), request)
99: }
Line by line:
import org.springframework.web.util.UrlPathHelperbrings in a helper class from Spring that already knows how to read request paths correctly. Reusing a well-tested helper is safer than writing the parsing by hand.- The
[...]marks lines that were left out of the excerpt. protected String determineUrl(FilterInvocation filterInvocation) {declares the method that decides which URL is being checked. AFilterInvocationis the object Spring Security uses to represent a request passing through a security filter.final HttpServletRequest request = filterInvocation.requestpulls the underlying HTTP request out of it.lowercaseAndStripQuerystring stripContextPath(urlPathHelper.getRequestUri(request), request)asks the helper for the request URI, removes the context path, and then lowercases and strips the query string. The helper handles the semicolon case correctly.
That method states in its documentation that "some containers [...] include ";" strings like ";jsessionid" in the URI. This method cuts off such incorrect appendices." Reproducing the earlier request against version 5.1.1 confirms the fix:
$ curl -i 'http://localhost:8080/secure;/admin' -H 'Cookie: JSESSIONID=[...]'
HTTP/1.1 403
[...]
<div class="errors">Sorry, you're not authorized to view this page.</div>
The same request that returned 200 and the admin page on the vulnerable version now returns 403 and the refusal message on the fixed version. The same request is now denied on the fixed version.
Timeline
| Date | Description |
|---|---|
| 2022.11 | Advisory sent to Grails Foundation |
| 2022.11.10 | Patches deployed on GitHub.com |
| 2022.11.22 | Advisory published on the Grails Framework blog: https://grails.org/blog/2022-11-22-ss-plugin-auth-cve.html |
| 2023.03.21 | Public release |
An advisory is the formal notice a security researcher sends to the maintainers of a product, describing the problem and how to fix it. The sequence shows the usual responsible disclosure pattern: the maintainers were told first, patches went out, a public notice followed, and the full write-up was released later.
If you maintain an application that uses this plugin, or a similar one, these are the cases worth checking. Each one is a way of asking the same question: does the security check and the router read the address the same way?
- Semicolon before a restricted path segment. On an application where a controller's default action is reachable by a low-privileged role, request a privileged action as
/controller;/privileged-action. A positive result is a200with the privileged content where the plain path returns403. - Semicolon with a matrix parameter. Try
/controller;jsessionid=anything/privileged-actionand/controller;x=1/privileged-action. A positive result is the same mismatch: the authorization layer evaluates only/controllerwhile the framework routes to the privileged action. - Other path-parsing delimiters. Where the authorization layer and the router disagree on how a URI is split, test encoded and unencoded separators in the same position. A positive result is any request that the authorization layer maps to a permitted URI but the framework maps to a restricted one.
- Different containers. The semicolon notation exists because some containers pass
jsessionidin the path. Test the same payloads behind different servlet containers to see whether the mismatch appears or disappears depending on how the container forwards the URI.
Synacktiv thanked the Grails Foundation team for their quick response to the vulnerability and their feedback for the advisory.
Glossary
- Advisory: a formal notice describing a security vulnerability, sent to the maintainers of the affected product and later published.
- Annotation: a label attached to code that a framework reads at runtime to change behaviour, such as
@Secured. - Authenticated: having logged in and holding a valid session, so the server knows who you are.
- Authorization: the decision about what an authenticated user is allowed to do.
- Bypass: getting past a check without satisfying it.
- Container: the server software that runs a web application and forwards requests to it.
- Context path: the prefix under which an application is deployed on a server, for example
/myapp. - Controller: the part of a web application that handles a group of related pages or actions.
- Cookie: a small piece of data a website asks the browser to store and send back on later requests.
- CVE: a public identifier assigned to a known security vulnerability.
curl: a command-line tool that sends HTTP requests and prints the responses.- Endpoint: a specific address an application responds to, such as
/secure/admin. - Framework: a set of ready-made building blocks programmers use to build an application faster.
- Grails: an open source web framework built on the Groovy programming language.
- Groovy: a programming language that runs on the Java platform and is used by Grails.
- Header: a metadata line sent with an HTTP request or response, such as
Cookieor the status code. - HTTP: the protocol browsers and servers use to exchange requests and responses.
- Interface: a contract stating which operations a piece of code must offer, without saying how.
JSESSIONID: the conventional name of the session cookie used by Java web servers.- Matrix Parameters: a way of attaching parameters to path segments using semicolons, as in
/foo;name=value. - Parsing: reading a string and breaking it into pieces a program can reason about.
- Plugin: an add-on package that plugs into a larger program to add features.
- Privilege: the level of access an account has, such as ordinary user or administrator.
- Role: a label such as
ROLE_USERorROLE_ADMINthat groups permissions. - Session: the server-side record of a logged-in user, identified by a cookie.
- Spring Security: a widely used Java security library that handles authentication and authorization.
- Status code: the three-digit number in an HTTP response, such as
200(OK) or403(forbidden). - URI: the technical name for the address of a resource on the web; in practice, the path part of a URL.
- URL: the address you type in a browser to reach a page.
- Vulnerability: a weakness in software that an attacker can exploit.