Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(server): custom resource provider gated under scripting enabled
Elian Doranfc4f981a24ca
diff --git a/apps/server/src/routes/custom.spec.ts b/apps/server/src/routes/custom.spec.tsindex ab6869f85a..61da40bac5 100644--- a/apps/server/src/routes/custom.spec.ts+++ b/apps/server/src/routes/custom.spec.ts@@ -84,4 +84,31 @@ describe("Custom request/resource handlers", () => {const res = await supertest(app).get("/custom/no-such-path").expect(404);expect(res.text).toContain("No handler matched");});++ // A resource provider executes no code — it only serves a note's static content. It should+ // therefore remain accessible even when backend scripting (code execution) is disabled, unlike+ // customRequestHandler. Currently the /custom route gates the whole surface behind the scripting+ // toggle, so this fails until the resource provider is decoupled from backendScriptingEnabled.+ it("serves a custom resource provider note even when backend scripting is disabled", async () => {+ config.Security.backendScriptingEnabled = false;++ try {+ const res = await supertest(app).get("/custom/resource").expect(200);+ expect(res.text).toContain("resource body");+ } finally {+ config.Security.backendScriptingEnabled = true;+ }+ });++ // The flip side of the decoupling: a request handler executes code, so it must stay gated.+ it("rejects a custom request handler when backend scripting is disabled", async () => {+ config.Security.backendScriptingEnabled = false;++ try {+ const res = await supertest(app).get("/custom/greet/world").expect(403);+ expect(res.text).toContain("Backend script execution is disabled");+ } finally {+ config.Security.backendScriptingEnabled = true;+ }+ });});diff --git a/apps/server/src/routes/custom.ts b/apps/server/src/routes/custom.tsindex bb93b27325..942c876bae 100644--- a/apps/server/src/routes/custom.ts+++ b/apps/server/src/routes/custom.ts@@ -7,11 +7,6 @@ import sql from "../services/sql.js";function handleRequest(req: Request, res: Response) {- if (!isScriptingEnabled()) {- res.status(403).send("Backend script execution is disabled on this server.");- return;- }-// handle path from "*path" route wildcard// in express v4, you could just add// req.params.path + req.params[0], but with v5@@ -65,6 +60,13 @@ function handleRequest(req: Request, res: Response) {}if (attr.name === "customRequestHandler") {+ // Custom request handlers execute backend scripts, so they remain gated behind the+ // scripting toggle. Resource providers only serve static note content and are not.+ if (!isScriptingEnabled()) {+ res.status(403).send("Backend script execution is disabled on this server.");+ return;+ }+const note = attr.getNote();getLog().info(`Handling custom request '${path}' with note '${note.noteId}'`);