-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
Is eval strictly necessary? #47
Comments
Hi there, Shortly after I added the new Thanks, |
Seems like it was added in #45 to stop bundlers from optimizing it away. |
Interesting. Perhaps we can avoid this by doing a parseInt call on the strings, then passing those to function feid (): number {
let toFixedEngineID = 0;
let neg = parseInt("-1");
try {
neg.toFixed(neg);
} catch (e) {
toFixedEngineID = (e as Error).message.length
}
return toFixedEngineID
} To know for sure if this works, we'd need to try it on detectIncognito's bundler. (Does it use one?) |
@JudahGabriel I committed that snippet, we'll see if that causes any issues. If it doesn't, I'll push it to npm. |
Is
eval
strictly necessary in this library?This library uses eval("(-1).toFixed(-1);") to trigger an exception and determine the browser from the exception message length.
What's the problem? Most secure web apps have a Content Security Policy (CSP) that prevents
eval
. Indeed, at many big corporations, such as GitHub and Microsoft, CSPs that prevent eval is required. Try it now in your browser: hit F12 and in the console, pasteeval("(-1).toFixed(-1);")
- you'll see GitHub prevents it:Looking at the code closer, the real exception is calling toFixed(-1). And this library is using the exception message length to determine the browser. It's not at all clear why
eval
is needed at all. Is it?The text was updated successfully, but these errors were encountered: