Encoded URIs can access WEB-INF directory in Eclipse Jetty
Moderate severity
GitHub Reviewed
Published
Jul 15, 2021
in
jetty/jetty.project
•
Updated Jan 27, 2023
Package
Affected versions
>= 9.4.37, < 9.4.43
>= 10.0.1, < 10.0.6
>= 11.0.1, < 11.0.6
Patched versions
9.4.43
10.0.6
11.0.6
Description
Published by the National Vulnerability Database
Jul 15, 2021
Reviewed
Jul 15, 2021
Published to the GitHub Advisory Database
Jul 19, 2021
Last updated
Jan 27, 2023
Description
URIs can be crafted using some encoded characters to access the content of the
WEB-INF
directory and/or bypass some security constraints.This is a variation of the vulnerability reported in CVE-2021-28164/GHSA-v7ff-8wcx-gmc5.
Impact
The default compliance mode allows requests with URIs that contain a %u002e segment to access protected resources within the WEB-INF directory. For example, a request to
/%u002e/WEB-INF/web.xml
can retrieve the web.xml file. This can reveal sensitive information regarding the implementation of a web application. Similarly, an encoded null character can prevent correct normalization so that /.%00/WEB-INF/web.xml cal also retrieve the web.xml file.Workarounds
Some Jetty rewrite rules can be deployed to rewrite any request containing encoded dot segments or null characters in the raw request URI, to a known not found resource:
Analysis
Prior to 9.4.37, Jetty was protected from this style of attack by two lines of defense:
.
and..
sequences. Whilst this is not according to the RFC, it did remove relative segments that were encoded or parameterized and made the resulting URI paths safe from any repeated normalization (often done by URI manipulation and file system mapping).FileResource
class treated any difference between absolute path and canonical path of a resource as an alias, and thus the resource would not be served by default.Prior to 9.4.37, the
FileResource
class was replaced by thePathResource
class that did not treat normalization differences as aliases. Then release 9.4.37 updated the URI parsing to be compliant with the RFC, in that normalization is done before decoding. This allowed various encodings or adornments to relative path segments that would not be normalized by the pure RFC URI normalization, but were normalized by the file system, thus allowing protected resources to be accessed via an alias. Specifically by decoding URIs after normalization, it left them vulnerable to any subsequent normalization (potentially after checking security constraints) changing the URI singificantly. Such extra normalization is often down by URI manipulation code and file systems.With Jetty releases 9.4.43, 10.0.6, 11.0.6, we have restored several lines of defense:
ContextHandler.getResource(String path)
method always checks that the passed path is normalized, only accepting a non normal path if approved by an AliasChecker. This is the method that is directly used by Jetty resource serving.ServletContext.getResource(String path)
will normalize the prior to callingContextHandler.getResource(String path)
. This allows applications to use non normal paths.PathResource
class now considers any difference in normal/canonical name between a request resource name and the found resource name to be an alias, which will only be served if approved by an explicitAliasChecker
In summary, the defense is a front line of detection of specific known URI alias attacks, with the last line defense of not allowing any aliasing of resources.
Many thanks to @cangqingzhe from @CloverSecLabs for reporting this issue.
References