Skip to content

[Android] Add a Platform Specific to allow disable js execution on the WebView #29446

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

Merged
merged 5 commits into from
Jun 11, 2025

Conversation

jsuarezruiz
Copy link
Contributor

Description of Change

Introduced a Platform-Specific that provides the ability to disable JavaScript execution within the Android WebView.

This change is part of an ongoing .NET MAUI threat modeling initiative aimed at identifying potential security risks and implementing proactive improvements to enhance application safety. This changes provides flexibility to enforce strict security policies based on app requirements.

@PureWeen PureWeen added this to the .NET 10 Planning milestone May 20, 2025
@jsuarezruiz jsuarezruiz marked this pull request as ready for review May 28, 2025 11:14
@Copilot Copilot AI review requested due to automatic review settings May 28, 2025 11:14
@jsuarezruiz jsuarezruiz requested a review from a team as a code owner May 28, 2025 11:14
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds a new Android-specific API to enable or disable JavaScript execution in WebView, supporting a security-hardening initiative.

  • Defines a bindable JavaScriptEnabled property and fluent extensions on Android platform configuration.
  • Hooks up handler mapping (MapJavaScriptEnabled) and runtime platform extension (UpdateJavaScriptEnabled).
  • Updates PublicAPI listings for the newly added methods and properties, and adds a sample toggle in the WebView gallery.

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Controls/src/Core/WebView/WebView.Mapper.cs Registered the JavaScriptEnabled mapping on the handler
src/Controls/src/Core/WebView/WebView.Android.cs Added MapJavaScriptEnabled method for Android handlers
src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/WebView.cs Introduced JavaScriptEnabledProperty and related APIs
src/Controls/src/Core/Platform/Android/Extensions/WebViewExtensions.cs Implemented UpdateJavaScriptEnabled to toggle settings
src/Controls/src/Core/PublicAPI/**/PublicAPI.Unshipped.txt Exposed new Android-specific API signatures for JS control
src/Controls/samples/Controls.Sample/Pages/Controls/WebViewGalleries/WebViewGallery.xaml(.cs) Sample UI and event handler for toggling JavaScriptEnabled
Comments suppressed due to low confidence (1)

src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/WebView.cs:119

  • No automated tests have been added for the new JavaScriptEnabled Android platform-specific property; please add relevant UI tests in TestCases.HostApp and shared tests in TestCases.Shared.Tests to cover this behavior.
public static readonly BindableProperty JavaScriptEnabledProperty = BindableProperty.Create("JavaScriptEnabled", typeof(bool), typeof(FormsElement), true);

@jsuarezruiz jsuarezruiz requested review from PureWeen and removed request for tj-devel709 May 28, 2025 11:34
Copy link
Member

@rmarinho rmarinho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems theres a issue on the sample code.
Is it possible to add a test?

@github-project-automation github-project-automation bot moved this from Approved to Changes Requested in MAUI SDK Ongoing May 30, 2025
@jsuarezruiz jsuarezruiz requested a review from rmarinho June 4, 2025 08:06
@jsuarezruiz
Copy link
Contributor Author

Seems theres a issue on the sample code. Is it possible to add a test?

Added a test, could you review it again?

@github-project-automation github-project-automation bot moved this from Changes Requested to Approved in MAUI SDK Ongoing Jun 11, 2025
@rmarinho rmarinho merged commit 678d205 into net10.0 Jun 11, 2025
129 checks passed
@rmarinho rmarinho deleted the threat-models-changes-1 branch June 11, 2025 11:29
@github-project-automation github-project-automation bot moved this from Approved to Done in MAUI SDK Ongoing Jun 11, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Jul 12, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-webview WebView t/enhancement ☀️ New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants