[Security] Potential stored XSS through inline local HTML/SVG attachments
[Security] Potential stored XSS through inline serving of local HTML/SVG attachments
Summary
In Halo v2.26.1, the default local attachment policy does not restrict file types, while the local attachment handler preserves an uploaded filename and the /upload/** resource handler serves the stored bytes from the primary site origin. An authenticated user with attachment-upload permission can upload an .html (and potentially .svg) file. An unauthenticated request to its /upload/... permalink receives the bytes inline with an extension-derived executable content type and without Content-Disposition: attachment.
This creates a stored same-origin active-content/XSS risk when a victim visits the permalink. The upload and same-origin HTTP serving behavior were reproduced against a clean v2.26.1 deployment. Browser DOM execution was not used in this report, so the runtime evidence directly establishes the serving mechanism; browser execution should be confirmed by the maintainer during triage.
Affected version
- Halo
v2.26.1(latest stable release at the time of testing) - Local attachment storage policy; other storage backends may have different behavior
Preconditions
- The attacker has an authenticated account with an attachment upload permission, such as
uc:attachments:manageorsystem:attachments:manage. - The selected local policy permits the upload. In the shipped default policy,
allowedFileTypesis absent/empty ({"location":""}), so the MIME/extension allow-list check is not applied. - A victim opens the resulting
/upload/...URL. The victim does not need upload permission.
Reproduction
Use a test account with the required upload permission. Replace the placeholders; do not share real cookies in a public report.
Create poc.html:
<!doctype html>
<html><body>
<script>document.body.dataset.haloPoc = "attachment-inline-content";</script>
HALO_ATTACHMENT_POC
</body></html>Upload it through the console attachment endpoint:
HALO_URL="https://<halo-host>"
curl -i -X POST \
-b "<SESSION_COOKIE>" \
-H "X-XSRF-TOKEN: <XSRF_TOKEN>" \
-F '[email protected];filename=poc.html;type=text/html' \
"$HALO_URL/apis/console.api.storage.halo.run/v1alpha1/attachments/-/upload"The response contains an attachment permalink similar to /upload/poc.html.
Fetch it without authentication:
curl -i "$HALO_URL/upload/poc.html"Observed result
The tested v2.26.1 deployment returned:
HTTP/1.1 200 OK
Content-Type: text/html
Content-Disposition: (absent)
X-Content-Type-Options: nosniffThe response body contained the uploaded HTML and the HALO_ATTACHMENT_POC marker verbatim. A PNG control upload was also anonymously retrievable as 200 image/png, confirming that the upload-and-serve path was functioning normally. After deleting the attachment, both permalinks returned 404.
X-Content-Type-Options: nosniff was present, but it does not turn a top-level document explicitly served as text/html into a download and does not replace Content-Disposition or origin isolation. No browser DOM-execution claim is required to reproduce the unsafe response behavior; a browser-level test can be used to confirm the final XSS impact.
Source path
application/src/main/resources/extensions/attachment-local-policy.yaml:23-28— default policy omitsallowedFileTypes.application/src/main/java/run/halo/app/core/attachment/endpoint/LocalAttachmentUploadHandler.java:177-208— file-type validation runs only whenallowedFileTypesis non-empty.LocalAttachmentUploadHandler.java:369-371— original filename is retained whenalwaysRenameFilenameis false.application/src/main/java/run/halo/app/infra/config/WebFluxConfig.java:159-163—/upload/**is mapped directly to the local attachment directory without a forced download disposition or fixed safe content type.application/src/main/java/run/halo/app/infra/config/WebServerSecurityConfig.java:55-69—/upload/**is not in the static-resource exclusion list.application/src/main/java/run/halo/app/security/authorization/AuthorizationExchangeConfigurers.java:95-99— the final authorization rule permits the public resource request; upload itself remains permission-controlled.
Security impact
The attacker needs upload permission, so this is not an unauthenticated file-upload issue. However, the resulting file is publicly reachable and is served from the Halo site origin. If a victim navigates to the permalink, attacker-controlled markup may execute in the site's origin and may be able to perform same-origin actions with the victim's active session. The exact confidentiality/integrity impact depends on the victim's privileges, cookie flags, CSRF protections, and any reverse-proxy CSP.
Deployments that explicitly restrict the policy to safe file categories, force downloads, or serve uploads from a separate cookie-less origin reduce or remove this risk.
Historical scope
The issue is not caused by a single upload route. Console, UC, and legacy attachment upload routes converge on the same local attachment handler and the same /upload/** resource mapping. A fix limited to one endpoint, or a fix that only rejects MIME/extension mismatches when an allow-list is configured, does not address the default unrestricted-policy plus inline-serving path.
Relation to earlier reports
Halo has historical reports for older upload/XSS behavior (for example, #1522 and #1575). This report is focused on the current Halo 2.x path: the shipped default local policy leaves allowedFileTypes empty, and the current /upload/** resource mapping still returns user-controlled HTML inline from the site origin. PR #7149 addresses MIME/extension mismatch (polyglot) validation when an allow-list is configured; it does not prevent an unrestricted default policy from accepting active-content extensions or force those files to download.
Suggested remediation
- Reject active-content extensions such as
.html,.htm,.xhtml, and.svgby default, regardless of whetherallowedFileTypesis configured. - Serve user uploads with
Content-Disposition: attachmentand a safe non-executable content type such asapplication/octet-streamunless a type is explicitly safe. - Prefer serving uploads from a separate origin that does not carry Halo session cookies.
- Add an end-to-end regression test covering the default policy: upload HTML, fetch the public permalink anonymously, and assert that it cannot be returned as an inline
text/htmldocument.
Source: halo-dev/halo