- Media rows can no longer be created through the CRUD API, updates only take description fields on the caller's own row, and every media read or delete goes through mediaFilePath, which refuses paths outside DATA_DIR or inside the database folder. - Uploads strip the file name and extension to safe characters and keep only title, description and summary from the request's media object. - Folder imports no longer follow symlinks (walkRegularFiles), and the source path is quoted in the computer's shell. - User and bot files are served with nosniff, and HTML, SVG, XML and scripts are sandboxed by CSP. - Sandbox cookies are kept to the computer's prefix, and websocket upgrades on /ws and the computer proxy must come from the app's own address (README and Help note nginx's Host header). - user_types CRUD writes go through the assignment matrix; members only read their own user record; read-only users can read CRUD again; grabUsers builds valid SQL for array search terms and bad pages; an admin media DELETE needs an id; read-only users can't delete media. - Rate limits and the audit log use the connection's address, trusting forwarded headers only from a proxy, and login limits are split per address, per account from that address and per account overall. Co-Authored-By: Claude Opus 5.5 <[email protected]>
53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
type Params = {
|
|
/**
|
|
* The type the file goes out with, e.g. `text/html; charset=utf-8`.
|
|
*/
|
|
content_type?: string | null;
|
|
};
|
|
|
|
/**
|
|
* Types a browser runs as a page or script when opened. Files of these
|
|
* types come from users and bots (a report a bot wrote from a scraped
|
|
* site), and they are served from the app's own origin, so opened as they
|
|
* are they would run with the viewer's session.
|
|
*/
|
|
const ActiveContentTypes = [
|
|
"text/html",
|
|
"application/xhtml+xml",
|
|
"image/svg+xml",
|
|
"text/xml",
|
|
"application/xml",
|
|
"text/javascript",
|
|
"application/javascript",
|
|
"application/ecmascript",
|
|
"text/ecmascript",
|
|
"text/xsl",
|
|
];
|
|
|
|
/**
|
|
* Whether a type is one a browser would run (`ActiveContentTypes`), any
|
|
* `+xml` type included.
|
|
*/
|
|
export function isActiveContentType({ content_type }: Params) {
|
|
const type = (content_type || "").split(";")[0]!.trim().toLowerCase();
|
|
|
|
return ActiveContentTypes.includes(type) || type.endsWith("+xml");
|
|
}
|
|
|
|
/**
|
|
* The headers every user or bot file is served with: never sniffed into
|
|
* another type, and an active one (HTML, SVG, XML, scripts) sandboxed, so
|
|
* it still opens but runs no script and gets an origin of its own instead
|
|
* of the app's. Other types (images, PDFs, audio) are left alone, since a
|
|
* sandbox stops the browser's PDF viewer.
|
|
*/
|
|
export default function servedFileHeaders({ content_type }: Params): Record<string, string> {
|
|
const headers: Record<string, string> = { "X-Content-Type-Options": "nosniff" };
|
|
|
|
if (isActiveContentType({ content_type })) {
|
|
headers["Content-Security-Policy"] = "sandbox";
|
|
}
|
|
|
|
return headers;
|
|
}
|