Skip to content

Commit 75ea2ff

Browse files
committed
fix: infer Content-Type from file extension when creating files
- Add getContentTypeFromExtension() helper with common MIME types - Use extension-based content type instead of hardcoded text/plain - Add aisafe.io to security acknowledgments (JWT_SECRET issue)
1 parent 8a13f34 commit 75ea2ff

3 files changed

Lines changed: 47 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ See [.env.example](.env.example) for all available options.
197197

198198
Thank you to the following researchers for responsibly disclosing security issues:
199199

200+
- [aisafe.io](https://aisafe.io) - Insecure JWT_SECRET default allowing token forgery
200201
- [debsec](https://x.com/deb_security) - LFI via improper path handling
201202
- [JaGoTu](https://infosec.exchange/@jagotu) - DoS via unrestricted file upload
202203
- [m0z](https://x.com/LooseSecurity) - LFI via session subdomain

frontend/src/components/file-tree/FileTree.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
renameInTree,
2020
deleteFromTree,
2121
getFilesInFolder,
22+
getContentTypeFromExtension,
2223
} from "@/lib/fileTree";
2324
import type { FileTree as FileTreeType } from "@/types";
2425

@@ -349,7 +350,10 @@ export function FileTree({
349350
raw: "", // Empty content
350351
headers: [
351352
{ header: "Access-Control-Allow-Origin", value: "*" },
352-
{ header: "Content-Type", value: "text/plain" },
353+
{
354+
header: "Content-Type",
355+
value: getContentTypeFromExtension(fullPath),
356+
},
353357
],
354358
status_code: 200,
355359
},

frontend/src/lib/fileTree.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,47 @@ export function deleteFromTree(files: FileTree, path: string): FileTree {
179179
return newFiles;
180180
}
181181

182+
/**
183+
* Get the Content-Type header value based on file extension
184+
*/
185+
export function getContentTypeFromExtension(filename: string): string {
186+
const ext = filename.split(".").pop()?.toLowerCase() || "";
187+
const mimeTypes: Record<string, string> = {
188+
// Text/Code
189+
html: "text/html; charset=utf-8",
190+
htm: "text/html; charset=utf-8",
191+
css: "text/css; charset=utf-8",
192+
js: "text/javascript; charset=utf-8",
193+
mjs: "text/javascript; charset=utf-8",
194+
json: "application/json; charset=utf-8",
195+
xml: "application/xml; charset=utf-8",
196+
txt: "text/plain; charset=utf-8",
197+
md: "text/markdown; charset=utf-8",
198+
csv: "text/csv; charset=utf-8",
199+
yaml: "text/yaml; charset=utf-8",
200+
yml: "text/yaml; charset=utf-8",
201+
// Images
202+
png: "image/png",
203+
jpg: "image/jpeg",
204+
jpeg: "image/jpeg",
205+
gif: "image/gif",
206+
svg: "image/svg+xml",
207+
ico: "image/x-icon",
208+
webp: "image/webp",
209+
// Fonts
210+
woff: "font/woff",
211+
woff2: "font/woff2",
212+
ttf: "font/ttf",
213+
otf: "font/otf",
214+
eot: "application/vnd.ms-fontobject",
215+
// Other
216+
pdf: "application/pdf",
217+
zip: "application/zip",
218+
wasm: "application/wasm",
219+
};
220+
return mimeTypes[ext] || "text/plain; charset=utf-8";
221+
}
222+
182223
/**
183224
* Get unique folder paths from a FileTree
184225
*/

0 commit comments

Comments
 (0)