Fix file access, XSS and access-control bugs from a security scan
- 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]>
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
import path from "node:path";
|
||||
import mediaFilePath from "@/src/utils/media-file-path";
|
||||
import { AppData } from "@/src/data/app-data";
|
||||
import grabMessagesMedia, {
|
||||
type MessageMediaRow,
|
||||
} from "@/src/functions/backend/db/bots/grab-messages-media";
|
||||
import type { HarnessContentPart } from "@/src/harness/types";
|
||||
import type { BotMessageWithAttachments } from "@/src/types";
|
||||
import grabDirNames from "@/src/utils/grab-dir-names";
|
||||
import describeAttachment from "./describe-attachment";
|
||||
|
||||
type Params = {
|
||||
@@ -74,9 +73,10 @@ async function fileToParts({ file }: { file: MessageMediaRow }): Promise<Harness
|
||||
return [{ type: "text", text: `[Attached video ${label}: videos can't be read yet.]` }];
|
||||
}
|
||||
|
||||
const disk = Bun.file(path.join(grabDirNames().DATA_DIR, file.media_write_path || ""));
|
||||
const absolute = mediaFilePath({ write_path: file.media_write_path });
|
||||
const disk = absolute ? Bun.file(absolute) : null;
|
||||
|
||||
if (!file.media_write_path || !(await disk.exists())) {
|
||||
if (!disk || !(await disk.exists())) {
|
||||
return [{ type: "text", text: `[Attached file ${label} is missing on the server.]` }];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user