react-native-clipboard / clipboard

React Native Clipboard API for both iOS and Android.
MIT License
669 stars 118 forks source link

Expose access to EXTRA_IS_SENSITIVE for setString on Android #222

Open mmmcloughlin opened 5 months ago

mmmcloughlin commented 5 months ago

Describe the Feature

Starting with Android 13, the system will display any text that is copied in a popover UI on the user's screen. If the user has copied sensitive content (such as a password), this can lead to sensitive data exposure. To mitigate this risk factor, Android 13 introduces a new flag, EXTRA_IS_SENSITIVE, that can be applied to data copied to the clipboard. If this flag is applied, the system will treat the data copied to the clipboard as sensitive and will refrain from displaying it on the user's screen.

Possible Implementations

ClipboardModule.java needs the following added before setPrimaryClip in setString. This could be an optional flag passed to setString

public void setString(String text, Boolean isSensitive) {
  try {
    ClipData clipdata = ClipData.newPlainText(null, text);

    if (isSensitive) {
      PersistableBundle extras = new PersistableBundle();
      extras.putBoolean("android.content.extra.IS_SENSITIVE", true);
      clipdata.getDescription().setExtras(extras);
    }
    ...

Related Issues