Skip to content

Commit d4810be

Browse files
committed
fix: handle header array edge case and add URL scheme validation for SSRF mitigation
1 parent cf7ac03 commit d4810be

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

apps/server/src/services/auth.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,11 @@ function checkCredentials(req: Request, res: Response, next: NextFunction) {
168168

169169
// Verify TOTP if enabled
170170
if (totp.isTotpEnabled()) {
171-
const totpToken = req.headers["trilium-totp"] || "";
171+
const totpHeader = req.headers["trilium-totp"];
172+
const totpToken = Array.isArray(totpHeader) ? totpHeader[0] : totpHeader;
172173
if (typeof totpToken !== "string" || !totpToken) {
173174
res.setHeader("Content-Type", "text/plain").status(401).send("TOTP token is required");
174-
log.info(`WARNING: Missing TOTP token from ${req.ip}, rejecting.`);
175+
log.info(`WARNING: Missing or invalid TOTP token from ${req.ip}, rejecting.`);
175176
return;
176177
}
177178

apps/server/src/services/setup.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ function getSyncSeedOptions() {
112112
}
113113

114114
async function checkRemoteTotpStatus(syncServerHost: string): Promise<{ totpEnabled: boolean }> {
115+
// Validate URL scheme to mitigate SSRF
116+
if (!syncServerHost.startsWith("http://") && !syncServerHost.startsWith("https://")) {
117+
return { totpEnabled: false };
118+
}
119+
115120
try {
116121
const resp = await request.exec<{ totpEnabled?: boolean }>({
117122
method: "get",

0 commit comments

Comments
 (0)