Skip to content

Commit b57e101

Browse files
huihuimoejeffliu27
authored andcommitted
fix issuer of OTP URI should be URI-encoded. (go-gitea#6634)
* fix: Issuer of OTP URI should be URI-encoded. follow this link https://github.com/google/google-authenticator/wiki/Key-Uri-Format . * filter unsafe character ':' in issuer * Use Replace rather than ReplaceAll
1 parent 046e0d0 commit b57e101

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

routers/user/setting/security_twofa.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,13 @@ func twofaGenerateSecretAndQr(ctx *context.Context) bool {
7474
if uri != nil {
7575
otpKey, err = otp.NewKeyFromURL(uri.(string))
7676
}
77+
// Filter unsafe character ':' in issuer
78+
issuer := strings.Replace(setting.AppName+" ("+setting.Domain+")", ":", "", -1)
7779
if otpKey == nil {
7880
err = nil // clear the error, in case the URL was invalid
7981
otpKey, err = totp.Generate(totp.GenerateOpts{
8082
SecretSize: 40,
81-
Issuer: setting.AppName + " (" + strings.TrimRight(setting.AppURL, "/") + ")",
83+
Issuer: issuer,
8284
AccountName: ctx.User.Name,
8385
})
8486
if err != nil {

0 commit comments

Comments
 (0)