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

URI malformed error during base64 encoding #530

Closed
sanex3339 opened this issue Jan 27, 2020 · 9 comments
Closed

URI malformed error during base64 encoding #530

sanex3339 opened this issue Jan 27, 2020 · 9 comments

Comments

@sanex3339
Copy link
Member

sanex3339 commented Jan 27, 2020

var foo = '\ud801\ud804-';

when encodeUriComponent

@sanex3339 sanex3339 added the bug label Jan 27, 2020
@sanex3339
Copy link
Member Author

Anyone have a idea how to fix this when this string is passed to `encodeUriComponent'?

@zamotkin
Copy link
Member

I can review today.

@zamotkin
Copy link
Member

@sanex3339 I can't understand how did you receive such a string, but you can try to strip invalid surrogate pairs by something like this:

function stripUnmatchedSurrogates (str) {
    return str.replace(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])/g, '').split('').reverse().join('').replace(/[\uDC00-\uDFFF](?![\uD800-\uDBFF])/g, '').split('').reverse().join('');
}

@cliffhall
Copy link

I ran into a similar problem, and was getting URI Malformed error when doing a production build of my react app using webpack-obfusicator. I have two apps actually and one did not have the problem but the other did. In the app that did, I was basically redoing the configuration that I had on the one that worked.

When I hit the error, I just started commenting out likely suspects in the JavascriptObfusicator configuration. I found quickly that it was stringArrayEncoding: "base64" causing the issue. The 'fix' turned out to be setting splitStrings: false.

Cheers, and thanks for such an awesome tool!

@sanex3339
Copy link
Member Author

Hi. @cliffhall can you show a small example here https://obfuscator.io/ with enabled stringArrayEncoding and splitStrings?

@cliffhall
Copy link

Unfortunately it’s a large app and I have no idea what specifically broke and caused the error.

@msheakoski
Copy link

msheakoski commented Sep 29, 2020

Here is how to reproduce:

  1. Visit https://obfuscator.io
  2. Use the following code for the input: "12😃45"
  3. Change String Array Threshold to: 1
  4. Change String Array Encoding to: Base64
  5. Enable: Split Strings
  6. Change Split Strings Chunk Length to: 3
  7. Click the Obfuscate button
  8. Output should be: URIError: URI malformed

It looks like the combination of "Split Strings Chunk Length" and "Base64" is not correctly handling multibyte characters if they occur on a chunk boundary. 😃 is composed of 2 unicode sequences, \uD83D and \uDE03. With a chunk length of 3, this particular string ends up being split into 12\uD83D and \uDE0345

@sanex3339
Copy link
Member Author

Ok. Will fix it using https://github.com/sallar/stringz

@sanex3339
Copy link
Member Author

Fixed in 2.4.2

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

No branches or pull requests

4 participants