Add subresource integrity to the CDN assets in the GraphiQL and error pages - #8395
Add subresource integrity to the CDN assets in the GraphiQL and error pages#8395ofri-peretz wants to merge 2 commits into
Conversation
The GraphiQL page loads five assets from jsdelivr and the theme error page one from unpkg. Three of them carry no integrity attribute, including graphiql.min.js, three megabytes of script the page executes. react and react-dom already carry hashes but their URLs float on @17, so the hash and the URL disagree: the day jsdelivr resolves 17.0.3 the hash stops matching and the script silently does not load. The pinned hashes match 17.0.2 exactly, so pinning the URLs to 17.0.2 changes nothing today and removes that failure mode.
Adds eslint-plugin-node-security and enables require-dependency-integrity on the three templates this PR fixes. Without a rule the next CDN asset added without a hash ships unguarded, which is how the five in this diff got there. Scoped to those files: they are clean under the rule after this change and were not before, so it turns CI red only on a new one. Pinned to 4.13.1, published nine days ago, so it clears the cooldown: default-days: 7 in .github/dependabot.yml rather than asking for an exception. 5.x crosses that window in a couple of days and is a one-line bump whenever you want it.
|
Added the regression guard I'd left out of the first push.
I said in the description that your cooldown made this a separate PR. That was me checking the wrong number: I looked at the age of our latest release rather than asking which release already satisfies your policy.
So the pin clears your window as it stands. No exception requested, and no version newer than your own policy allows. 5.x crosses the same line in a couple of days if you'd rather have it — a one-line bump. Two things checked before proposing it:
|
What
Three assets loaded from a public CDN carry no
integrityattribute, and two more carry a hash pinned against a floating version range.cli-kit/.../templates/graphiql.tsx@shopify/polaris@12.10.0/build/esm/styles.csscli-kit/.../templates/graphiql.tsxgraphiql@3.0.4/graphiql.min.csscli-kit/.../templates/graphiql.tsxgraphiql@3.0.4/graphiql.min.jscli-kit/.../templates/unauthorized.tsx@shopify/polaris@12.10.0/build/esm/styles.csstheme/.../hot-reload/error-page.ts@shopify/polaris@13.9.2(unpkg)cli-kit/.../templates/graphiql.tsxreact@17,react-dom@17Without
integrity, whatever the CDN returns is what the page runs.graphiql.min.jsexecutes in a page that is already authenticated against the developer's store.The React case is a different bug in the same area. The URLs float on
@17while theintegrityhashes are fixed, so the two disagree by construction: the day jsdelivr resolves17.0.3, the hash stops matching and the script silently fails to load. The hashes in the file today are exactly17.0.2:which matches the file. So pinning the URLs to
17.0.2changes nothing today and removes the failure mode.How the hashes were produced
Each one is
sha384over exactly the bytes at the URL in the diff:crossorigin="anonymous"is required for SRI to be enforced on a cross-origin fetch. Both CDNs returnaccess-control-allow-origin: *on all five URLs, so the assets keep loading — I checked each one rather than assuming.Test plan
sha512hashes match17.0.2.access-control-allow-origin: *on all five CDN URLs, socrossorigin="anonymous"does not block them.error-page.jsisvi.mocked inhtml.test.ts, so no fixture needed updating.A follow-up I deliberately left out
I found this with an ESLint rule (
require-dependency-integrityineslint-plugin-node-security) and the natural companion to this PR is that rule, scoped to these three files, so the next CDN asset added without a hash fails lint rather than shipping.I did not add it here. Your
.github/dependabot.ymlsetscooldown: default-days: 7, and the current release is about a day old — proposing it now would be asking you to make an exception to your own policy in the same PR. I'm glad to open that as a separate PR once it has aged past your window, if it's of interest.🤖 Generated with Claude Code