Privacy for Flutter

Learn about the privacy-oriented settings for Session Replay.

Masking in the Sentry Flutter SDK is based on Widget types, e.g. Image, not the string representation of the type (i.e. we check whether a widgetInstance should be masked by checking if (widgetInstance is Image) instead of if (widgetInstance.runtimeType == 'Image')). This means we can ensure masking works regardless of obfuscation in release builds and also works for subclasses. This approach allows the SDK to automatically mask widgets that are part of the Flutter SDK itself. However, for third-party widgets, you need to manually configure the privacy settings to mask their content. Read more about Third Party Widgets below.

The following options can be configured in the options.privacy field of your Sentry Flutter SDK, in SentryFlutter.init((options) { ... }):

KeyTypeDefaultDescription
maskAllTextbooltrueMask all text content. Draws a rectangle of text bounds with text color on top. Currently Text, EditableText and RichText widgets are masked.
maskAllImagesbooltrueMask content of all images. Draws a rectangle of image bounds with image's dominant color on top. Currently Image widgets are masked.
maskAssetImagesboolfalseMask asset images coming from the root asset bundle.
mask<T extends Widget>()void/Mask given widget type T (or subclasses of T). Note: masking rules are called in the order they're added so if a previous rule already makes a decision, this rule won't be called.
unmask<T extends Widget>()void/Unmask given widget type T (or subclasses of T). Note: masking rules are called in the order they're added so if a previous rule already makes a decision, this rule won't be called.
maskCallback<T extends Widget>()void/Provide a custom callback to decide whether to mask the widget of class T (or subclasses of T). Note: masking rules are called in the order they're added so if a previous rule already makes a decision, this rule won't be called.

For example, you can explicitly mask or unmask widgets by type, or you can even have a callback to decide whether a specific widget instance should be masked:

Copied
options.privacy.mask<IconButton>();
options.privacy.unmask<Image>();
options.privacy.maskCallback<Text>(
    (Element element, Text widget) =>
        (widget.data?.contains('secret') ?? false)
            ? SentryMaskingDecision.mask
            : SentryMaskingDecision.continueProcessing);

To disable the default text and image masking rules for screenshots and Session Replay, use the following options. This does not disable SensitiveContent masking, SentryMask, or custom rules. Only use these settings when the content is safe to capture:

Copied
options.privacy.maskAllText = false;
options.privacy.maskAllImages = false;

The default rules mask Flutter SensitiveContent widgets marked ContentSensitivity.sensitive or ContentSensitivity.autoSensitive. Unrecognized sensitivity values are also masked. ContentSensitivity.notSensitive continues through other masking rules; it does not unmask the content by itself.

These rules apply to both screenshots and Session Replay. Custom rules and SentryUnmask take precedence over the default rules, so verify your configuration if you override masking.

The Sentry Flutter SDK cannot automatically mask widgets from third party packages. You need to manually configure the privacy configuration to mask the content of these widgets.

For example, if you are using the FlutterMap package, you need to add the following privacy configuration:

Copied
options.privacy.mask<FlutterMap>();
Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").