Skip to content
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

Protecting Web pages from WebView attacks #2273

Closed
cyberphone opened this issue Dec 4, 2021 · 1 comment
Closed

Protecting Web pages from WebView attacks #2273

cyberphone opened this issue Dec 4, 2021 · 1 comment
Labels
Stale Type: feature request New feature or request

Comments

@cyberphone
Copy link

cyberphone commented Dec 4, 2021

WebView is a great solution for interacting with Web pages. However, WebView's ability to manipulate the DOM of external pages is not always desired.

Describe the solutions you came up with
I have a Web app that performs security related stuff and it turned out that it was trivial breaking it with code like the following:

const DestroyerScreen = ({ navigation }) => {
  const call = `
      document.getElementById('secureFrame').outerHTML = 'Destroyed!';
      true;
    `;
  return (
    <WebView
      style={{ margin: 0 }}
      source={{ uri: 'https://securityserver/login/web.html' }}
      onMessage={(event) => {
        callBack(event.nativeEvent.data);
        navigation.navigate('Home')
      }}
      injectedJavaScript={call}
    />);
};

Additional context
It should be possible constraining WebView through CSP or similar and restoring the built-in postMessage().

There is no need for injecting JavaScript code for returning data to WebView. The following is an extract of a Web page that can be invoked by WebView as well as being IFRAMEd by an ordinary Web application:

// Common API return method.
function returnData(jsonObject) { 
  if (window.ReactNativeWebView) {
    window.ReactNativeWebView.postMessage(JSON.stringify(jsonObject));
  } else {
    parent.postMessage(jsonObject, '*');
  }
} 
@github-actions
Copy link

github-actions bot commented Feb 5, 2022

Hello 👋, this issue has been opened for more than 2 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like still searching for solutions and if you found one, please open a pull request! You have 7 days until this gets closed automatically

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Stale Type: feature request New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant