- 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]>
44 lines
1.6 KiB
TypeScript
44 lines
1.6 KiB
TypeScript
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
|
import { mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import path from "node:path";
|
|
import walkRegularFiles from "./walk-regular-files";
|
|
|
|
let root = "";
|
|
let outside = "";
|
|
|
|
beforeAll(() => {
|
|
root = mkdtempSync(path.join(tmpdir(), "cobble-walk-"));
|
|
outside = mkdtempSync(path.join(tmpdir(), "cobble-walk-outside-"));
|
|
|
|
writeFileSync(path.join(outside, "secret.env"), "ENCRYPTION_KEY=x");
|
|
mkdirSync(path.join(outside, "folder"));
|
|
writeFileSync(path.join(outside, "folder", "db.sqlite"), "db");
|
|
|
|
mkdirSync(path.join(root, "reports"));
|
|
writeFileSync(path.join(root, "a.md"), "a");
|
|
writeFileSync(path.join(root, "reports", "b.md"), "b");
|
|
symlinkSync(path.join(outside, "secret.env"), path.join(root, "secret.env"));
|
|
symlinkSync(path.join(outside, "folder"), path.join(root, "linked"));
|
|
});
|
|
|
|
afterAll(() => {
|
|
rmSync(root, { recursive: true, force: true });
|
|
rmSync(outside, { recursive: true, force: true });
|
|
});
|
|
|
|
describe("walkRegularFiles", () => {
|
|
test("lists regular files in nested folders", () => {
|
|
const found = [...walkRegularFiles({ dir: root })].map((p) => path.relative(root, p)).sort();
|
|
|
|
expect(found).toEqual(["a.md", "reports/b.md"]);
|
|
});
|
|
|
|
test("never follows a symlink to a file or a folder", () => {
|
|
const found = [...walkRegularFiles({ dir: root })];
|
|
|
|
expect(found.some((p) => p.includes("secret.env"))).toBe(false);
|
|
expect(found.some((p) => p.includes("db.sqlite"))).toBe(false);
|
|
});
|
|
});
|