Skip to content

Commit 66e0942

Browse files
committed
Properly encode label part of otpauth URL.
1 parent 255021c commit 66e0942

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

models/totp.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@ module.exports.create = (apiKeyValue, apiSecret, {issuer, label = 'SecretKey'} =
2020

2121
const otpSecrets = speakeasy.generateSecret({length: 10});
2222
let otpAuthUrlOptions = {
23-
'label': label,
23+
'label': encodeURIComponent(label),
2424
'secret': otpSecrets.base32,
2525
'encoding': 'base32'
2626
};
2727
if (issuer) {
2828
otpAuthUrlOptions.issuer = issuer;
29-
otpAuthUrlOptions.label = issuer + ':' + label;
29+
30+
// Note: The issuer and account-name used in the `label` need to be
31+
// URL-encoded. Presumably speakeasy doesn't automatically do so because
32+
// the colon (:) separating them needs to NOT be encoded.
33+
otpAuthUrlOptions.label = encodeURIComponent(issuer) + ':' + encodeURIComponent(label);
3034
}
3135

3236
const otpAuthUrl = speakeasy.otpauthURL(otpAuthUrlOptions);

0 commit comments

Comments
 (0)