#11335·dropwizard

AssetServlet.loadAsset() .. path traversal concern (thinking: defense-in-depth, but not an issue?)

Author: accwebsCreated Sep 28, 2026Updated Sep 28, 2026

Something @insaf021 noticed and raised on one-or-more PRs - feeding potentially-malicious URI inputs into AssetServlet.loadAsset(String key) could have security problems.

This was one change (of a few different logical changes) raised in https://github.com/dropwizard/dropwizard/pull/11233. Because that PR is rather old (and possibly a number of the changes in that PR do not make sense to merge....I posted various questions on that PR), I have created this issue to track that this particular problem gets looked at further and not forgotten.

What @insaf021's PR does right now

  1. Reject any 'resource path' containing ..

Does this fix a security issue?

Under the anticipated 'resources live within the uber jar' deployment model, this is a non-issue. The .. path segment does not get treated specially meaning any such segment in the input path will result in a null resource -> not found.

In the model where the resource root is an actual filesystem directory, then yes, .. is treated specially. Prior to Dropwizard upgrading to Servlet API 6.0 (older versions had less clear rules regarding URI path normalization), this was quite possibly exploitable depending on how Jetty behaved. However, as of today this is not exploitable even in such a deployment scenario since the Jetty rules of getServletPath() and getPathInfo() are now clear.

See "Detailed Analysis" below.

At this point, adding this type of check would be a defense-in-depth change if we want that.

Any similar 'related' vulns related to paths?

I batted around various other possible ways to abuse getResource(). The other "possible vulnerably" that jumps out is related to Windows reserved-name defenses. Basically, if you're operating the app NOT using an uber-jar deployment, various filenames on windows are reserved (CON, PRN, AUX, NUL, COM1, COM2, etc). There are alternate data stream concerns. Various characters are unsafe to use. There are various custom canonicalization rules file. -> file unless UNC paths are used to override Win32's typical restrictions. Each of these things could be a way to access file data not intended by the developer.

Reference: https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#file-and-directory-names

So yes, probably in an ideal world we'd also guard against these things. But at the same time, I'm not convinced there's any clean "standard" solution out there for that sort of thing and I'm not eager to take on all the logic to 'sanitize all windows path names'.

I'm generally anticipating a fat-jar deployment in any real deployed environment, which means this is not exploitable even on Windows. So I'd suggest tabling these Windows-only worries indefinitely. Maybe with an action to document 'expected deployment model' and that 'violating the model will break security assumptions'.

Thus, for this ticket, I'd suggest - if anything - we only add the .. path segment blocking as a defense-in-depth measure.

Change correctness

I think the check itself is not quite implemented properly and is overly-strict. Possibly something like:

  for (String segment : requestedResourcePath.split("[/\\\\]")) {
      if ("..".equals(segment)) {
          throw new IllegalArgumentException("Path traversal attempt detected: " + requestedResourcePath);
      }
  }

would be more correct.


Detailed Analysis

Analysis of Resource.getResource() security properties

How it resolves: Resources.getResource(name) → ClassLoader.getResource(name). The lookup dispatches through URLClassPath to one of two loaders per classpath entry: JarLoader (jar-based) or FileLoader (directory-based).

Historical concerns with ClassLoader.getResource() / URLClassPath:

  • Directory-classpath .. resolution has always been the primary hazard. The JDK's URLClassPath$FileLoader resolves .. segments as directory traversal and enforces only a string-prefix containment check against the classpath entry root. This bounds escape to the classpath root but permits access to any sibling of the intended asset directory (config files, class files, META-INF contents).
  • The string-prefix check is not a canonicalized-path check. In principle vulnerable to case-insensitive filesystem quirks and unicode normalization edge cases; no specific exploit is widely documented but the pattern is known-brittle.
  • Jar-classpath lookups have always been safer. The jar loader treats resource names as opaque ZIP central-directory keys, invoking no filesystem API with attacker input. This distinction — file-classpath dangerous, jar-classpath safe — has held across all modern JDK versions.
  • Percent-decoding and URL-scheme parsing have never been part of the resource-name resolution. The classloader treats %2E%2E, file:/, jar:... as literal characters. Historical CVEs in this area targeted the servlet container's URI canonicalization, not the classloader itself (e.g. Tomcat CVE-2016-6816, various Jetty URI compliance CVEs). Those bugs allowed unnormalized paths to reach servlets, at which point downstream getResource calls could resolve the ..
  • JDK-side null-byte handling was hardened around JDK 7-8 (CVE-2015-2601, CVE-2015-4732 in java.io.File and related). Post-JDK-8, NIO2 (Files.exists(Path) etc.) rejects \0 in filenames; legacy File API is more permissive on some paths. Classloader resource lookup goes through URL handlers that typically reject \0 at the URL-parse stage.
  • Windows-specific hazards (reserved device names, NTFS ADS syntax, trailing-dot stripping, UNC path parsing) have never been filtered by the classloader — they're considered filesystem semantics. Any code that passes user input to getResource() on a directory-classpath deployment on Windows has always been exposed to these, and there is no documented JDK-side fix planned because the JDK considers this the caller's responsibility.

What does this mean for this use of getResource()?

Resulting behaviors differs materially depending on a fat-jar deployment model or classpath running from a directory:

Jar-based classpath (standard fat-jar deployment):

  • The name string is used only as a hash-map key against the jar's ZIP central directory. No filesystem API is invoked with any part of name.
  • .. in a path segment does NOT get resolved.
  • Thus: safe on all platforms

Directory-based classpath (dev mode, IDE, exploded WAR, mvn exec, or extra -cp directory):

  • .. in a path segment does get resolved. Escape is bounded to the classpath root (JDK enforces a string-prefix containment check on the resolved URL), but this still allows access to anything sharing the classpath root: application.yml, logback.xml, class files, META-INF/MANIFEST.MF, other packages.
  • Empty name, ., assets, assets/ return the directory URL — enabling directory-listing info disclosure.
  • On Windows only, additional concerns arise because the classloader eventually invokes Windows filesystem APIs with the name:
    • Reserved device names (CON, AUX, NUL, etc.) can trigger device I/O — most notably readAllBytes() on CON blocks forever, enabling thread-pool-exhaustion DoS.
    • NTFS alternate data streams (file.txt:hidden) could expose hidden data if any exists.
    • Trailing dots/spaces are stripped by Windows, potentially bypassing string-form checks.
    • 8.3 short names, case-insensitivity, and unicode normalization can bypass allow-lists.

Concerns ruled out:

  • Percent-encoding (%2E%2E, %2F, %00) — classloader does not percent-decode. Reaches the loader as literal string, does not match anything.
  • Backslashes as separators — treated as literal characters, not path separators.
  • Null-byte truncation via raw \0 — no match, no I/O; modern JDK's NIO layer additionally rejects.
  • URL-scheme prefixes (file:/, jar:file:...!/...) — treated as literal name, not honored.
  • Unicode look-alikes for / (fraction slash, division slash, etc.) — not treated as separator.
  • Root-escape past the classpath entry (../../../../etc/passwd) — blocked by string-prefix containment check in URLClassPath$FileLoader.
  • Servlet-container-level bypasses under Servlet 6.0 + Jetty 12 defaults — container canonicalizes and rejects suspicious sequences before dispatch. Only relevant if operator has explicitly disabled Jetty's strict URI compliance mode.