ADsafe – Making JavaScript Safe for Advertising
adsafe.org
adsafe.org
The requirement for subresource integrity would have to be recursive; if something has an integrity hash, anything it loads must also have an integrity hash. This prevents escaping via indirection.
This would break a lot of sites, of course. (HN would be fine; I just looked at page source.) But it probably wouldn't be much worse than running with Ghostery set to reject all known third party crap. It would definitely break a lot of hostile code.
Not sure if you could enforce this from a browser add-on; those usually don't get control early enough.
When I see HTTPS on a bank's backend/login page, i have the full expectation that what i am entering into the page cannot be seen, screen-scraped or intercepted by any third party. i want full encryption ONLY between me and the domain i see in the address bar.
The truth of the matter is, 100 third party scripts (cdns, analytics) can be [and usually are] injected from completely unrelated HTTPS domains, and the average user has absolutely no idea because there is never an indication of this from browser UIs. It is such a blatant violation of trust, and it's the norm!
I have no explanation except that advertisers insist on having direct access to the user-agent for tracking/click-through accountability.
Amusingly, Google has a canned answer for "iframe size": 200 pixels.
[1] http://stackoverflow.com/questions/819416/adjust-width-heigh...
Caja is Mark Miller's (supported by Google) attempt at making JS secure in browsers. This was implemented in the static analyzers used by Google in their Google Apps Script environment.
I am afraid the ad networks never wanted to play fair in the first place however.
JS browser engines themselves have to start providing strongly jailed sandboxes or the problem won't ever be solved (which is the goal, I'd argue; almost nobody has an economical incentive to fix the current state of affairs).
Sadly, having in mind how much Google loves its tracking, I don't think they'll ever help wich such an effort in Chrome. Mobile Chrome for example never got support for content blockers, unlike other mobile browsers like Apple's Safari, Samsung's Internet (Android) and several, less popular, others.
Maybe I'm missing something, but I don't see much that I would consider CS. This is an attempt at an engineering-style workaround.
> malware
They explicitly include support for spyware with the mouse{over,out} (etc) events.
> "ADsafe makes it possible to quickly and reliably determine that script is safe"
That's incredibly hard. It's easy to hide arbitrary code even if all you have is a lambda expression[1] ("function () {}" in JavaScript). There are so many sharp corners and inconsistent gotchas in JavaScript - multiplied by the variations between browsers - that identifying a "safe" subset of the language is extremely difficult (or maybe undecidable).
Douglas Crockford has been warned[2] almost a decade ago about the insecurity of mixing foreign JavaScript. The language simply wasn't designed with a security model sufficient for running untrusted code.
The important thing is to get the major browsers on board so that ad nets have to use it in order not to be blocked by default.
(Assuming that browsers have the browser users interests in mind, and not advertisers, this is sketchy at best in the case of Goog)
It came from CompSci people researching sandboxing of JavaScript. The papers on the left show that. They later turned it into a more engineered solution and convenient web site. Uncommon with CompSci projects. I give them extra credit for that whether the method pans out or not.
"They explicitly include support for spyware with the mouse{over,out} (etc) events."
Is that limited to the site it executes in or would it have visibility to all sites? And anything you see that would lead to code injection outside hardware-level attacks?
Ahh! That makes more sense.
> site it executes in
They seem to be allowing capture of UI events on any element that is selectable through their (limited) query interface. This is probably to allow interactive designs or ad-network "auction" tracking, but it's still spyware.
1. You like and trust the site 2. You want to support the site 3. You trust that the ads displayed on the site are non-intrusive (and if they cease to be that you start blocking ads again)
Does anyone know if such a model would generate enough revenue for the web as it exists today to stay in business? Because even if ads become less risky and less intrusive, there's no going back to allowing arbitrary ads from arbitrary sites. Your model seems about as promiscious as a responsible user could be going forward.
Parts like disallowing '_' at the start or end of a method because some browsers have dangerous methods don't fill me with confidence that this is a fool proof solution.
It seems like a compiler or iframe would be not only more comprehensive but also wouldn't butcher the language in ways that would make most code need to be adapted.
*fool proof
It was not unheard of ad companies probing, say, 0-day buffer overflows in browsers just to uncover botters.
Even a short time ago I saw something on here about a bank complaining Perfect Forward Secrecy would break their security.
Too bad. The world won't end, life goes on and they'll find a way to manage without. The ad networks will play ball if not doing so means they can't play at all.
The threat model changes quite a bit if we assume the attacker has a SOP exploit.
The problem is stated backwards though. Ads don't need JavaScript. But ad vendors will use whatever tools they can use, so if you let them use JavaScript, it will get used - and not just for malicious, track-the-shit-out-of-users purposes, but also as an enabler of general coding laziness (much like a lot of things are moved to JS today, because hey, free frameworks!).
So good luck trying to define a non-TC js-subset that allows to use these chars.
[ ] subscript operator except when the subscript is a numeric literal or string literal or an expression that must produce a number value. So expressions like a[i] are disallowed because we cannot statically determine that i is not one of the dangerous property names. But a[+i] is allowed, because +i will always produce a number.
You can't know if a script or program is going to be malicious without effectively executing it. It's almost impossible.
Just look at Anti-Virus, they've been trying forever and the best we have is research papers on immune-system-based AVs or AI-solutions.
Is JavaScript so hard to parse and analyze that this is impossible?
Of course, proving the jail is secure is awfully difficult but you can at least analyze it at your leisure, and you only have to do it once. I don't know if this is possible as a practical matter but the halting problem doesn't exclude the possibility.
JS is already turing complete but we are pretty sure websites don't upload our local files to strangers) short of using vulnerabilities). I don't understand how it would be hard to invent a subset of JS small enough to be possible to validate.
While this is not a bad start, assuming they work is a bad option from a security standpoint.
You should be pessimistic and always assume the sandbox will be broken and the API abused. Then you plan for that.
Assuming nobody will ever hack your product because it's perfect is harmful for any security product. Period.
If that doesn't work then we are all screwed anyway. I don't see it as a reason for not pursuing the idea of further shrinking the sandbox. A smaller language and smaller sandbox should theoretically be easier to validate than large langage running in a large sandbox.
If you ever think about "could we just block bad stuff?" then look at AVs and see if they can do it.
AVs have probably the highest amount of research to ensure they catch as much as possible but it still does not work.
There are some people with more extreme opinons that label every ad as malicious while others (like me) will not label everything ad-like as malicious by default.
Philosophical Issues makes complicate.
If the sandbox is leaky in either direction, the code can behave malicious again.
As some research showed, even if your sandbox is absolutely perfect, you can break out using memory corruption through cosmic rays (no kidding)
https://www.cs.princeton.edu/~appel/papers/memerr.pdf
So to almost 100% protect against malicious javascript code we would have to:
1) Create a JS subset that is verifiably safe
2) Create a Sandbox for that JS subset that is verifiably safe
3) Ensure the Sandbox cannot leak data, which is going to be hard since it's probably going to interact with the user in some way
4) Have the consumer run ECC memory to reduce the chance of Sandbox-Leakage
https://www.usenix.org/legacy/event/osdi08/tech/full_papers/...
The tricky part is only isolating the ads and not the functional parts of the website.
See for example https://en.wikipedia.org/wiki/Browser_hijacking for more on a kind of malware that injects ads into browsers.