Microsoft-authentication-library-for-js: Problem when multibyte is included in JWTToken

Created on 5 Mar 2018  路  8Comments  路  Source: AzureAD/microsoft-authentication-library-for-js

For example, garbled characters will occur, such as when multibyte is included in the user name.

It is probably caused by calling atob.
https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/355dc1fb78651bece7806476879f9955f2cc61e0/src/Utils.ts#L67

enhancement

Most helpful comment

We also hit this, some of our users have scandinavian characters in their names, like 脰 and 脛.
Those get garbled when the Id token is decoded. @nehaagrawal is this on your roadmap?
If you are not going to fix this soon, would you accept a PR if I make one? :D

All 8 comments

HI @HiroyukiSako This is a known issue with window.atob() that it can't support unicode charcaters. There are different ways to solve this issue as per the MDN article( https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#The_Unicode_Problem) and below stackoverflow link.
https://stackoverflow.com/questions/30106476/using-javascripts-atob-to-decode-base64-doesnt-properly-decode-utf-8-strings
We need to discuss the fix in our team. I will report this as a bug for now.

We also hit this, some of our users have scandinavian characters in their names, like 脰 and 脛.
Those get garbled when the Id token is decoded. @nehaagrawal is this on your roadmap?
If you are not going to fix this soon, would you accept a PR if I make one? :D

@juunas11 Are you still open to submit a PR for this? We welcome contribution through PRs.

I'll try to look at it once I have some time. It's been pretty hectic lately so I can't promise a schedule ;)

Ok, i use the code found in decode-jwt on the jwt.ms and find the solution, but i just don't know how do the PR in the good way, if someone could help me or do it for me, here the solution:

https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/355dc1fb78651bece7806476879f9955f2cc61e0/src/Utils.ts#L95

need to be change for

return decodeURIComponent(atob(base64IdToken).replace(/(.)/g, function (m, p) {
        var code = p.charCodeAt(0).toString(16).toUpperCase();
        if (code.length < 2) {
          code = '0' + code;
        }
        return '%' + code;
      })); // jshint ignore:line

Before the fix:
image

After the fix:
image

i tried the solution by manually editing the Utils.js file found in ~node_modulesmsallib-commonjs

in hope that could help someone.

Tracking this with #596

@juunas11 I am trying to integrate this solution in our preview and will update the build details in the tagged #596. Please test and let us know if this works once we release the fix.

712 fixes this issue. As mentioned above, this will be in the next patch release from msal js, @juunas11 @ghost @jeverduzco @Davilink please feel free to pick the PR or the dev branch (which has the PR now) to test this until the patch is released.

Was this page helpful?
0 / 5 - 0 ratings