-
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
"Script error." message in window.onerror makes bad DevExp trade off #2440
Comments
I recommend filing a (security) bug against Edge. I don't see why we would potentially compromise security of users or complicate JavaScript's processing model when the alternative is rather easy to deploy and works everywhere. |
What is the added benefit of the error obfuscation for non-initial execution errors? Since JS can instrument all other stack entry points this protection effectively only applies to initial execution. Try even googling for "Script error.". There are 2 obscure blog posts explaining what is going on and a lot of confused developers that wonder why their stuff just doesn't work after they deployed using a CDN in production. Meanwhile people use the mentioned above stack entry point instrumentation to fix things mostly for them (See Angular Zones, |
I'm not entirely sure, but I don't think the burden is on me to proof that it doesn't reveal any new data. I understand that running into this is frustrating, but the answer here is CORS and it doesn't make JS slower for everyone everywhere. Poking more holes in the same-origin policy is not a good solution. |
The answer to the question is that there is no benefit as proven in subsequent paragraph. If spec simplicity is more important than developer experience, sure I understand your point, but some developers may disagree. |
I don't see how that's true though, e.g., with closures. |
I don't think this is warranted. |
@annevk Do you have an example for how to run JS in a browser outside of script tag injection's immediate side effect that cannot be wrapped as an entry point as in const orig = window.setTimeout;
window.setTimeout = function(fn, timeout) {
orig(function() {
try { return fn.apply(this, arguments) } catch (e) { console.log(e.stack) /* full stack trace */ }
}, timeout)
}; I'm not aware of a way that JS gets run outside of initial execution where a sufficiently motivated attacker couldn't change it so that they get to wrap that execution in a |
If the foreign script uses Promise.then() or registers event listeners? |
You can (and this is what all the tools do), just override Of course, this makes execution slower since every API call is going through an extra closure and try-block. |
If that leaves no holes and the exception you get is otherwise identical that is somewhat compelling. Did you talk to Chrome's security team about this? |
We're certainly not going to poke more holes in the same-origin policy. Please use CORS. |
@annevk Yes, talked to @mikewest. https://bugs.chromium.org/p/chromium/issues/detail?id=701371#c1 @domenic Not proposing to poke a new hole. Just make an existing hole benefit developers instead of only attackers. |
So a few thoughts:
Paging @syg and @jswalden for this last bit and more hard data on what the state of mitigations I mention in item 3 is. |
FWIW we use onerror handling in React and it's very confusing for people that it doesn't work cross-origin. Especially on sites like jsfiddle style sites that might need cross-origin in place without CORS. However, the main reason we use this instead of try/catch everywhere is because we don't want to force people to use "Break On Caught Exceptions" in debuggers. Because try/catch is also used by libraries to do feature detection and "Break On Caught Exception" is too noisy because of it. |
Can you explain why jsfiddle cannot use the basic safe CORS protocol setup? |
I don't know why TBH. The last one we saw was codesandbox.io. I haven't evangelized all of them to update so I just gave up. |
@domenic CORS also requires a |
The core of the problem is that it'll just work in the normal case and you won't notice until you get an error and then it's a broken experience. You can tell people to put stuff in all their fiddle hosts, CDNs, fiddle examples and tutorial examples but they'll keep getting dropped because they do nothing to enable the primary functionality. |
No, that's only used if you want to enforce disallowing opaque cross-origin scripts. If the correct CORS headers are set, the response is still CORS-same-origin, and so errors are not muted, regardless of the crossorigin="" attribute (which only affects the request, not the response). |
Hmm, I might be wrong, I'm having a hard time following the state mutations throughout the Fetch algorithm. Regardless, we've at least fixed this mess for module scripts, where CORS is always required, so we won't run into the problem @sebmarkbage mentions. I think that's our long-term solution here. |
@domenic Maybe then we could clarify the spec here to not require the |
No, we require explicit client-side opt-in (be it |
I already outlined my preferred solution. Right now we are are hurting
developers with a s solution that is overzealous given the thread model.
Module scripts are years from reality. Fixing the status quo is well worth
the effort.
…On Jul 29, 2017 12:14 AM, "Anne van Kesteren" ***@***.***> wrote:
If the correct CORS headers are set, the response is still
CORS-same-origin, and so errors are not muted, regardless of the
crossorigin="" attribute (which only affects the request, not the response).
No, we require explicit client-side opt-in (be it crossorigin or
type=module). There's no "maybe CORS" and I don't think we should add
that. It's already confusing enough.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#2440 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAFeT_stCfgq-sxwlPlOFoU3OnT6Tf1Zks5sStvUgaJpZM4MfVuZ>
.
|
Just for the record: Module scripts would have the same issue even more same origin requests. |
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. |
When a script that isn't served from the same origin as the document throws an error, then the error message exposed to window.onerror is "Script error." and the stack trace is empty.
This is to spec and it can be worked around in some browsers by
While the behavior is understandable, it leads to bad developer experience in practice and is overzealous with respect to the threat model.
My understanding of the threat model is that it is worried about attackers circumventing CORS restrictions by e.g. script src-ing a privileged file from a cross origin and then gaining insights from the error message that happens because the file is not valid JavaScript.
I think browsers could successfully prevent the threat while maintaining most of the developer experience:
Since SyntaxErrors are essentially irrelevant in JavaScript production monitoring, these changes would reinstate the ideal developer experience while maintaining the desired protection against data leaks.
As an additional data point: Safari& Chrome seem to follow the spec but Edge & IE do not handle cross origin errors specifically at all and provide full exception info.
The text was updated successfully, but these errors were encountered: