Skip to content

Android WebView doesn't expose AllowFileAccess permissions #15604

@airandfingers

Description

@airandfingers

I want to disable file access within an Android WebView I'm creating using react-native's built-in WebView component.

The Android WebView docs say "File access is enabled by default.", and this is a security concern for my organization.

The react-native 0.31 docs mention a getWebViewHandle method that can be used to access the underlying WebView node; if this worked, then I could (presumably) write:

import { WebView, Platform } from 'react-native';
//...
var reactWebview = <Webview [props here] />
if (Platform.OS === 'android') {
    var webview = reactWebview.getWebViewHandle();
    console.log(webview.getAllowFileAccess()); // check AllowFileAccess setting
    webview.setAllowFileAccess(false); // disable file access
}

However, later versions of the react-native docs don't mention getWebViewHandle, and when I run code like this in react-native 0.44 on an Android device, I get this error:

webview.getWebViewHandle is not a function.

My questions are:

  1. How can we check if file access is enabled by default for the Android WebViews created by react-native's WebView component?

  2. How can we disable this file access? Would we need to extend the WebView class, or fork and modify react-native?

Thanks for your time!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions