Post

wouldn't it be nice if sites could share a cache of common js? ... stuff like react, or vue or svelte? 👉 there's an early stage proposal for cross-origin storage which enables exactly this. there are challenges but I think it's very interesting indeed

github.comGitHub - WICG/cross-origin-storage: Explainer for the Cross-Origin Storage (COS) APIExplainer for the Cross-Origin Storage (COS) API. Contribute to WICG/cross-origin-storage development by creating an account on GitHub.

19 reposts135 likes

The amount of pain that this would cause a regulated software product would be horrifically large without an ability to opt out entirely. It’s a great idea, but hashes aren’t sufficient anymore for where regulations are trending Now, combine this with attestation and you have me very interested :)

No it’s about being able to guarantee your supply chain. Having the runtime of your software not under your control has large implications for risk management and for producing the evidence required to demonstrate compliance

I want to make a comment about the fact that I JUST gave a talk about this on a stage we both spoke from, but to be fair I did say websites aren’t covered by the CRA without clarifying that there are plenty of other regulations that cover many industries (finance, healthcare, etc) that may apply.

It is opt-in/explicit and is a hash-indexed cache independent of where it was served from (you can serve react core from your origin but benefit if someone already shipped it and still trust the payload). Also has different security and pervasiveness considerations.

The evolution on the API helps... "We need a way to share 2GB models that will never be pervasive"... "If the security and privacy considerations can be figured out, why limit it to 2GB models"... Mostly driven by efforts to keep the web competitive with locked platforms while staying open.

Second order effects of this seem troubling. Do people stick on older versions because newer ones a late to the cache? Are the popularity of new libraries stymied due to not being in the cache? Do developers concede the DCE hit and ship wasted bytes just to get better cache hit ratio?

We used to have this many years ago by default. It was common to load jQuery et al from a public CDN so most people wouldn't have to download it again just for your site. Then marketers started using it to fingerprint. And hackers used it to poison cross-origin JS. The feature got removed sigh

It’s still a thing, Cloudflare has the big public CDN that does this now, but it was a product of its time. Internet Explorer had a limit of requests in-flight per server, so the extra DNS lookup cost was worth it. When that went away and we got HTTP/2, it mostly nullified the speed benefit

Right, but if you loaded the exact same jQuery from a different CDN, there was no cache hit. COS is hash-based, so now you can self host jQuery from swizecs-random-server dot com and still get a cache hit. The Public Hash List (github.com/WICG/cross-o...) proposal aims to mitigate the attacks.

github.comPublic Hash List as a way to solve the availability gating challenge · Issue #64 · WICG/cross-origin-storageThe explainer suggests vendors apply availability gating to decide whether a resource can be shared via the COS cache. The repo tomayac/public-hash-list contains some early explorations in the dire...

When we split the cache many years ago we anticipated a need for content-addressable storage (CAS) to improve caching. IIRC we envisioned enforcing k-anonymity locally, but big resource lists certainly help bootstrap. We also assumed it would just extend SRI, and just work for any SRI'd resource.

The Public Hash List can be augmented by local k-anonymity, right. But having a common baseline browsers (hopefully) agree on seems to make a lot of sense. The problem with "any SRI'ed resource" is that it includes supercookies a friendly neighborhood tracker would mint for you—so it can't be any.

These are the two big questions that jump out at me: 1. Why a separate API? Just extend SRI, to allow for the broadest and simplest use. 2. Why just published lists? If the browser sees a hash advertised in any form past a k-anonymity threshold then just use the CAS cache implicitly.

Due to the way caches are domain sharded for privacy, it doesn’t really work that well. Caches aren’t as effective as people had hoped. That, and a third party takeover of a CDN is too bigger security risk for most websites

Being hash-based helps us there. You can be sure about the content as long as the hash matches. A resource with hash abc123 put in the COS cache can be trusted, even if it came from sketchy-server dot com. The hash is checked before writing to COS.

Just peeped JS API in the readme and it reminded me of the Dropbox dropship hack where you could spoof file hash IDs to the API and get Dropbox to sync files that other users had in the cloud It immediately got abused as a way to distribute movies 😂

This attack would not be possible with COS because it's hash-based. Say you expect jQuery 1.2.3 with hash def456 and good-become-evil dot com /jquery1_2_3.js suddenly serves a modified resource, then said resource would not be allowed in the COS cache for the hash mismatch.

I recall seeing several proposals about popular library caches in the past decade. The general consensus was that it wasn’t worth it, and people didn’t want “blessed” libraries to gain an advantage that could hinder web progress. Is this proposal different in some way?

It's different in that it's hash-based, so we don't need to agree on the same CDNs (as when before the caches were isolated by origin). This means the cache hit rates would improve, as we work directly with fullstack frameworks like Nuxt, so they can consider COS at build time.

Super interesting! Wondering if this could/should live on the browser layer instead of an API layer? E.g. could a browser do the heavy lifting automatically? Like, cached/shared network responses. Not sure how it would decide which files to cache though.

Regarding which resources can be always shared, we're proposing the Public Hash List (github.com/WICG/cross-o...). Independently, on the origins you decide, you can still share other resources, like your proprietary code files on janis dot com and janis-marketing-site dot com for example.

github.comPublic Hash List as a way to solve the availability gating challenge · Issue #64 · WICG/cross-origin-storageThe explainer suggests vendors apply availability gating to decide whether a resource can be shared via the COS cache. The repo tomayac/public-hash-list contains some early explorations in the dire...

one part that requires bundler integration is that we have to ensure that the chunks are as byte-for-byte identical as possible. e.g. treeshaking, mangled export names, sourcemap comments, etc., need to drop out but then it's over to the browser when we expose the chunks as 'cacheable'

True! In my head it was as simple as "vue.js version x.y.z always ships as the same js file, with the same cryptographic hash, so it can be reused safely" but it's not that simple. And in any case a website has to dictate which files it actually needs. So maybe it's the right layer haha. Will try!

Thanks for trying! Yes, fullstack frameworks like Nuxt can really help increase the likelihood of cache hits by creating COS-friendly chunks of vendor code that will be the same for all Nuxt users on the same version. That being said, we plan to add support for tapping into COS from just `script`.

By working with fullstack frameworks like Nuxt, we can make sure they output COS-friendly chunks that are the same for all Nuxt users on the same version. This even can mean bundling together different unrelated vendor libraries that just happen to be all used by the framework.

I'm working with @tomayac.com to build bundler integration for this (currently a nuxt module + a vite plugin) I'd love to know: 1️⃣ if this sounds like a good idea you'd use 2️⃣ if you wanted to test it out and see if it might make a difference for you ... happy to help if you have questions! 🙏

github.comGitHub - danielroe/cross-origin-storage: Load shared dependencies from Cross-Origin Storage (COS).Load shared dependencies from Cross-Origin Storage (COS). - danielroe/cross-origin-storage

with so many supply chain issues lately, I would be very concerned about security with something like this. i love the idea for sure, but I personally lean toward security over convenience

that definitely helps. but (correct me if i’m wrong) verification of those hashes is not enforced, correct? so devs/vibe coders out there could just as easily skip that validation and use a corrupt resource…so the users of those systems are then at risk

right now testing it out means: ⚪ using the vite plugin or nuxt module ⚪ installing an 'unpacked' version of a chrome extension that polyfills this functionality ⚪ checking to see if your site still builds, and ideally comparing output _across_ several sites

chromewebstore.google.comCross-Origin Storage - Chrome Web StoreImplements the proposed Cross-Origin Storage API, letting sites share files with your consent for a faster and more efficient web.

I sort of get it. But wouldn't it be simpler to use SRI? You get the same hashing protection - but without lots of new syntax. If example,org has `src=whatever.js integrity="sha25-…” cross origin=*` why not let the browser serve up its cached version if the hashes match?

Suspect ad networks etc will use it as a cross site fingerprinting and tracking storage Know the spec mentions this but it’s mitigation involves browsers sharing what’s in the cache to a central resource