From 98a653efb698c54c5dd1c1d30a272610864c2863 Mon Sep 17 00:00:00 2001 From: shuaiplus <2327005759@qq.com> Date: Tue, 17 Mar 2026 23:35:34 +0800 Subject: [PATCH] feat: add support for steam:// secrets in TOTP handling and corresponding tests --- webapp/src/lib/crypto.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/webapp/src/lib/crypto.ts b/webapp/src/lib/crypto.ts index e7ecc3d..5724005 100644 --- a/webapp/src/lib/crypto.ts +++ b/webapp/src/lib/crypto.ts @@ -171,10 +171,23 @@ function normalizeTotpSecret(secret: string): string { return secret.toUpperCase().replace(/[\s-]/g, '').replace(/=+$/g, ''); } +function parseSteamSecret(raw: string): string { + const match = raw.trim().match(/^steam:\/\/([^/?#]+)(?:[/?#].*)?$/i); + if (!match?.[1]) return ''; + try { + return normalizeTotpSecret(decodeURIComponent(match[1])); + } catch { + return normalizeTotpSecret(match[1]); + } +} + function parseTotpConfig(raw: string): { secret: string; steam: boolean } { if (!raw) return { secret: '', steam: false }; const s = raw.trim(); if (!s) return { secret: '', steam: false }; + if (/^steam:\/\//i.test(s)) { + return { secret: parseSteamSecret(s), steam: true }; + } if (/^otpauth:\/\//i.test(s)) { try { const u = new URL(s);