Skip to content

Build your personal knowledge base with Trilium Notes

fix(login): keep the failed-logout redirect inside a proxied subpath

Elian Doran5bf87f831a0f
diff --git a/apps/server/src/routes/error_handlers.ts b/apps/server/src/routes/error_handlers.ts
index 6bbc3b5c15..343c692eab 100644
--- a/apps/server/src/routes/error_handlers.ts
+++ b/apps/server/src/routes/error_handlers.ts
@@ -52,8 +52,9 @@ function register(app: Application) {
// A logout form is a top-level navigation so OIDC redirects can leave the origin.
// Keep validation and provider failures inside the app instead of rendering an error body.
+ // "." resolves to the directory holding /logout, which keeps a reverse proxy's path prefix.
if (isLogoutFormNavigation(req)) {
- res.redirect("..");
+ res.redirect(".");
return;
}
diff --git a/apps/server/src/routes/transport.spec.ts b/apps/server/src/routes/transport.spec.ts
index cacd86745c..4ef7263111 100644
--- a/apps/server/src/routes/transport.spec.ts
+++ b/apps/server/src/routes/transport.spec.ts
@@ -79,6 +79,17 @@ describe("Route transport & middleware", () => {
.expect(302);
});
+ it("returns a failed logout form navigation to the app, keeping any prefix", async () => {
+ // "." resolves against the request URL, so /trilium/logout lands on /trilium/ rather
+ // than the origin root; ".." would drop the prefix and strand the user outside the app.
+ const res = await supertest(app).post("/logout")
+ .type("form")
+ .set("Accept", "text/html")
+ .send({ "x-csrf-token": "bogustoken1234567890" })
+ .expect(302);
+ expect(res.headers.location).toBe(".");
+ });
+
it("returns a 404 body for an unknown route", async () => {
const res = await supertest(app).get("/this-route-does-not-exist").expect(404);
expect(res.body.message).toBeTruthy();