CVE-2020-27216

CVE-2020-27216 is a high-severity security vulnerability in org.mortbay.jetty:jetty-webapp (maven), affecting versions < 9.4.33. It is fixed in 9.4.33, 10.0.0.beta3, 11.0.0.beta3, 9.4.33.v20201020.

Does this CVE actually affect you?

Kodem shows which CVEs are reachable and running in your applications, so you fix what's exploitable, not just what's listed.

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Runtime intelligence, not another scanner.

Summary

Local Temp Directory Hijacking Vulnerability

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)

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.

[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):

<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

Similar Vulnerabilities

Similar, but not the same.

For more information

The original report of this vulnerability is below:

On Thu, 15 Oct 2020 at 21:14, Jonathan Leitschuh [email protected] 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.

// 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

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:

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.

CVE-2020-27216 has a CVSS score of 7.0 (High). The vector is requires local access, low privileges required, and no user interaction. A CVSS score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether this affects your application depends on whether the vulnerable code is present and reachable in your environment. A fixed version is available (9.4.33, 10.0.0.beta3, 11.0.0.beta3, 9.4.33.v20201020); upgrading removes the vulnerable code path.

Affected versions

org.mortbay.jetty:jetty-webapp (< 9.4.33) org.eclipse.jetty:jetty-webapp (>= 10.0.0.beta1, <= 10.0.0.beta2) org.mortbay.jetty:jetty-webapp (>= 10.0.0.beta1, <= 10.0.0.beta2) org.eclipse.jetty:jetty-webapp (>= 11.0.0.beta1, <= 11.0.0.beta2) org.mortbay.jetty:jetty-webapp (>= 11.0.0.beta1, <= 11.0.0.beta2) org.eclipse.jetty:jetty-webapp (< 9.4.33.v20201020)

Security releases

org.mortbay.jetty:jetty-webapp → 9.4.33 (maven) org.eclipse.jetty:jetty-webapp → 10.0.0.beta3 (maven) org.mortbay.jetty:jetty-webapp → 10.0.0.beta3 (maven) org.eclipse.jetty:jetty-webapp → 11.0.0.beta3 (maven) org.mortbay.jetty:jetty-webapp → 11.0.0.beta3 (maven) org.eclipse.jetty:jetty-webapp → 9.4.33.v20201020 (maven)

Kodem intelligence

Severity tells you how bad this could be in the worst case. It does not tell you whether you are exposed. Exploitability and impact are functions of runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A vulnerable package can sit in your dependency tree and never run.

Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter. Kodem's runtime-powered SCA identifies whether this CVE is reachable in your applications.

Already deployed Kodem?

See it in your environmentNew to Kodem? Get a demo →

Remediation advice

Fixes were applied to the 9.4.x branch with:

These will be included in releases: 9.4.33, 10.0.0.beta3, 11.0.0.beta3

Frequently Asked Questions

  1. What is CVE-2020-27216? CVE-2020-27216 is a high-severity security vulnerability in org.mortbay.jetty:jetty-webapp (maven), affecting versions < 9.4.33. It is fixed in 9.4.33, 10.0.0.beta3, 11.0.0.beta3, 9.4.33.v20201020.
  2. How severe is CVE-2020-27216? CVE-2020-27216 has a CVSS score of 7.0 (High). This score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether it represents real risk in your environment depends on whether the vulnerable code is present and reachable.
  3. Which packages are affected by CVE-2020-27216?
    • org.mortbay.jetty:jetty-webapp (maven) (versions < 9.4.33)
    • org.eclipse.jetty:jetty-webapp (maven) (versions >= 10.0.0.beta1, <= 10.0.0.beta2)
  4. Is there a fix for CVE-2020-27216? Yes. CVE-2020-27216 is fixed in 9.4.33, 10.0.0.beta3, 11.0.0.beta3, 9.4.33.v20201020. Upgrade to this version or later.
  5. Is CVE-2020-27216 exploitable, and should I be worried? Whether CVE-2020-27216 is exploitable in your environment depends on whether the vulnerable code is present and reachable. A CVSS score is a worst-case rating; it does not account for your specific deployment, configuration, or usage patterns. Kodem, an Intelligent Application Security platform, uses runtime intelligence to show which vulnerabilities actually execute in production, so you can focus on the ones that represent real risk. Get a demo
  6. What actually determines whether CVE-2020-27216 is exploitable, and how bad it is? Exploitability and impact are not fixed properties of a CVE. They depend on runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A high CVSS score on a dependency that never runs is not the same as real risk. Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter.
  7. How do I fix CVE-2020-27216?
    • Upgrade org.mortbay.jetty:jetty-webapp to 9.4.33 or later
    • Upgrade org.eclipse.jetty:jetty-webapp to 10.0.0.beta3 or later
    • Upgrade org.mortbay.jetty:jetty-webapp to 10.0.0.beta3 or later
    • Upgrade org.eclipse.jetty:jetty-webapp to 11.0.0.beta3 or later
    • Upgrade org.mortbay.jetty:jetty-webapp to 11.0.0.beta3 or later
    • Upgrade org.eclipse.jetty:jetty-webapp to 9.4.33.v20201020 or later

Stop the waste.
Protect your environment with Kodem.