An introduction to JavaScript-based DDoS
blog.cloudflare.com
blog.cloudflare.com
* Loading common resources is fast - already loaded by other sites
* If resource isn't cached, the browser doesn't need to open a second connection to a CDN, it can grab the file from the same site
* Proliferation of multiple CDNs ceases to be an issue, as each does not have separate browser cache
* Evil CDNs cannot provide bad JS as integrity is checked and the site isn't relying on a CDN anyway
* If a CDN goes down, your site isn't broken, because the fallback can be to a local file
Would work something like this:
<script src="hash-lookup:jquery-1.10.2.min.js,sha256-C6CB9UYIS9UJeqinPHWTHVqh/E1uhG5Twh+Y5qFQmYg=,static/jquery-1.10.2.min.js"></script>
Browser checks cache for a file with a matching name and hash, ignoring site (this looks in a special cache for files loaded with hash-lookup, you can't check for arbitrary web resources). If there is one, it's used. If not, it loads it from the fallback URL, checks the hash, and catches it.Now, this would create potential for hash collision attacks. However:
* If hash algorithms found to be weak, browsers can disable them
* Unlikely to be effective given users will usually already have a file cached
If a hash is weak then the browser can disable it. The only consequence is that the src fallback will now be used every time.
No it's not. SRI means you keep relying on multiple CDNs, so you keep having cache fragmentation, CDN unavailability continues to be a problem, and uncached items still require a second connection.
On a side note: there is no need to match the file name, only the hash matters.
[1] http://www.w3.org/TR/SRI/#conformance: "Conformance requirements [...] can be implemented in any manner, so long as the end result is equivalent"
Yes, but having names prevents accidental collisions.
All you need to do is to have an option to migrate to stronger hashes the day attacks start weakening SHA256, which is why SRI uses a "sha256-" prefix so we can migrate to stronger hashes when needed.
IF you're able to create a hash collision and IF you're able to deliver (for example) jquery first, your malicious version would be cached and injected into every page that uses the targeted jquery version and makes use of this feature.
This isn't simple, but still an attack vector with huge impact, if successful.
Also:
* If you keep the file forever, you've poisoned this hash forever. If you clear it sometimes, there's a short time window in which you can insert your malicious version.
* If you target an old version of jquery, you're increasing the chance the browser hasn't seen this file yet or forgot about it, to mitigate the poison-forever issue.
If I had this capability I wouldn't waste it on injecting javascript into web pages. I'd create forged browser upgrades and go from there.
The only way to get the wrong hash onto sites is to actually publish it on the authoritative server. That's not cache poisoning, that's a malicious official version.
As for your suggestion... the browser can easily cache the CDN resource as it does now... without a complicated new protocol. The main difference being the integrity check. All of that said, as others have suggested, another nicety would be a local-src="" url, that could be used as a fallback if the cdn resource fails the integrity check.
I know. But the use of CDNs has problems (CDN dies, cache fragmentation across multiple CDNs, extra connections).
This would also work pretty well for a multi-site reverse-proxy like Cloudflare, where it could hit cache for commonly-used asset URLs even if your site in particular was evicted. Hey, wait a minute...
Here is the SRI working draft - http://www.w3.org/TR/SRI/
Here is a tool for generating SRI hashes - https://srihash.org/
I think per-IP rate limiting is one of the best ways of preventing DDoS - stop answering clients that issue too many requests in a short time and they will probably choke on their own open-connections limit very soon as the connections start timing out, since the packets are coming from the browser initiating TCP connections and not a dedicated packet-spewing program.
Also one time a myspace template linked to pictures on some guys website and became really popular. He decided to goatse the myspace profiles who were hot-linking his photos.
Embedding scripts that are hosted behind cloudflare is a terrible idea though.