Privacy for React Native

Learn how to mask sensitive data that may appear in your app in Session Replay.

The Session Replay SDK masks all text content, images, webviews, and user input by default. This helps ensure that no sensitive data is exposed. You can also manually choose which parts of your app to mask by using the options listed below.

If your app doesn't contain any sensitive date, you can disable the default masking behavior with:

Copied
Sentry.mobileReplayIntegration({
  maskAllText: false,
  maskAllImages: false,
  maskAllVectors: false,
}),

Make sure your Sentry React Native SDK version is 5.36.0, 6.3.0 and up

You can choose which views you want to mask or unmask by using the Mask or Unmask components.

Copied
import * as Sentry from "@sentry/react-native";

const Example = () => {
  return (
    <View>
      <Sentry.Unmask>
        <Text>This will be unmasked</Text>
      </Sentry.Unmask>
      <Sentry.Mask>
        <Text>This will be masked</Text>
      </Sentry.Mask>
    </View>
  );
};

Make sure your Sentry React Native SDK version is 6.4.0-beta.1 and up to use the masking components

Supported in React Native SDK v8.27.0 and later

When you can't wrap views with the Mask or Unmask components—for example, views rendered by a third-party library—you can mask or unmask them by their native view class name. Use maskedViewClasses to redact additional classes on top of the maskAllText/maskAllImages/maskAllVectors defaults, and unmaskedViewClasses to exempt classes from redaction. Both match views that are instances of the listed classes or their subclasses.

Copied
import * as Sentry from "@sentry/react-native";

Sentry.init({
  dsn: "___PUBLIC_DSN___",
  replaysSessionSampleRate: 0.1,
  replaysOnErrorSampleRate: 1.0,
  integrations: [
    Sentry.mobileReplayIntegration({
      maskAllText: true,
      // Unmask text views so text is visible in the replay, even though
      // `maskAllText` is enabled.
      unmaskedViewClasses: [
        "RCTTextView", // iOS (Legacy Architecture)
        "RCTParagraphComponentView", // iOS (New Architecture)
        "com.facebook.react.views.text.ReactTextView", // Android
      ],
      // Mask a specific native view class in addition to the defaults.
      maskedViewClasses: [
        "MKMapView", // iOS
      ],
    }),
  ],
});

The class names are the native view class names, not the React component names, and they differ between iOS and Android. Class names for the other platform are harmless no-ops, so you can list both in the same array. Because matching is class-based, a name that isn't loaded at runtime is ignored.

unmaskedViewClasses takes precedence over the maskAllText/maskAllImages/maskAllVectors defaults, so a view whose class is unmasked is shown in the replay even when the corresponding maskAll* option is enabled. An explicit Mask component still always wins—see Masking Priority.

When components are wrapped by Unmask, only direct children will be unmasked. You'll need to explicitly wrap any indirect children that you want to appear in the replay.

Copied
<Sentry.Unmask>
  <Text>
    This will be unmasked
    <Text>This will be masked</Text>
  </Text>
  <Text>This will be unmasked</Text>
</Sentry.Unmask>;

When components are wrapped by Mask, all children will be masked.

Copied
<Sentry.Mask>
  <Text>
    This will be masked
    <Text>This will be masked</Text>
  </Text>
  <Text>This will be masked</Text>
</Sentry.Mask>;

If a view is marked as masked, it will always be masked, even if it's a child of an unmasked view.

Copied
<Sentry.Mask>
  <Text>This will be masked</Text>
  <Sentry.Unmask>
    <Text>This will be masked</Text>
  </Sentry.Unmask>
</Sentry.Mask>;

The Mask component can't be unmasked.

Copied
<Sentry.Unmask>
  <Sentry.Mask>
    <Text>This will be masked</Text>
  </Sentry.Mask>
</Sentry.Unmask>;

The Mask and Unmask components are native on iOS and Android and are compatible with both the New and the Legacy Architecture.

The masking components behave as standard React Native View components.

If you're experiencing issues with unmasking that are more than one level deep, check if the wrapped components are present in the native views hierarchy. If not, it means that your view was evaluated by React Native as Layout Only and flattened. Read more about flattening views in the React Native documentation.

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").