QRCoder icon indicating copy to clipboard operation
QRCoder copied to clipboard

Ensure that an OTP's issuer and label values are escaped correctly

Open josh- opened this issue 3 years ago • 4 comments

Summary

This PR fixes/implements the following bugs/features:

  • [x] Creating an OTP with an issuer/label that contains a space or other restricted characters does not properly escape the issuer/label

What existing problem does the pull request solve?**

Currently, if you create an OTP with an issuer that contains a space, for example:

var oneTimePassword = new OneTimePassword {
	Issuer = "Google Google",
	Label = "[email protected]",
	Secret = "pwq6 5q55"
};

and then call ToString on that oneTimePassword, that will return:

otpauth://totp/Google Google:[email protected]?secret=pwq65q55&issuer=Google%20Google

(note the first "Google Google" is not escaped, like the second one in the issuer parameter)

which then looks like this in Google Authenticator after scanning the resulting QR code:

File

This PR resolves this issue by correctly escaping both instances of the issuer in the URL, which then appears correctly in Google Authenticator:

otpauth://totp/Google%20Google:[email protected]?secret=pwq65q55&issuer=Google%20Google

Test plan

Test cases have been added.

Closing issues

N/A

josh- avatar Mar 08 '22 04:03 josh-

I discovered the same problem yesterday, thank you for the fix! Also, MS Authenticator does not support unescaped URLs, so that fix is really important.

prvacy avatar Mar 09 '22 18:03 prvacy

Thanks for this fix, it addresses issue #375.

I suggest also escaping the Label value, since an email address can contain / and ? characters.

tom-156842 avatar Mar 10 '22 12:03 tom-156842

Thanks for this fix, it addresses issue #375.

I suggest also escaping the Label value, since an email address can contain / and ? characters.

Thanks @tom-156842, done 👍

josh- avatar Mar 15 '22 05:03 josh-

@codebude Do you have any update on when this fix will be released?

hdocsek avatar Oct 31 '22 03:10 hdocsek

All changes here look good. Generated QR codes scan properly with Google Authenticator. Tests have already been added :+1:

Shane32 avatar Apr 06 '24 23:04 Shane32