-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unhandledrejection should fire even for muted scripts #5051
Comments
Why can these not be CORS scripts? |
A similar (but not the same) issue was discussed in #2440. We currently have no plans to enable more security bypasses for non-CORS scripts, via onerror or onunhandledrejection or any other cross-origin information leakage vectors. Instead we're doing a lot of work on things like COOP/COEP to push more and more pages into a "CORS only" mode. So yeah, as @annevk indicates, the correct approach here is to mark your scripts as CORS (using the |
AMP is a library included on publisher's pages. Part of being "valid AMP" is following a set of restrictions on the HTML. Unfortunately, we didn't when we designed the original validator, we didn't understand that we needed Additionally, we do experimental opt-ins via cookies (you can opt into next week's production build). Adding Then there's also #2440 (comment).
I'm not arguing that we should take #2440's approach. Just the same "Script error." message without a stack trace, now passed to
What is the acronym here? Googling is very unhelpful… |
https://docs.google.com/document/d/1zDlfvfTJ_9e8Jdc8ehuV4zMEu9ySMCiTGMS9y0GU92k/edit explains COOP and COEP, though they won't help as much since they now require CORP and not CORS (I know). The problem with adding side channels is that everyone thinks their side channel is minor enough, but in aggregate all these bits become problematic. So yeah, I think a conservative stance on them is a better approach. |
It also directly calls into the globally installed error reporting function. Re: ampproject#25289 It seems HTML spec is unlikely to change: whatwg/html#5051
Soo many 4-letter
Let's examine the side channel, then. I (the attacker? I'm at least interested in listening to I load some cross-origin script. It's a non-cors request, so the script has the Somewhere, the script created a rejected So: const originalPromise = Promise;
const originalThen = Promise.prototype.then;
function Wrapper(resolver) {
const p = new originalPromise((resolve, reject) => {
let called = false;
function wrappedResolve(value) {
if (called) return;
called = true;
resolve(value);
}
function wrappedReject(err) {
if (called) return;
called = true;
reject(err);
maybeReport(err, p);
}
try {
resolver(wrappedResolve, wrappedReject);
} catch (e) {
wrappedReject(e);
}
});
p._chainEnd = true;
Object.setPrototypeOf(p, Wrapper.prototype);
return p;
}
Object.setPrototypeOf(Wrapper, Promise);
Object.setPrototypeOf(Wrapper.prototype, Promise.prototype);
Wrapper.prototype.then = function(f, r) {
this._chainEnd = false;
const p = originalThen.call(this, f, r);
const wrapper = Promise[Symbol.species];
Promise[Symbol.species] = null;
originalThen.call(p, undefined, (err) => maybeReport(err, p));
Promise[Symbol.species] = wrapper;
return p;
};
function maybeReport(err, p) {
setTimeout(() => {
if (p._chainEnd) {
console.error('unhandledrejection', err, p);
p._chainEnd = false;
}
}, 1);
}
Promise[Symbol.species] = function() {
return Wrapper;
};
Promise.prototype.constructor = Wrapper;
window.Promise = Wrapper; By patching It's admittedly not perfect. It'll be slow, and anything that has native access a few native things will create native promises instead of my species wrapper. I could wrap all the DOM APIs, but as soon as you Now back to me as the library author, who installed a
As a library author, I'm able to forbid As for the DOM APIs, I'm not really sure I care about someone who called So, now I have to choose detecting promise rejections (verify the correctness of my releases) and performance/ I can still get the errors, it just would have been nice to not have the browser fight me along the way. I think this is the same frustration Malte had in #2440 (comment), but the surface area is easier to wrap for |
You can do all that. Or you can add (I realize the deployment challenges are different.) |
Yes, we're going to try updating to But my point was that the protection (not exposing a redacted "Script error.") here is really ineffective, when I can attack the script in 50 lines (getting unredacted errors in the process). Things that would be more useful:
|
It also directly calls into the globally installed error reporting function. Re: #25289 It seems HTML spec is unlikely to change: whatwg/html#5051
Wraps promises in a special subclass that can detect unhandled rejections and report them. This sidesteps the issue with non-cors scripts entirely. See whatwg/html#5051 (comment)
…ject#25342) It also directly calls into the globally installed error reporting function. Re: ampproject#25289 It seems HTML spec is unlikely to change: whatwg/html#5051
It also directly calls into the globally installed error reporting function. Re: ampproject/amphtml#25289 It seems HTML spec is unlikely to change: whatwg/html#5051
It also directly calls into the globally installed error reporting function. Re: ampproject/amphtml#25289 It seems HTML spec is unlikely to change: whatwg/html#5051
It also directly calls into the globally installed error reporting function. Re: ampproject/amphtml#25289 It seems HTML spec is unlikely to change: whatwg/html#5051
It also directly calls into the globally installed error reporting function. Re: ampproject/amphtml#25289 It seems HTML spec is unlikely to change: whatwg/html#5051
Merging into #10514. It's possible one direction for resolving that issue is to take the approach mentioned here, but as I discuss there, I suspect loosening security boundaries won't be a high priority for anyone. |
Previous context in:
The AMP project was recently surprised that promise rejections that are unhandled did not fire an
unhandledrejection
event when the script is cross-origin.I understand the PII risk that lead to muting script errors to begin with, but we still expected to receive a "Script error." error. We have an alert setup to monitor for that error message and ping us whenever there is a spike.
So, I want to contest the "it's useless" reasoning for not firing any error when a promise rejection is unhandled. The raw number of muted errors that we receive is useful for telling us if something has gone horribly wrong with a release.
/cc @domenic
The text was updated successfully, but these errors were encountered: