Skip to content

security: disable JavaScript in WebViews loading static content - #501

Open
diraol wants to merge 1 commit into
mainfrom
security/disable-webview-javascript
Open

security: disable JavaScript in WebViews loading static content#501
diraol wants to merge 1 commit into
mainfrom
security/disable-webview-javascript

Conversation

@diraol

@diraol diraol commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Disables JavaScript execution (JavaScriptMode.disabled) in all 3 WebView pages that load static server-rendered content: privacy policy, terms of use, and FAQ
  • None of these pages use JavaScript — the mailto: handler in AboutPenhasPage works via NavigationDelegate at the Dart level, not via JS
  • Adds test coverage for AboutPenhasPage which previously had no tests at all
  • Enhances FakeWebViewController mock to capture JavaScriptMode for test assertions

Security context

Enabling JavaScript unnecessarily in WebViews creates an XSS attack vector. If the server is compromised or traffic is intercepted (the app currently lacks certificate pinning), malicious JavaScript could execute in the WebView context. This is especially concerning for PenhaS, a platform for women facing domestic violence — attackers may control the local network.

Changes

File Change
privacy_policy_page.dart JavaScriptMode.unrestricteddisabled
terms_of_use_page.dart JavaScriptMode.unrestricteddisabled
about_penhas_page.dart JavaScriptMode.unrestricteddisabled
webview_mocks.dart FakeWebViewPlatform exposes lastController; FakeWebViewController captures lastJavaScriptMode; added setPlatformNavigationDelegate override
privacy_policy_page_test.dart Added testWidgets asserting JavaScriptMode.disabled
terms_of_use_page_test.dart Added testWidgets asserting JavaScriptMode.disabled
about_penhas_page_test.dart New file — golden test + JavaScript mode assertion

Before / After

Before: All 3 WebViews used JavaScriptMode.unrestricted. AboutPenhasPage had no tests.
After: All 3 WebViews use JavaScriptMode.disabled. 3 new tests prevent accidental re-enablement.

Test plan

  • Run flutter test test/app/features/authentication/presentation/sign_in/privacy_policy/ — passes
  • Run flutter test test/app/features/authentication/presentation/sign_in/terms_of_use/ — passes
  • Run flutter test test/app/features/main_menu/presentation/pages/ — passes
  • Run flutter test — full suite, no regressions
  • Manual: open Privacy Policy, Terms of Use, and FAQ pages in the app — content renders correctly without JavaScript

🤖 Generated with Claude Code

Disable JavaScript execution in all 3 WebView pages that load static
server-rendered content (privacy policy, terms of use, FAQ). None of
these pages use JavaScript — the mailto: handler in AboutPenhasPage
works via NavigationDelegate at the Dart level, not via JS.

Enabling JavaScript unnecessarily creates an XSS attack vector: if the
server is compromised or traffic is intercepted (especially relevant
given the absence of certificate pinning), malicious JavaScript could
execute in the WebView context.

Changes:
- privacy_policy_page.dart: JavaScriptMode.unrestricted -> disabled
- terms_of_use_page.dart: JavaScriptMode.unrestricted -> disabled
- about_penhas_page.dart: JavaScriptMode.unrestricted -> disabled
- webview_mocks.dart: FakeWebViewPlatform now exposes lastController;
  FakeWebViewController captures lastJavaScriptMode for assertions;
  added setPlatformNavigationDelegate override for AboutPenhasPage
- Added testWidgets asserting JavaScriptMode.disabled in all 3 pages
- Created about_penhas_page_test.dart (previously had no test coverage)

Before: All WebViews used JavaScriptMode.unrestricted.
After: All WebViews use JavaScriptMode.disabled.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@diraol
diraol requested a review from a team as a code owner April 16, 2026 17:32
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant