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

html5shiv Vulnerability. #202

Open
prakash-patel opened this issue Sep 8, 2016 · 3 comments
Open

html5shiv Vulnerability. #202

prakash-patel opened this issue Sep 8, 2016 · 3 comments

Comments

@prakash-patel
Copy link

prakash-patel commented Sep 8, 2016

I use sonarQube for code analysis and it's gave me vulnerability for for html5shiv.js and html5shiv-printshiv.js file.

image

I updated code as below. Am i missing anything in below function.

ownerDocument.createDocumentFragment = function(h,f){
    return function(){ 
      var n=f.cloneNode(),c=n.createElement;
      h.shivMethods&&(
        // unroll the `createElement` calls
        getElements().join().replace(/[\w\-:]+/g, function(nodeName) {
          data.createElem(nodeName);
          data.frag.createElement(nodeName);
          return c("' + nodeName + '");
        }) 
      );
      return n;
    };
    }(html5, data.frag); 
  }

If you think this need to be change. I can create a pull request.

@zg
Copy link

zg commented Sep 15, 2016

Why don't you open the pull request and get feedback there instead?

prakash-patel pushed a commit to prakash-patel/html5shiv that referenced this issue Sep 15, 2016
@prakash-patel
Copy link
Author

prakash-patel commented Sep 15, 2016

@zg I have created PR. I am not sure how to test my changes.

@aborkowski
Copy link

You are indeed missing something: The original Function constructor is used here precisely due to the evaluation of the string arguments (which is what SonarQube complains about). This is intended in order to "unroll the createElement calls". The original function body is generated as text in order to inline function calls and thereby unroll a loop which would be required otherwise (and cache the state at function creation), with one call to c() (and thereby n.createElement()) for each element. Your version calls the function c() with the string ' + nodeName + ' (literally) for each element instead. Hope this explains it. Have a look at the version of the code before the change in 189e939.

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

3 participants