Skip to content

Build your personal knowledge base with Trilium Notes

fix(oidc): address review feedback on the config transformers

perfectra1n1ed08062e1a4
diff --git a/apps/server/src/services/config.spec.ts b/apps/server/src/services/config.spec.ts
index c3e62d03a9..e5ce970253 100644
--- a/apps/server/src/services/config.spec.ts
+++ b/apps/server/src/services/config.spec.ts
@@ -200,6 +200,12 @@ describe("Config Service", () => {
config = (await import("./config.js")).default;
expect(config.MultiFactorAuthentication.oauthHttpTimeout).toBe(30000);
expect(config.MultiFactorAuthentication.oauthScope).toBe("openid profile email");
+
+ // Internal whitespace is normalized to single spaces even when 'openid' is already present.
+ process.env.TRILIUM_MULTIFACTORAUTHENTICATION_OAUTHSCOPE = "openid profile\t email";
+ vi.resetModules();
+ config = (await import("./config.js")).default;
+ expect(config.MultiFactorAuthentication.oauthScope).toBe("openid profile email");
});
it("should handle all Sync environment variables correctly", async () => {
diff --git a/apps/server/src/services/config.ts b/apps/server/src/services/config.ts
index 67b0f66ead..76983d5d59 100644
--- a/apps/server/src/services/config.ts
+++ b/apps/server/src/services/config.ts
@@ -483,7 +483,7 @@ const configMapping = {
iniGetter: () => getIniSection("MultiFactorAuthentication")?.oauthHttpTimeout,
defaultValue: 30000,
transformer: (value: unknown) => {
- const parsed = parseInt(String(value));
+ const parsed = parseInt(String(value), 10);
// express-openid-connect requires httpTimeout >= 500; fall back to the default otherwise.
return Number.isFinite(parsed) && parsed >= 500 ? parsed : 30000;
}
@@ -496,9 +496,9 @@ const configMapping = {
transformer: (value: unknown) => {
const trimmed = String(value).trim();
if (!trimmed) return 'openid profile email';
- // 'openid' is required by the OIDC spec; silently prepend it if the user forgot.
+ // Normalize internal whitespace, and prepend the spec-required 'openid' if the user forgot it.
const tokens = trimmed.split(/\s+/);
- return tokens.includes('openid') ? trimmed : `openid ${trimmed}`;
+ return tokens.includes('openid') ? tokens.join(' ') : `openid ${tokens.join(' ')}`;
}
}
},