This issue has been created
There is 1 update.
 
 
XWiki Platform / cid:jira-generated-image-avatar-fb853a3d-09ae-4dcc-93d6-45e2799ae843 XWIKI-24999 Open

Path traversal protection during WebJar export can be bypassed through a sibling of the export directory

 
View issue   ยท   Add comment
 

Issue created

 
cid:jira-generated-image-avatar-6ad5d295-7e96-4c6e-b48f-522689a8fcb9 Simon Urli created this issue on 16/Sep/26 10:24
 
Summary: Path traversal protection during WebJar export can be bypassed through a sibling of the export directory
Issue Type: cid:jira-generated-image-avatar-fb853a3d-09ae-4dcc-93d6-45e2799ae843 Bug
Affects Versions: 16.10.17
Assignee: Unassigned
Components: Webjar
Created: 16/Sep/26 10:24
Priority: cid:jira-generated-image-static-major-0954465a-ea05-4fa4-a4ec-ca64e709f033 Major
Reporter: Simon Urli
Description:

Problem

XWIKI-23902 added a protection against path traversal when WebJar resources are copied to the filesystem during an HTML export. The check in FilesystemResourceReferenceCopier#copyResourceFromJAR compares the two canonical paths as plain strings:

String canonicalTargetPath = targetLocation.getCanonicalPath();
String canonicalExportPath = exportDirectory.getCanonicalPath();
if (canonicalTargetPath.startsWith(canonicalExportPath)) {

String.startsWith does not stop at a path component boundary. A target such as /tmp/xwiki/export-evil/poc.txt therefore passes the check for the export directory /tmp/xwiki/export, even though it is a sibling of the export directory and not inside it.

A WebJar containing a JAR entry whose name escapes the export directory (for example META-INF/resources/webjars/../../export-evil/poc.txt) can consequently have its content written next to the export directory instead of inside it. Installing a WebJar only requires the ADMIN right, not Programming Right, so this is a weaker check than the one the protection is meant to enforce.

Why this is not currently exploitable

The escape only works if the attacker can name a sibling directory whose name starts with the export directory's own name, which means knowing that name when the WebJar is built. In practice the export directory is created by HtmlPackager as a fresh RandomStringUtils.secure().nextAlphanumeric(8) directory under the temporary directory, and it is regenerated for every export, so the name is not predictable. Even with a correct guess, the write stays confined to a path that starts with the export directory's absolute path, i.e. a sibling inside XWiki's own temporary directory.

This is therefore reported as a hardening issue and not as a vulnerability: the correctness of the check currently rests on an unrelated decision in HtmlPackager to randomise the directory name, rather than on the check itself.

Fix

Compare path components instead of characters, using java.nio.file.Path#startsWith.

 
 

1 update

 
cid:jira-generated-image-avatar-6ad5d295-7e96-4c6e-b48f-522689a8fcb9 Changes by Simon Urli on 16/Sep/26 10:24
 
Fix Version: 18.9.0-rc-1