CVE-2020-27216: Race Condition
Impact On Unix like systems, the system's temporary directory is shared between all users on that system. A collocated user can observe the process of creating a temporary sub directory in the shared temporary directory and race to complete the creation of the temporary subdirectory. If the attacker wins the race then they will have read and write permission to the subdirectory used to unpack web applications, including their WEB-INF/lib jar files and JSP files. If any code is ever executed out of this temporary directory, this can lead to a local privilege escalation vulnerability.
Additionally, any user code uses of WebAppContext::getTempDirectory) would similarly be vulnerable.
Additionally, any user application code using the ServletContext attribute for the tempdir will also be impacted. See: https://javaee.github.io/javaee-spec/javadocs/javax/servlet/ServletContext.html#TEMPDIR
For example: java import java.io.File; import java.io.IOException; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;
public class ExampleServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { File tempDir = (File)getServletContext().getAttribute(ServletContext.TEMPDIR); // Potentially compromised // do something with that temp dir } }
Example: The JSP library itself will use the container temp directory for compiling the JSP source into Java classes before executing them.
CVSSv3.1 Evaluation
This vulnerability has been calculated to have a CVSSv3.1 score of 7.8/10 (AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H)
Patches Fixes were applied to the 9.4.x branch with: - https://github.com/eclipse/jetty.project/commit/53e0e0e9b25a6309bf24ee3b10984f4145701edb - https://github.com/eclipse/jetty.project/commit/9ad6beb80543b392c91653f6bfce233fc75b9d5f
These will be included in releases: 9.4.33, 10.0.0.beta3, 11.0.0.beta3
Workarounds
A work around is to set a temporary directory, either for the server or the context, to a directory outside of the shared temporary file system. For recent releases, a temporary directory can be created simple by creating a directory called work in the ${jetty.base} directory (the parent directory of the webapps directory). Alternately the java temporary directory can be set with the System Property java.io.tmpdir. A more detailed description of how jetty selects a temporary directory is below.
The Jetty search order for finding a temporary directory is as follows:
1. If the WebAppContext has a temp directory specified), use it. 2. If the ServletContext has the javax.servlet.context.tempdir attribute set, and if directory exists, use it. 3. If a ${jetty.base}/work directory exists, use it (since Jetty 9.1) 4. If a ServletContext has the org.eclipse.jetty.webapp.basetempdir attribute set, and if the directory exists, use it. 5. Use System.getProperty("java.io.tmpdir") and use it.
Jetty will end traversal at the first successful step. To mitigate this vulnerability the directory must be set to one that is not writable by an attacker. To avoid information leakage, the directory should also not be readable by an attacker.
Setting a Jetty server temporary directory.
Choices 3 and 5 apply to the server level, and will impact all deployed webapps on the server.
For choice 3 just create that work directory underneath your ${jetty.base} and restart Jetty.
For choice 5, just specify your own java.io.tmpdir when you start the JVM for Jetty.
shell [jetty-distribution]$ java -Djava.io.tmpdir=/var/web/work -jar start.jar
Setting a Context specific temporary directory.
The rest of the choices require you to configure the context for that deployed webapp (seen as ${jetty.base}/webapps/<context>.xml)
Example (excluding the DTD which is version specific):
xml <Configure class="org.eclipse.jetty.webapp.WebAppContext"> <Set name="contextPath"><Property name="foo"/></Set> <Set name="war">/var/web/webapps/foo.war</Set> <Set name="tempDirectory">/var/web/work/foo</Set> </Configure>
References - https://github.com/eclipse/jetty.project/issues/5451 - CWE-378: Creation of Temporary File With Insecure Permissions - CWE-379: Creation of Temporary File in Directory with Insecure Permissions - CodeQL Query PR To Detect Similar Vulnerabilities
Similar Vulnerabilities
Similar, but not the same.
- JUnit 4 - https://github.com/junit-team/junit4/security/advisories/GHSA-269g-pwp5-87pp - Google Guava - https://github.com/google/guava/issues/4011 - Apache Ant - https://nvd.nist.gov/vuln/detail/CVE-2020-1945 - JetBrains Kotlin Compiler - https://nvd.nist.gov/vuln/detail/CVE-2020-15824
For more information
The original report of this vulnerability is below:
> On Thu, 15 Oct 2020 at 21:14, Jonathan Leitschuh <jonathan.leitschuh@gmail.com> wrote: > Hi WebTide Security Team, > > I'm a security researcher writing some custom CodeQL queries to find Local Temporary Directory Hijacking Vulnerabilities. One of my queries flagged an issue in Jetty. > > https://lgtm.com/query/5615014766184643449/ > > I've recently been looking into security vulnerabilities involving the temporary directory because on unix-like systems, the system temporary directory is shared between all users. > There exists a race condition between the deletion of the temporary file and the creation of the directory. > > java > // ensure file will always be unique by appending random digits > tmpDir = File.createTempFile(temp, ".dir", parent); // Attacker knows the full path of the file that will be generated > // delete the file that was created > tmpDir.delete(); // Attacker sees file is deleted and begins a race to create their own directory before Jetty. > // and make a directory of the same name > // SECURITY VULNERABILITY: Race Condition! - Attacker beats Jetty and now owns this directory > tmpDir.mkdirs(); > > > https://github.com/eclipse/jetty.project/blob/1b59672b7f668b8a421690154b98b4b2b03f254b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebInfConfiguration.java#L511-L518 > > In several cases the parent parameter will not be the system temporary directory. However, there is one case where it will be, as the last fallback. > > > https://github.com/eclipse/jetty.project/blob/1b59672b7f668b8a421690154b98b4b2b03f254b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebInfConfiguration.java#L467-L468 > > If any code is ever executed out of this temporary directory, this can lead to a local privilege escalation vulnerability. > > Would your team be willing to open a GitHub security advisory to continue the discussion and disclosure there? https://github.com/eclipse/jetty.project/security/advisories > > This vulnerability disclosure follows Google's 90-day vulnerability disclosure policy (I'm not an employee of Google, I just like their policy). Full disclosure will occur either at the end of the 90-day deadline or whenever a patch is made widely available, whichever occurs first. > > Cheers, > Jonathan Leitschuh
Other sources
In Eclipse Jetty versions 1.0 thru 9.4.32.v20200930, 10.0.0.alpha1 thru 10.0.0.beta2, and 11.0.0.alpha1 thru 11.0.0.beta2O, on Unix like systems, the system's temporary directory is shared between all users on that system. A collocated user can observe the process of creating a temporary sub directory in the shared temporary directory and race to complete the creation of the temporary subdirectory. If the attacker wins the race then they will have read and write permission to the subdirectory used to unpack web applications, including their WEB-INF/lib jar files and JSP files. If any code is ever executed out of this temporary directory, this can lead to a local privilege escalation vulnerability.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
redhat/rh-eclipseto a version that resolves this vulnerability.Fixed in 1:4.17-6.el7_9 - Upgrade
Upgrade
redhat/rh-eclipse-antto a version that resolves this vulnerability.Fixed in 0:1.10.9-1.2.el7 - Upgrade
Upgrade
redhat/rh-eclipse-antlr32to a version that resolves this vulnerability.Fixed in 0:3.2-28.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-apache-sshdto a version that resolves this vulnerability.Fixed in 1:2.4.0-5.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-apiguardianto a version that resolves this vulnerability.Fixed in 0:1.1.0-6.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-args4jto a version that resolves this vulnerability.Fixed in 0:2.33-12.2.el7 - Upgrade
Upgrade
redhat/rh-eclipse-batikto a version that resolves this vulnerability.Fixed in 0:1.13-1.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-bouncycastleto a version that resolves this vulnerability.Fixed in 0:1.67-1.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-cbi-pluginsto a version that resolves this vulnerability.Fixed in 0:1.1.7-8.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-decentxmlto a version that resolves this vulnerability.Fixed in 0:1.4-24.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-ecjto a version that resolves this vulnerability.Fixed in 1:4.17-1.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-eclipseto a version that resolves this vulnerability.Fixed in 1:4.17-2.2.el7_9 - Upgrade
Upgrade
redhat/rh-eclipse-eclipse-ecfto a version that resolves this vulnerability.Fixed in 0:3.14.17-1.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-eclipse-egitto a version that resolves this vulnerability.Fixed in 0:5.9.0-1.1.el7_9 - Upgrade
Upgrade
redhat/rh-eclipse-eclipse-emfto a version that resolves this vulnerability.Fixed in 1:2.23.0-1.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-eclipse-gefto a version that resolves this vulnerability.Fixed in 0:3.11.0-14.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-eclipse-jgitto a version that resolves this vulnerability.Fixed in 0:5.9.0-1.1.el7_9 - Upgrade
Upgrade
redhat/rh-eclipse-eclipse-licenseto a version that resolves this vulnerability.Fixed in 0:2.0.2-2.1.el7_9 - Upgrade
Upgrade
redhat/rh-eclipse-eclipse-m2e-coreto a version that resolves this vulnerability.Fixed in 0:1.16.2-3.1.el7_9 - Upgrade
Upgrade
redhat/rh-eclipse-eclipse-m2e-workspaceto a version that resolves this vulnerability.Fixed in 0:0.4.0-16.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-eclipse-mpcto a version that resolves this vulnerability.Fixed in 0:1.8.4-1.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-eclipse-pydevto a version that resolves this vulnerability.Fixed in 1:8.0.0-1.1.el7_9 - Upgrade
Upgrade
redhat/rh-eclipse-eclipse-subclipseto a version that resolves this vulnerability.Fixed in 0:4.3.0-8.1.el7_9 - Upgrade
Upgrade
redhat/rh-eclipse-eclipse-webtoolsto a version that resolves this vulnerability.Fixed in 0:3.19.0-1.1.el7_9 - Upgrade
Upgrade
redhat/rh-eclipse-ed25519-javato a version that resolves this vulnerability.Fixed in 0:0.3.0-8.2.el7 - Upgrade
Upgrade
redhat/rh-eclipse-felix-gogo-commandto a version that resolves this vulnerability.Fixed in 0:1.0.2-12.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-felix-gogo-parentto a version that resolves this vulnerability.Fixed in 0:4-6.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-felix-gogo-runtimeto a version that resolves this vulnerability.Fixed in 0:1.1.0-8.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-felix-gogo-shellto a version that resolves this vulnerability.Fixed in 0:1.1.0-6.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-felix-scrto a version that resolves this vulnerability.Fixed in 0:2.1.16-7.2.el7 - Upgrade
Upgrade
redhat/rh-eclipse-javaewahto a version that resolves this vulnerability.Fixed in 0:1.1.6-10.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-javaparserto a version that resolves this vulnerability.Fixed in 0:3.14.16-1.2.el7 - Upgrade
Upgrade
redhat/rh-eclipse-jchardetto a version that resolves this vulnerability.Fixed in 0:1.1-23.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-jctoolsto a version that resolves this vulnerability.Fixed in 0:3.1.0-1.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-jettyto a version that resolves this vulnerability.Fixed in 0:9.4.33-1.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-jffito a version that resolves this vulnerability.Fixed in 0:1.2.23-2.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-jgitto a version that resolves this vulnerability.Fixed in 0:5.9.0-1.2.el7 - Upgrade
Upgrade
redhat/rh-eclipse-jnato a version that resolves this vulnerability.Fixed in 0:5.4.0-7.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-jnr-constantsto a version that resolves this vulnerability.Fixed in 0:0.9.12-7.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-jnr-ffito a version that resolves this vulnerability.Fixed in 0:2.1.8-9.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-jnr-netdbto a version that resolves this vulnerability.Fixed in 0:1.1.6-11.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-jnr-posixto a version that resolves this vulnerability.Fixed in 0:3.0.47-7.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-jnr-x86asmto a version that resolves this vulnerability.Fixed in 0:1.0.2-22.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-jsch-agent-proxyto a version that resolves this vulnerability.Fixed in 0:0.0.8-14.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-junit5to a version that resolves this vulnerability.Fixed in 0:5.7.0-1.2.el7 - Upgrade
Upgrade
redhat/rh-eclipse-jythonto a version that resolves this vulnerability.Fixed in 0:2.7.1-14.1.el7_9 - Upgrade
Upgrade
redhat/rh-eclipse-jzlibto a version that resolves this vulnerability.Fixed in 0:1.1.3-15.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-luceneto a version that resolves this vulnerability.Fixed in 0:8.6.3-1.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-maven-archetypeto a version that resolves this vulnerability.Fixed in 0:3.2.0-1.1.el7_9 - Upgrade
Upgrade
redhat/rh-eclipse-maven-indexerto a version that resolves this vulnerability.Fixed in 0:6.0.0-5.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-nettyto a version that resolves this vulnerability.Fixed in 0:4.1.51-1.2.el7 - Upgrade
Upgrade
redhat/rh-eclipse-objectweb-asmto a version that resolves this vulnerability.Fixed in 0:8.0.1-1.2.el7 - Upgrade
Upgrade
redhat/rh-eclipse-opentest4jto a version that resolves this vulnerability.Fixed in 0:1.2.0-4.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-os-maven-pluginto a version that resolves this vulnerability.Fixed in 0:1.6.2-2.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-sacto a version that resolves this vulnerability.Fixed in 0:1.3-34.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-sat4jto a version that resolves this vulnerability.Fixed in 0:2.3.5-20.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-sequence-libraryto a version that resolves this vulnerability.Fixed in 0:1.0.3-8.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-sqljetto a version that resolves this vulnerability.Fixed in 0:1.1.10-18.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-stringtemplateto a version that resolves this vulnerability.Fixed in 0:3.2.1-24.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-svnkitto a version that resolves this vulnerability.Fixed in 1:1.8.12-9.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-takari-polyglotto a version that resolves this vulnerability.Fixed in 0:0.4.5-2.1.el7_9 - Upgrade
Upgrade
redhat/rh-eclipse-trilead-ssh2to a version that resolves this vulnerability.Fixed in 0:217.21-3.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-tychoto a version that resolves this vulnerability.Fixed in 0:1.7.0-2.5.el7_9 - Upgrade
Upgrade
redhat/rh-eclipse-univocity-parsersto a version that resolves this vulnerability.Fixed in 0:2.9.0-1.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-ws-commons-utilto a version that resolves this vulnerability.Fixed in 0:1.0.2-14.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-xmlgraphics-commonsto a version that resolves this vulnerability.Fixed in 0:2.4-1.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-xml-maven-pluginto a version that resolves this vulnerability.Fixed in 0:1.0.2-7.1.el7 - Upgrade
Upgrade
redhat/rh-eclipse-xmlrpcto a version that resolves this vulnerability.Fixed in 1:3.1.3-27.1.el7 - Upgrade
Upgrade
redhat/jenkinsto a version that resolves this vulnerability.Fixed in 0:2.289.1.1624365627-1.el7 - Upgrade
Upgrade
redhat/jenkinsto a version that resolves this vulnerability.Fixed in 0:2.277.3.1623846768-1.el7 - Upgrade
Upgrade
redhat/jenkinsto a version that resolves this vulnerability.Fixed in 0:2.277.3.1623853726-1.el8 - Upgrade
Upgrade
maven/org.eclipse.jetty:jetty-webappto a version that resolves this vulnerability.Fixed in 9.4.33.v20201020 - Upgrade
Upgrade
maven/org.mortbay.jetty:jetty-webappto a version that resolves this vulnerability.Fixed in 11.0.0.beta3 - Upgrade
Upgrade
maven/org.eclipse.jetty:jetty-webappto a version that resolves this vulnerability.Fixed in 11.0.0.beta3 - Upgrade
Upgrade
maven/org.mortbay.jetty:jetty-webappto a version that resolves this vulnerability.Fixed in 10.0.0.beta3 - Upgrade
Upgrade
maven/org.eclipse.jetty:jetty-webappto a version that resolves this vulnerability.Fixed in 10.0.0.beta3 - Upgrade
Upgrade
maven/org.mortbay.jetty:jetty-webappto a version that resolves this vulnerability.Fixed in 9.4.33 - Upgrade
Upgrade
debian/jetty9to a version that resolves this vulnerability.Fixed in 9.4.16-0+deb10u1Fixed in 9.4.50-4+deb10u1Fixed in 9.4.39-3+deb11u2Fixed in 9.4.50-4+deb11u1Fixed in 9.4.50-4+deb12u2Fixed in 9.4.53-1 - Upgrade
Upgrade
redhat/jettyto a version that resolves this vulnerability.Fixed in 9.4.33. - Upgrade
Upgrade
redhat/jettyto a version that resolves this vulnerability.Fixed in 10.0.0. - Upgrade
Upgrade
redhat/jettyto a version that resolves this vulnerability.Fixed in 11.0.0. - Upgrade
Upgrade
debian/jetty9to a version that resolves this vulnerability.Fixed in 9.4.16-0+deb10u1 - Upgrade
Upgrade
debian/jetty9to a version that resolves this vulnerability.Fixed in 9.4.50-4+deb10u1 - Upgrade
Upgrade
debian/jetty9to a version that resolves this vulnerability.Fixed in 9.4.39-3+deb11u2 - Upgrade
Upgrade
debian/jetty9to a version that resolves this vulnerability.Fixed in 9.4.50-4+deb11u1 - Upgrade
Upgrade
debian/jetty9to a version that resolves this vulnerability.Fixed in 9.4.50-4+deb12u2 - Upgrade
Upgrade
debian/jetty9to a version that resolves this vulnerability.Fixed in 9.4.53-1 - Configuration
Create a directory named 'work' under your ${jetty.base} (the parent of the webapps directory) and restart Jetty so Jetty will use this directory as its work directory.
Jetty (server) work directory presence = create ${jetty.base}/work - Configuration
Start the JVM for Jetty with -Djava.io.tmpdir=/var/web/work to force Jetty to use a temp directory outside the shared system /tmp.
JVM / Jetty startup java.io.tmpdir = /var/web/work - Configuration
Set the WebAppContext tempDirectory in the context XML (e.g. <Set name="tempDirectory">/var/web/work/foo</Set>) to a directory outside the shared /tmp for that deployed webapp.
WebAppContext tempDirectory = /var/web/work/foo - Configuration
Set the ServletContext attribute 'org.eclipse.jetty.webapp.basetempdir' to a path outside the shared /tmp and ensure the directory exists; Jetty will use it if present.
ServletContext org.eclipse.jetty.webapp.basetempdir = existing directory path outside /tmp - Configuration
Ensure the 'javax.servlet.context.tempdir' ServletContext attribute points to a directory outside the shared /tmp and that the directory exists and is not writable/readable by untrusted users.
ServletContext javax.servlet.context.tempdir = existing directory path outside /tmp - Configuration
Ensure any temp directory used by Jetty (e.g. ${jetty.base}/work or the path set via java.io.tmpdir) is owned by the service user and permissions are set so it is not readable or writable by other unprivileged users.
Temporary directory permissions = not readable or writable by attackers
Event History
Parent advisories
This vulnerability appears in the following advisories.
Frequently Asked Questions
What is the severity of CVE-2020-27216?
CVE-2020-27216 is classified as a medium severity vulnerability.
How do I fix CVE-2020-27216?
To fix CVE-2020-27216, upgrade to the appropriate patched version of the affected software packages listed in the advisory.
Which software is affected by CVE-2020-27216?
CVE-2020-27216 affects multiple versions of Eclipse Jetty and related packages.
What is the exploit type of CVE-2020-27216?
CVE-2020-27216 is a race condition vulnerability that can lead to unauthorized access.
Is CVE-2020-27216 a remotely exploitable vulnerability?
Yes, CVE-2020-27216 can potentially be exploited by a collocated user on a Unix-like system.