Repository navigation
Conversation
Reverts wxt-dev#2456. URL imports work again, but every import must now pin an integrity hash. A bare `url:` import is a build error with no opt-out. import 'url#sha256-kmHvs0B+OpCW5GVHUNjv9rOmY0IvSIRcf7zGUDTDQM8=:https://code.jquery.com/jquery-3.7.1.slim.min.js'; sha256/384/512 are supported, in base64 (the SRI format CDNs publish) or hex. This addresses the supply chain risk from wxt-dev#2229 and wxt-dev#2262: a compromised CDN can no longer put code into a build, since content that fails verification is never bundled or cached. - Unverified downloads are never written to the cache - Cached content is verified on read, so a poisoned cache can't slip through - A tampered download falls back to a verified cache entry when one exists - Errors print expected vs received hashes, in the encoding that was pinned - A missing hash prints the exact import line to paste Implements the checksum request from wxt-dev#1924.
The GA4 provider uses the Measurement Protocol, so there's no remote code and no hash to keep up to date. Drop the GA parenthetical from the feature comparison table, since remote code bundling isn't GA-specific.
| @@ -1,3 +1,6 @@ | |||
| // @ts-expect-error: URL imports not typed | |||
| import 'url#sha256-kmHvs0B+OpCW5GVHUNjv9rOmY0IvSIRcf7zGUDTDQM8=:https://code.jquery.com/jquery-3.7.1.slim.min.js'; | |||
There was a problem hiding this comment.
#2235
There's a problem for time to time, are you know about it, and it's fixed in this PR?
There was a problem hiding this comment.
I think I may have found the problem. The fetch could throw an error (like on network issues, ECONNRESET whatever) which would bypass the cache. Please see changes here: https://github.com/wxt-dev/wxt/pull/2514/changes#diff-7f5f341e02d05df8813c881b169aa49234938ff2877a50b7e02c0778d42258c7R79-R96
WXT wraps build failures in `Error('Failed to build ...', { cause })`, so
asserting on the message directly never matched. Use `rejects.toMatchObject`
against the cause, matching the pattern in auto-imports.test.ts.
`fetchCached` fell back to the cache when a request returned a non-2xx response, but not when the request itself rejected. A connection reset, TLS error, or timeout propagated straight out and failed the build, even with a good copy already cached. `isOnline` only checks that google.com resolves, so a host that is intermittently unavailable while you are otherwise online hits exactly this path. That is the flakiness reported in wxt-dev#2235. Refs wxt-dev#2235
The previous commit guarded the request itself, but not the body read. A connection that delivers headers and then dies partway through the response still threw past the cache, which is a common shape of the flakiness in wxt-dev#2235. Refs wxt-dev#2235
638995a to
1092f09
Compare
|
Another reason this was removed - do you have an example of a real dependency that needs to downloaded via a CDN or URL?
Also, instead of adding this back to the core package, what about making this a WXT module that people can install if they need this functionality (I'm still not convinced anyone does) This is what we did when we removed the |
|
I will wait for this to be resolved before doing the major release. |
Yes - for us its a feedback assistant chat tool, called Maven (https://maven.com) and they only distribute the js via CDN.
That's an option, I'll defer to you on it. :) FWIW, we definitely need this functionality |
A remote file changing upstream no longer interrupts anyone who already has a verified copy. The build keeps using the version that matches the pinned hash and warns that upstream moved, so the new file is picked up deliberately rather than silently. The build still fails when there is no matching cached copy, since there is nothing reviewed to build with. `.wxt` isn't committed, so CI starts cold and fails on drift rather than warning.
|
Thanks for sharing! Some other thoughts:
This is true, you would want to add tooling to check for updates. A simple script that downloads and checks if there's a git diff would do it - that's a few lines of shell scripting.
Yes, you should have a
Yes, it would be noisy, but that's normal for managing vendored dependencies.
So this works fine (most of the time) for URLs with a version identifier. But what about URLs without a version? Or what if an attacker overwrites a version, same URL, but different content? Or for your example, what happens if maven goes out of business and stops hosting the file? In both cases, it would be impossible to build your extension from a fresh computer unless you've committed the library to your repo. Because the SHA would have changed and you might never be able to download the old file again - causing your build to fail when it downloads something with a different SHA. But if you download it, commit it to the repo, it would still build, you'd have a runtime error instead. I think that's much better than depending on something that no longer exists. You have no way to verify the old behavior without the old file. There is no way to "lock" down a version to a specific URL and SHA without downloading the file and committing it. |
Thats true but its true of any dependency, including npmjs.org.
Well thats what the integrity is for - build should fail in that case and tell you.
I see your point, but in our case before we used WXT thats what we did, and the dependency would stop working randomly because we wouldn't be notified that the file changed, and the JS would stop working (couldn't communicate with their API, too old). All that being said though, I appreciate all the time you dedicate to this project, I'm happy to make this into a plugin if you'd like to keep it out of core, should be possible! |
Yeah, very true, very true. I see where you're coming from, but let me be stubborn one more time... This is a 700 line PR that I'll have to maintain, and it seems like your use case could be implemented in less than 20 lines: # vendor.sh
curl -o vendor/dep.js https://some.website.com/some-path# vendor-check.sh
./vendor.sh
if [ -n "$(git status --porcelain)" ]; then
echo "Versioned dependencies are out of date" >&2
exit 1
fi# .github/workflows/vendor-check.yml
on:
cron: @daily
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: action/checkout
- run: ./vendor-check.sh
- if: failure()
run: echo "Message slack, open PR, etc"At the cost of some ugly diffs. No need to verify hashes if you commit the file to the repo. Even if we decide we don't want to merge this, either apart of the core |
|
Yeah I think I see what you're saying! And if its just me using this functionality then I agree, best to not maintain it here. I'll pull it into a separate plugin, or some one-off scripting for the use case I need. Thanks! |
Overview
#2456 removed
url:imports over supply chain risk (#2229, #2262). The suggested alternative was to download the file and commit it to your repo. That works, but it has three problems:vendor/gtag.min.jscame from. You can write it down, but docs drift.This PR restores
url:imports with a required integrity hash. That keeps the thing that made vendoring safe, knowing exactly which bytes ship, without any of the three problems:sha256/384/512, in base64 (the SRI format CDNs already publish) or hex. Every URL import must pin a hash, with no opt-out, so the hole that motivated removal stays closed. A bare
url:import is now a build error that prints the exact line to paste, so migrating is copy/paste. Content that fails verification is never bundled or cached, and the cache is verified on read, so a poisoned.wxt/cachecan't slip through either.That also covers #1924 without a new command: build on a schedule in CI and you find out when a remote dependency drifts.
Manual Testing
packages/wxt-demopins a jQuery URL, sobun run buildexercises it. Then edit the import insrc/entrypoints/options/main.ts: dropping the hash, corrupting the hash, or usingmd5-each fails with a specific error, and swapping base64 for hex still builds.Unit tests cover parsing, hashing, verification, and the cache behavior.
e2e/tests/remote-code.test.tscovers valid, hex, missing, and mismatched hashes.Related Issue
This PR closes #1924.
Also relevant: #2262, #2229, and #2456 (the removal this reverts). Targets
major, since that's where #2456 landed and this is breaking.