Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

Commit 9d1e99f

Browse files
authored
Merge pull request #1686 from TriliumNext/refactor_remove-cookiePath
refactor(cookiePath): remove non-working cookiePath option
2 parents 9770d3e + b4a5f95 commit 9d1e99f

File tree

6 files changed

+55
-22
lines changed

6 files changed

+55
-22
lines changed

data-docs/config.ini

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,6 @@ trustedReverseProxy=false
3030

3131

3232
[Session]
33-
# Use this setting to set a custom value for the "Path" Attribute value of the session cookie.
34-
# This can be useful, when you have several instances running on the same domain, under different paths (e.g. by using a reverse proxy).
35-
# It prevents your instances from overwriting each others' cookies, allowing you to stay logged in multiple instances simultanteously.
36-
# E.g. if you have instances running under https://your-domain.com/triliumNext/instanceA and https://your-domain.com/triliumNext/instanceB
37-
# you would want to set the cookiePath value to "/triliumNext/instanceA" for your first and "/triliumNext/instanceB" for your second instance
38-
cookiePath=/
39-
4033
# Use this setting to set a custom value for the "Max-Age" Attribute of the session cookie.
4134
# This controls how long your session will be valid, before it expires and you need to log in again, when you use the "Remember Me" option.
4235
# Value needs to be entered in Seconds.

docs/User Guide/User Guide/Installation & Setup/Server Installation/2. Reverse proxy/Nginx.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Configure Nginx proxy and HTTPS. The operating system here is Ubuntu 18.04.
2727
ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
2828
ssl_prefer_server_ciphers on;
2929
access_log /var/log/nginx/access.log; #check the path of access.log, if it doesn't fit your file, change it
30-
30+
3131
location / {
3232
proxy_set_header Host $host;
3333
proxy_set_header X-Real-IP $remote_addr;
@@ -40,10 +40,31 @@ Configure Nginx proxy and HTTPS. The operating system here is Ubuntu 18.04.
4040
proxy_redirect http://127.0.0.1:8080 https://trilium.example.net; # change them based on your IP, port and domain
4141
}
4242
}
43+
4344
# This part is for HTTPS forced
4445
server {
45-
listen 80;
46-
server_name trilium.example.net; # change to your domain
47-
return 301 https://$server_name$request_uri;
46+
listen 80;
47+
server_name trilium.example.net; # change to your domain
48+
return 301 https://$server_name$request_uri;
4849
}
50+
```
51+
4. Alternatively if you want to serve the instance under a different path (useful e.g. if you want to serve multiple instances), update the location block like so:
52+
53+
* update the location with your desired path (make sure to not leave a trailing slash "/", if your `proxy_pass` does not end on a slash as well)
54+
* add the `proxy_cookie_path` directive with the same path: this allows you to stay logged in at multiple instances at the same time.
55+
56+
```
57+
location /trilium/instance-one {
58+
proxy_set_header Host $host;
59+
proxy_set_header X-Real-IP $remote_addr;
60+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
61+
proxy_set_header X-Forwarded-Proto $scheme;
62+
proxy_set_header Upgrade $http_upgrade;
63+
proxy_set_header Connection "upgrade";
64+
proxy_pass http://127.0.0.1:8080; # change it to a different port if non-default is used
65+
proxy_cookie_path / /trilium/instance-one
66+
proxy_read_timeout 90;
67+
proxy_redirect http://127.0.0.1:8080 https://trilium.example.net; # change them based on your IP, port and domain
68+
}
69+
4970
```

src/public/app/doc_notes/en/User Guide/User Guide/Installation & Setup/Server Installation/2. Reverse proxy/Nginx.html

Lines changed: 28 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/routes/csrf_protection.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { doubleCsrf } from "csrf-csrf";
22
import sessionSecret from "../services/session_secret.js";
33
import { isElectron } from "../services/utils.js";
4-
import config from "../services/config.js";
54

65
const doubleCsrfUtilities = doubleCsrf({
76
getSecret: () => sessionSecret,
87
cookieOptions: {
9-
path: config.Session.cookiePath,
8+
path: "/",
109
secure: false,
1110
sameSite: "strict",
1211
httpOnly: !isElectron // set to false for Electron, see https://github.com/TriliumNext/Notes/pull/966

src/routes/session_parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const sessionParser = session({
1111
resave: false, // true forces the session to be saved back to the session store, even if the session was never modified during the request.
1212
saveUninitialized: false, // true forces a session that is "uninitialized" to be saved to the store. A session is uninitialized when it is new but not modified.
1313
cookie: {
14-
path: config.Session.cookiePath,
14+
path: "/",
1515
httpOnly: true,
1616
maxAge: config.Session.cookieMaxAge * 1000 // needs value in milliseconds
1717
},

src/services/config.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export interface TriliumConfig {
3131
trustedReverseProxy: boolean | string;
3232
};
3333
Session: {
34-
cookiePath: string;
3534
cookieMaxAge: number;
3635
};
3736
Sync: {
@@ -84,9 +83,6 @@ const config: TriliumConfig = {
8483
},
8584

8685
Session: {
87-
cookiePath:
88-
process.env.TRILIUM_SESSION_COOKIEPATH || iniConfig?.Session?.cookiePath || "/",
89-
9086
cookieMaxAge:
9187
parseInt(String(process.env.TRILIUM_SESSION_COOKIEMAXAGE)) || parseInt(iniConfig?.Session?.cookieMaxAge) || 21 * 24 * 60 * 60 // 21 Days in Seconds
9288
},

0 commit comments

Comments
 (0)