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

Infinity cycling #129

Open
dsteb opened this issue Jul 16, 2012 · 1 comment
Open

Infinity cycling #129

dsteb opened this issue Jul 16, 2012 · 1 comment

Comments

@dsteb
Copy link

dsteb commented Jul 16, 2012

function xssPrevent(string, flag) goes in infinity loop if the text in input is something like «^1%».
It's because of escaping in for loop:

master/jquery.fcbkcomplete.js:lines 441-448:

      for(i = 0; i < string.length; i++) {
        var charcode = string.charCodeAt(i);
        if ((_key.exclamation <= charcode && charcode <= _key.slash) ||
            (_key.colon <= charcode && charcode <= _key.at) ||
            (_key.squarebricket_left <= charcode && charcode <= _key.apostrof)) {
          string = string.replace(string[i], escape(string[i]));
        }
      }

Javascripts hangs up and browser hangs up.

@dsteb
Copy link
Author

dsteb commented Jul 16, 2012

The problem is in wrong usage of «String.replace». If there are several occurancies of identical characters in string, «String.replace» is replacing only first always. And the cycle goes forever.

«^1%» ^ replaces to %5E, but last % replaces first % to %25 again, and we gets %255E%, and it's forever %2525E% ... %252525E% ....

The solution is replace character at position:
446: »»» string = string.replace(string[i], escape(string[i]));
446: string = string.substring(0, i) + escape(string[i]) + string.substring(i + 1);

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

No branches or pull requests

1 participant