The vulnerability exists within the xwiki-platform-webjars-api component, specifically in the FilesystemResourceReferenceCopier class. The root cause is a path traversal vulnerability when handling resources from WebJar extensions. An attacker with administrative privileges on a subwiki could install a malicious WebJar extension containing specially crafted file paths.
The analysis of the patch 9f747fcd3200259a1de51957d3f5f6acc8e3816c reveals two key vulnerable functions:
-
org.xwiki.webjars.internal.FilesystemResourceReferenceCopier.copyResourceFromJAR: This function is the core of the vulnerability. It copies files from a JAR to the filesystem. Before the patch, it did not validate whether the destination path was within the intended export directory. By crafting a resource path with ../ sequences, an attacker could write files to arbitrary locations on the server's filesystem.
-
org.xwiki.webjars.internal.FilesystemResourceReferenceCopier.processCSSfile: This function acts as an entry point for the vulnerability. It parses CSS files within a WebJar, extracts resource URLs using url(), and then calls copyResourceFromJAR to place them on the filesystem. A malicious CSS file could contain a url() with a path traversal payload, which this function would then use to construct a malicious destination path, leading to the exploitation of the vulnerability in copyResourceFromJAR.
The patch mitigates this by adding path validation checks in both functions. In copyResourceFromJAR, it now verifies that the canonical path of the destination file is within the boundaries of the export directory. In processCSSfile, it checks that the resolved resource path starts with the expected prefix before attempting to copy it. Any runtime profiler monitoring file I/O operations during the installation of a malicious WebJar would see these function names in the stack trace leading up to the unauthorized file write.