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

Upgrade jquery from v1.7.1 to v1.9.0 to fix security vulnerability #1351

Closed

Conversation

floehopper
Copy link

Description

This is a lot less ambitious than #1294 and so hopefully shouldn't
introduce any problems. The idea is to do just enough to address the
CVE-2017-16011 security vulnerability.

I downloaded the jquery JS from here.

Completed Tasks

  • I have read the Contributing Guide.
  • The pull request is complete (implemented / written).
  • Git commits have been cleaned up (squash WIP / revert commits).
  • I wrote tests and ran bundle exec rake locally (if code is attached to PR).

This is a lot less ambitious than lsegal#1294 and so hopefully shouldn't
introduce any problems. The idea is to do just enough to address the
CVE-2017-16011 security vulnerability [1].

I downloaded the jquery JS from here [2].

[1]: GHSA-2pqj-h3vj-pqgw
[2]: https://code.jquery.com/jquery-1.9.0.min.js
@coveralls
Copy link

coveralls commented Sep 8, 2020

Coverage Status

Coverage remained the same at 93.439% when pulling 5cb6e69 on freerange:upgrade-jquery-from-v1.7.1-to-v1.9.0 into 2b16190 on lsegal:main.

@floehopper
Copy link
Author

Bump! Any chance of getting this merged? Thanks.

floehopper added a commit to freerange/mocha that referenced this pull request Sep 24, 2020
As per this commit [1] in this as yet unmerged PR [2].

Fixes CVE-2017-16011 security vulnerability [3].

I've also added a new rake task into the generate_docs prerequisites to
revert the jquery.js file generated by yard to the one in the git repo,
because until the yard PR is merged and released the jquery.js file
would be overwritten by the v1.7.1 version every time the docs were
generated.

[1]: freerange/yard@065d5dc
[2]: lsegal/yard#1351
[3]: GHSA-2pqj-h3vj-pqgw
@floehopper
Copy link
Author

In case anyone else has run into this problem, I've worked around it temporarily here: freerange/mocha@211098a.

@floehopper
Copy link
Author

I've only just noticed that jquery v1.9.0 introduces a problem with the "toggle source" links. I've downgraded jquery to v1.8.3 in my own project and that seems to fix the problem. I'm going to continue to investigate whether there's a way to upgrade back to v1.9.0, because that's the version that fixes the security vulnerability.

I've defined a jquery function called oldToggle closely based on the
code in the jquery-migrate plugin [1] as recommended here [2].

I'm sure this code could be made a lot better, but this seems to fix my
current problem.

[1]: https://github.com/jquery/jquery-migrate/blob/1.x-stable/src/event.js#L72-L103
[2]: https://github.com/jquery/jquery-migrate/blob/1.x-stable/warnings.md#jqmigrate-jqueryfntogglehandler-handler-is-deprecated
@floehopper
Copy link
Author

I've now pushed another commit which fixes the fact that the version of the jquery toggle function which takes 2 functions as arguments was removed in jquery v1.9.0. See the commit note for more details: e6d2492.

floehopper added a commit to freerange/mocha that referenced this pull request Sep 25, 2020
Ideally this would be fixed in yard. I've opened a PR [1] with the fix,
but haven't yet had any response at all - hence why I'm patching this.

Note that we now have to checkout both app.js & jquery.js after the docs
are generated in order to override the versions of these files generated
by yard.

[1]: lsegal/yard#1351
This fixes an error I was seeing in Chrome developer tools.
@floehopper
Copy link
Author

@lsegal:

Thanks for your response on Twitter.

From this tweet:

Without a full regression on YARD's many templates it would be hard to merge this as is. AFAIK there are many breaking changes between 1.7 and 1.9 that can affect downstream users, and the XSS vuln in question is kind of moot given that you can already inject JS via templates.

OK. In case it helps, I used the jQuery Migrate plugin to work out why the "view source" functionality wasn't working and the jQuery.fn.toggle(handler, handler...) deprecation warning was the only deprecation warning I saw on any of the pages I looked at. I wonder if it might be sufficient to use this tool more to more thoroughly check all page types...? That way at least we've moved to a slightly more recent version of jQuery.

And from this tweet:

The cleaner way to insulate from this issue would be to sanitize wherever selectors are used on user input, which seems to only happen on TOCs:

var proposedId = $(this).attr('toc-id');

Sounds sensible, but I'm not sure whether I'll have time to work on that any time soon.

@lsegal
Copy link
Owner

lsegal commented Sep 27, 2020

I wonder if it might be sufficient to use this tool more to more thoroughly check all page types...?

YARD can generate guide based templates too (via yard doc -t guide which generates only your README/extra-files), so you would have to check that template. The bigger issue is that others may have extended the default template and might be relying on more jquery features, so this would generally be seen as an unfortunate breaking change that affects downstream consumers.

It's more unfortunate that (a) YARD is a little outdated by using jQuery in general, and (b) jQuery has decided to make breaking changes in the middle of major versions, meaning in order to get this fix we'd need to incorporate breaking changes. That said, as mentioned above (and here) the actual impact of this jQuery vulnerability might be pretty low for YARD, a tool that already allows devs to put whatever they want inside a generated HTML document. It also may be that this vulnerability doesn't affect YARD at all. I cannot guarantee this, but it doesn't look like YARD generates selectors from user inputs in any place other than TOC id/toc-id attributes, which tend to be generated by other sanitizing tools (markdown, etc).

This probably affects sites that serve output a little more (like rubydoc.info), but even there we don't necessarily block people from customizing frontend, or at least, the goal is to allow developers to affect HTML up-to-and-including adding extra scripting into a page, so this might be something downstream consumers need to take on. Quite frankly, if XSS is a concern for user generated content, those who use YARD in this way should realize that the tool allows for quite liberal generation on content, including, for example, rendering a README.html file in your repo as an unsanitized HTML document in the generated output. Yes you read this right, any repo can contain a .html document that is rendered as is, scripts and all by simply adding it as an extra file. YARD is a generalized content generation tool, and as such, downstream users who are rendering arbitrary user-generated content need to be mindful of that fact and sanitize user input before it goes into the tool. (PS: you can use -m html to convert all your docstrings to bare HTML too. Fun stuff!)

Until this is patched for affected downstream usage, interested users could replace the jquery.js that is vendored in YARD with an updated version + relevant toggle patches as a post-step after running yard doc. Note that this doesn't solve the rendering .html extra files, of course, that is something downstream users would also have to address if they are not doing so.

@floehopper
Copy link
Author

@lsegal Thanks for explaining. Sorry not to respond sooner. I'm going to close this PR.

@floehopper floehopper closed this Dec 5, 2020
@adam12 adam12 mentioned this pull request Oct 16, 2024
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

Successfully merging this pull request may close these issues.

3 participants