Skip to content

Commit 88b541d

Browse files
committed
fix(server): preserve Office document MIME types
Narrow XML download detection so Office Open XML files keep their official content types while actual XML and SVG content stays octet-stream. Built with GPT-5.6 Sol in the Codex harness.
1 parent 826e1e3 commit 88b541d

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

‎apps/server/src/http.test.ts‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,35 @@ describe("assetResponseHeaders", () => {
8484
});
8585

8686
it("keeps renderable mime types as octet-stream downloads", () => {
87-
for (const mimeType of ["text/html", "image/svg+xml", "application/xml", "not a mime"]) {
87+
for (const mimeType of [
88+
"text/html",
89+
"text/xml",
90+
"image/svg+xml",
91+
"application/xhtml+xml",
92+
"application/rss+xml",
93+
"APPLICATION/XML",
94+
"IMAGE/SVG+XML",
95+
"application/xml-dtd",
96+
"application/xml-external-parsed-entity",
97+
"not a mime",
98+
]) {
8899
expect(
89100
assetResponseHeaders("/attachments/upload.bin", { download: true, mimeType }),
90101
).toHaveProperty("Content-Type", "application/octet-stream");
91102
}
92103
});
104+
105+
it("preserves official Office Open XML mime types", () => {
106+
for (const mimeType of [
107+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
108+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
109+
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
110+
]) {
111+
expect(
112+
assetResponseHeaders("/attachments/upload.bin", { download: true, mimeType }),
113+
).toHaveProperty("Content-Type", mimeType);
114+
}
115+
});
93116
});
94117

95118
describe("downloadContentDisposition", () => {

‎apps/server/src/http.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const SVG_CONTENT_SECURITY_POLICY = "default-src 'none'; style-src 'unsafe-inlin
5656
const DOWNLOAD_MIME_TYPE_PATTERN = /^[\w!#$&^.+-]+\/[\w!#$&^.+-]+$/;
5757
const isSafeDownloadMimeType = (mimeType: string): boolean =>
5858
DOWNLOAD_MIME_TYPE_PATTERN.test(mimeType) &&
59-
!/(?:^text\/html$|svg|xml)/i.test(mimeType.trim().toLowerCase());
59+
!/(?:^text\/html$|\/xml(?:$|-)|\+xml$)/i.test(mimeType.trim().toLowerCase());
6060

6161
/** RFC 6266 disposition with an ASCII fallback name plus a UTF-8 `filename*`. */
6262
export function downloadContentDisposition(fileName?: string): string {

0 commit comments

Comments
 (0)