-
Notifications
You must be signed in to change notification settings - Fork 85
feat(replay): add selective unmasking and protect sensitive inputs #574
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
marandaneto
wants to merge
2
commits into
main
Choose a base branch
from
fix/session-replay-selective-unmask
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "posthog_flutter": minor | ||
| --- | ||
|
|
||
| Add `PostHogUnmaskWidget` to selectively reveal known-safe Flutter text and images while keeping global session replay masking enabled. Explicit masks and sensitive inputs take precedence regardless of nesting. Password, card number/security code/expiration date (including day/month/year), and one-time-code autofill hints, password keyboard types, and obscured fields now stay masked across Material, Cupertino, and direct `EditableText` inputs even when global text masking is disabled. Flutter web still requires canvas masking to be enabled; native platform views and captured native screens are unaffected. |
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
29 changes: 29 additions & 0 deletions
29
posthog_flutter/lib/src/replay/mask/posthog_unmask_widget.dart
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import 'package:flutter/widgets.dart'; | ||
|
|
||
| /// Reveals a widget subtree in session replay despite global text/image masking. | ||
| /// | ||
| /// Keep `maskAllTexts` / `maskAllImages` enabled and reveal only known-safe UI: | ||
| /// | ||
| /// ```dart | ||
| /// PostHogUnmaskWidget(child: Text('Try again')) | ||
| /// ``` | ||
| /// | ||
| /// Only wrap content known to be safe. Explicit `PostHogMaskWidget` masks and | ||
| /// sensitive text inputs always take precedence, regardless of nesting order. | ||
| /// This does not erase masks from ancestors or overlapping widgets, reveal | ||
| /// native platform views, or change masking on captured native screens. | ||
| /// | ||
| /// On Flutter web, canvas masking must already be enabled through | ||
| /// `session_recording.canvasCapture.maskRegionsFn` in `posthog.init`, or by | ||
| /// mounting a `PostHogMaskWidget`. This widget does not enable canvas recording | ||
| /// or masking itself. Keep it inside `PostHogWidget` on all platforms. | ||
| class PostHogUnmaskWidget extends StatelessWidget { | ||
| /// The known-safe widget subtree to reveal in session replay. | ||
| final Widget child; | ||
|
|
||
| /// Creates an exception to global text/image masking around [child]. | ||
| const PostHogUnmaskWidget({super.key, required this.child}); | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) => child; | ||
| } |
41 changes: 41 additions & 0 deletions
41
posthog_flutter/lib/src/replay/mask/sensitive_text_input.dart
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import 'package:flutter/cupertino.dart'; | ||
| import 'package:flutter/material.dart'; | ||
|
|
||
| const _sensitiveAutofillHints = { | ||
| AutofillHints.password, | ||
| AutofillHints.newPassword, | ||
| AutofillHints.creditCardNumber, | ||
| AutofillHints.creditCardSecurityCode, | ||
| AutofillHints.creditCardExpirationDate, | ||
| AutofillHints.creditCardExpirationDay, | ||
| AutofillHints.creditCardExpirationMonth, | ||
| AutofillHints.creditCardExpirationYear, | ||
| AutofillHints.oneTimeCode, | ||
| }; | ||
|
|
||
| bool isSensitiveTextInput(Widget? widget) { | ||
| final bool obscureText; | ||
| final TextInputType? keyboardType; | ||
| final Iterable<String>? autofillHints; | ||
| if (widget is EditableText) { | ||
| obscureText = widget.obscureText; | ||
| keyboardType = widget.keyboardType; | ||
| autofillHints = widget.autofillHints; | ||
| } else if (widget is TextField) { | ||
| obscureText = widget.obscureText; | ||
| keyboardType = widget.keyboardType; | ||
| autofillHints = widget.autofillHints; | ||
| } else if (widget is CupertinoTextField) { | ||
| // Cupertino passes autofill hints through its AutofillClient, not through | ||
| // the nested EditableText's autofillHints. | ||
| obscureText = widget.obscureText; | ||
| keyboardType = widget.keyboardType; | ||
| autofillHints = widget.autofillHints; | ||
| } else { | ||
| return false; | ||
| } | ||
|
|
||
| return obscureText || | ||
| keyboardType == TextInputType.visiblePassword || | ||
| (autofillHints?.any(_sensitiveAutofillHints.contains) ?? false); | ||
| } | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.