This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[webview_flutter] Fix platform exception on iOS 14+ when evaluating any JavaScript that evaluates to null or undefined. #4328
Closed
Closed
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
42bf7f0
[webview_flutter] Fix platform exception being thrown on iOS 14+ when…
BeMacized 22428f1
Merge branch 'master' into issue/66318
BeMacized da7d890
Merge remote-tracking branch 'origin/master' into issue/66318
BeMacized 2219761
Bring up to date with master 1/2
BeMacized 85400e0
Bring up to date with master 2/2
BeMacized File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason for wrapping this in an
eval? That seems like something that could cause side-effects. E.g., I believe CSP could completely break this.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason for this is that unlike
evaluateJavascript,callAsyncJavaScriptexecutes the given string as the body of an async function, rather than directly evaluating it. As such, it will only return any value that is explicitly returned, not the result of the string being evaluated. I useevalhere to make sure the behavior is identical to whatevaluateJavascriptdoes on iOS 13 and below and avoid a breaking change.Personally I have not been able to find any edge cases or side effects, but I've also not tried anything to do with CSP. If you have any examples of this maybe we can find a way around it?
The only other way I can think of to avoid these side effects, assuming they're a thing, is to fix this the other way around:(make
evaluateJavaScriptbehave likecallAsyncJavaScript), forcing everyone to explicitly return a value in their JS strings, and consider it a breaking change.Please let me know what you think. In the mean time I'll update this PR to move the fix to the separated iOS implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have significant experience with CSP, but my expectation is that if you tried to run this on a site with CSP enabled and without
unsafe-evalset, it would completely fail.That would be worrying, since it would mean you we bypassing the browser's enforcement of the site's security policy...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would that be better than the current behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, I'll see if I can give this a test tomorrow.
Assuming with "current behavior" you mean this branch rather than master: It would no longer require
evalto be used, at the expense of introducing a breaking change.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean master; isn't the issue you are trying to fix that a void return causes an error? Can't people already avoid that error right now by explicitly returning a value?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On master the platform exception can indeed be avoided by ensuring the given string evaluates to a non-null/non-undefined value.
E.g:
Snackbar.postMessage("...")Throws on iOS 14+.Snackbar.postMessage("...");1Does not.