Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AuthenticationAPI - use base64encode which can deal with UTF8 passwords #1411

Merged
merged 5 commits into from
Mar 28, 2018
Merged

AuthenticationAPI - use base64encode which can deal with UTF8 passwords #1411

merged 5 commits into from
Mar 28, 2018

Conversation

himdel
Copy link
Contributor

@himdel himdel commented Mar 26, 2018

This is the same change as ManageIQ/manageiq-ui-classic#3682, except for SUI.


This adds 2 npm packages:

  • base64js - JS implementation of base64 which can deal with arbitrary encodings
  • text-encoder-lite - a shim for the TextEncoder api, useable for utf8 strings (even in IE)

and replaces the AuthenticationAPI use of $base64.encode with a custom base64encode function implemented using the 2 libraries.

This way, users can use passwords with unicode chars.

Note: on modern browsers, this will handle any unicode password, including emoji.
On IE, more modern unicode versions may not be fully supported (czech or japanese chars should be fine, emoji may not).

The difference:

btoa('babicka')
"YmFiaWNrYQ=="

base64encode("babicka")
"YmFiaWNrYQ=="

btoa('babička')
VM7832:1 Uncaught DOMException: Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.

base64encode("babička")
"YmFiacSNa2E="

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1527316

suffers from the same problem as window.btoa - can't handle unicode strings

https://bugzilla.redhat.com/show_bug.cgi?id=1527316
@himdel
Copy link
Contributor Author

himdel commented Mar 26, 2018

Testing:

add a user with special (unicode) characters in the password
try to log in :)

`window.btoa("sněhulák")` fails on InvalidCharacterError: String contains an invalid character

because it only expects latin1 chars

`$base64.encode` from `angular-base64` has the same problem.

We need to base64 encode the login:password pair even when the password uses non-latin1 chars :)

Implementation adapted from https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#Solution_2_%E2%80%93_rewrite_the_DOMs_atob()_and_btoa()_using_JavaScript's_TypedArrays_and_UTF-8

https://bugzilla.redhat.com/show_bug.cgi?id=1527316
AllenBW
AllenBW previously approved these changes Mar 26, 2018
Copy link
Member

@AllenBW AllenBW left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jumped in, checked it out, café is now a valid password!

LG2M Soon as travis is made happy (style things) will merge this in!

@AllenBW
Copy link
Member

AllenBW commented Mar 26, 2018

oh my, now those are annoying failures... lemme see what can be done to help out travis... 🤔

@himdel
Copy link
Contributor Author

himdel commented Mar 26, 2018

So.. this does fail with the PhantomJS launcher but not with Chrome launcher .. also, looks like this kind of import is not really used in SUI, almost everything exernal is required in client/app.js.

Also also, the specs kinda don't even run... looks like a runtime error early on, before any of the real code gets run (otherwise we'd see the promise either resolve, or catch, but if I add a .then(done, done), it still times out).

That leads me to think this could be some webpack config error (which we could see as not being able to login in older browsers) or a difference in how the specs are compiled (babel vs webpack?).

Either way, I'll try fixing in the morning by moving that import to client/app.js, and seeing if that works :).

@himdel
Copy link
Contributor Author

himdel commented Mar 27, 2018

Never mind, this (travis) is actually a different problem .. TextEncoder works just fine (in browsers that support it), but TextEncoderLite doesn't seem to have an encode method we rely on.

.. and that's because .. completely logically .. TextEncoderLite actually only exports TextDecoderLite when in module context :D

(problem described more in ManageIQ/manageiq-ui-classic#3687)

… the encoder

and explicitly say window.TextEncoder for when it doesn't exist
@miq-bot
Copy link
Member

miq-bot commented Mar 27, 2018

Checked commits https://github.com/himdel/manageiq-ui-service/compare/83273df13bd34afc633a07141450307c3c7719dc~...1384c4aeb94b957c62d3dade49ea8edbf8fe6694 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
0 files checked, 0 offenses detected
Everything looks fine. 🏆

@himdel
Copy link
Contributor Author

himdel commented Mar 27, 2018

@AllenBW looks like this fixes the specs, finally :) PTAL :)

package.json Outdated
@@ -112,6 +112,7 @@
"sprintf-js": "1.1.1",
"standard-loader": "6.0.1",
"style-loader": "0.20.2",
"text-encoder-lite": "git://github.com/coolaj86/TextEncoderLite.git#e1e031b",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DANG that's annoying... update the to the version we need... but don't release it, 1.0.2 looks like what we want... but its nowhere cept on the commit...

@himdel yah ok with rewording this as follows? "text-encoder-lite": "coolaj86/TextEncoderLite#e1e031b",

Copy link
Member

@AllenBW AllenBW left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌 💌 🎉

now everyone can use the password café!!!

@AllenBW AllenBW merged commit 0ae3d01 into ManageIQ:master Mar 28, 2018
@AllenBW
Copy link
Member

AllenBW commented Mar 28, 2018

@simaishi gooooood to get back! 👍 🌮

simaishi pushed a commit that referenced this pull request Apr 2, 2018
AuthenticationAPI - use base64encode which can deal with UTF8 passwords
(cherry picked from commit 0ae3d01)

https://bugzilla.redhat.com/show_bug.cgi?id=1562797
@simaishi
Copy link
Contributor

simaishi commented Apr 2, 2018

Gaprindashvili backport details:

$ git log -1
commit 98c826b38d0982221658923c5f6ee4392294e571
Author: Allen Wight <allen.b.wight@gmail.com>
Date:   Wed Mar 28 10:00:30 2018 -0400

    Merge pull request #1411 from himdel/password-utf-bz1527316
    
    AuthenticationAPI - use base64encode which can deal with UTF8 passwords
    (cherry picked from commit 0ae3d013fe0c6211080adb28f9c8130ba3ed1bdc)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1562797

@himdel himdel deleted the password-utf-bz1527316 branch May 18, 2018 11:35
@himdel
Copy link
Contributor Author

himdel commented May 18, 2018

simaishi pushed a commit that referenced this pull request May 18, 2018
AuthenticationAPI - use base64encode which can deal with UTF8 passwords
(cherry picked from commit 0ae3d01)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1562798
@simaishi
Copy link
Contributor

Fine backport details:

$ git log -1
commit 577c5533bdc412df10b2730c283253f36ff658ae
Author: Allen Wight <allen.b.wight@gmail.com>
Date:   Wed Mar 28 10:00:30 2018 -0400

    Merge pull request #1411 from himdel/password-utf-bz1527316
    
    AuthenticationAPI - use base64encode which can deal with UTF8 passwords
    (cherry picked from commit 0ae3d013fe0c6211080adb28f9c8130ba3ed1bdc)
    
    Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1562798

@simaishi
Copy link
Contributor

@himdel Can you please take a look at Travis failure in Fine branch?

https://travis-ci.org/ManageIQ/manageiq-ui-service/jobs/380680697

@himdel
Copy link
Contributor Author

himdel commented May 18, 2018

Aah, looks like the failure is just linters .. doing a FINE PR to fix... => #1434

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants