Micronaut static resources served from a class path directory follow symbolic links outside the configured base path
Description
Static resources mapped with a classpath: path (for example micronaut.router.static-resources.default.paths=classpath:public) are resolved by DefaultClassPathResourceLoader, which checks only the requested path and never the location of the file it opens. When the application runs from an exploded class path (a directory, as in development, gradle run, many container layouts and IDE launches), a symbolic link inside the static base directory is followed, and the server returns files outside of it.
DefaultFileSystemResourceLoader, used for file: static resource paths, compares the real path of the resolved file with the real path of the base directory and returns 404 in the same case; the class path loader does not.
Details
Path to serving: StaticResourceResolver.resolve -> ResourceLoader.getResource on the loader created by ClassPathResourceLoader.forBase("classpath:public") -> NettyRequestLifecycle.findFile in micronaut-http-server-netty, which streams the file: URL.
PoC
Class path directory layout:
classes/public/index.html
classes/public/export -> ../private
classes/private/key.txtWith micronaut.router.static-resources.default.paths=classpath:public and mapping=/**, GET /export/key.txt returns the contents of classes/private/key.txt.
Impact
Disclosure of files reachable through a symbolic link that sits inside a static resource directory on an exploded class path. The attacker cannot create the link; it must already exist in the deployed directory (for example created by a build step, a mounted volume or a shared directory). Applications running from jars are not affected.
Fix
DefaultClassPathResourceLoader with a base path rejects a file: resource whose real path is not under the real path of the base directory in the class path entry it came from. Loaders without a base path keep their behavior.
Affected and patched versions
| Package | Affected versions | Patched version |
|---|---|---|
io.micronaut:micronaut-core | < 3.10.19 | 3.10.19 |
io.micronaut:micronaut-core | >= 4.0.0, < 4.10.37 | 4.10.37 |
io.micronaut:micronaut-core | >= 5.0.0, < 5.2.23 | 5.2.23 |
The 3.x fix is in commit 6708ff83bc, first included in stable release 3.10.19. The last affected stable 3.10.x release is 3.10.18.