Skip to content

SEC: replace polyfill.io with Cloudflare equivalent - #16629

Merged
nstarman merged 1 commit into
astropy:mainfrom
tnfssc:main
Jun 28, 2024
Merged

nstarman merged 1 commit into
astropy:mainfrom
tnfssc:main

Conversation

@tnfssc

@tnfssc tnfssc commented Jun 28, 2024

Copy link
Copy Markdown
Contributor

Description

This pull request is to address the usage of polyfill.io in astropy/cosmology/_io/html.py file. This PR replaces the domain with a Cloudflare equivalent.

polyfill.io, a popular JavaScript library service, can no longer be trusted and should be removed from websites.

Source: https://blog.cloudflare.com/automatically-replacing-polyfill-io-links-with-cloudflares-mirror-for-a-safer-internet

  • By checking this box, the PR author has requested that maintainers do NOT use the "Squash and Merge" button. Maintainers should respect this when possible; however, the final decision is at the discretion of the maintainer that merges the PR.

@tnfssc
tnfssc requested a review from a team as a code owner June 28, 2024 05:58
@tnfssc
tnfssc requested a review from nstarman June 28, 2024 05:58
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see instructions for rebase and squash.
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Welcome to Astropy 👋 and congratulations on your first pull request! 🎉

A project member will respond to you as soon as possible; in the meantime, please have a look over the Checklist for Contributed Code and make sure you've addressed as many of the questions there as possible.

If you feel that this pull request has not been responded to in a timely manner, please send a message directly to the development mailing list. If the issue is urgent or sensitive in nature (e.g., a security vulnerability) please send an e-mail directly to the private e-mail [email protected].

@neutrinoceros neutrinoceros left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for taking care of this !
Let me ping @astropy/security-team for review

@pllim

pllim commented Jun 28, 2024

Copy link
Copy Markdown
Member

I think this only affected a doc example? So I'll defer to @nstarman . Thanks!

@nstarman nstarman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @tnfssc !

@nstarman
nstarman merged commit ed02689 into astropy:main Jun 28, 2024
@nstarman

Copy link
Copy Markdown
Member

We should definitely not be recommending a supply-chain attack to users 🙅

@hamogu

hamogu commented Jun 28, 2024

Copy link
Copy Markdown
Member

It should also be backported. Since this PR is already merged, how do we do that?

It also highlights the dangers of supply-chain attacks by using any js library. While the alternative in this PR (cloudflare) is trustworthy, we should keep our attack surface small by avoiding js code that's not absolutely necessary. In this particular case, I see why MathJax is needed, but do we really need polyfill at all?
If it just gives up some performance is one html code example or compatiblity with some really old browsers, then we might just remove it altogether.
I'm not an html/js expert, but it seems to me that just loading mathjax alone should be sufficient.

@neutrinoceros

Copy link
Copy Markdown
Contributor

Let me give it a try:

@meeseeksdev backport to v6.1.x

@lumberbot-app

lumberbot-app Bot commented Jun 28, 2024

Copy link
Copy Markdown

Awww, sorry neutrinoceros you do not seem to be allowed to do that, please ask a repository maintainer.

@neutrinoceros

Copy link
Copy Markdown
Contributor

I thought so. Well, now you know how to do it @hamogu :)

@tnfssc

tnfssc commented Jun 28, 2024 •

Copy link
Copy Markdown
Contributor Author

@hamogu Adding an integrity attribute to the script tags usually does the trick (example below). Even if there's a supply-chain attack, that maximum damage would be a broken application. Although this wouldn't work in case of polyfill.io since the JS it sends back depends on the User-Agent header. So the hash would be different depending on the browser 🤷.

<script
  src="https://example.com/example-framework.js"
  integrity="sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC"
  crossorigin="anonymous">
</script>

@hamogu

hamogu commented Jun 28, 2024

Copy link
Copy Markdown
Member

@meeseeksdev backport to v6.1.x

@pllim

pllim commented Jun 28, 2024

Copy link
Copy Markdown
Member

Thanks, @hamogu !

@nstarman , can we remove polyfill ?

pllim added a commit that referenced this pull request Jun 28, 2024
…629-on-v6.1.x

Backport PR #16629 on branch v6.1.x (SEC: replace polyfill.io with Cloudflare equivalent)
@hamogu

hamogu commented Jun 28, 2024

Copy link
Copy Markdown
Member

@tnfssc That approach also comes with a cost: While it prevents a supply-chain attack, it increases the maintenance burden because you can't just link to the "most recent bugfix version" of any library, but any update has to be manually validated. Of course, in some sense that's the whole purpose - but we're not js experts and in many cases will pretty much have to rubber-stamp whatever update the js library does. In addition, there is a significant time-lag. Astropy is released only every 6 months or so, and older versions are in use for years after that for a typical user. If we link to the "most recent version" all those old users will get the most recent bug and security fixes on any js library we link to - if we select a fixed version, that reduced supply-chain attacks like this, but might deliver libraries dangerously out of date by the time a user uses it.
(It's a bit less of a problem here, since this is more a documentation example and not code people run straight up, but there are a few other places in astropy where we interface or use with js libraries.)

@nstarman

Copy link
Copy Markdown
Member

@pllim I do think we can remove the link entirely as its only for compatibility with old browsers. https://docs.mathjax.org/en/latest/web/start.html#browser-compatibility

@pllim

pllim commented Jun 28, 2024

Copy link
Copy Markdown
Member

I vote to just remove it then. People nowadays can probably debug old browser problem via the power of Internet anyway.

hamogu added a commit to hamogu/astropy that referenced this pull request Jun 28, 2024
This grew out of discussion in astropy#16629, which replaced polyfill.io calls with a safer URL, but it is even more save to reduce the attack surface and remove polyfill altogether.
d-giles referenced this pull request in d-giles/astropy-abdufork Jul 26, 2024
This grew out of discussion in #16629, which replaced polyfill.io calls with a safer URL, but it is even more save to reduce the attack surface and remove polyfill altogether.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants