@capacitor/share 8.0.2-nightly-20260915T151241.0 → 8.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,25 +19,44 @@ import com.getcapacitor.annotation.CapacitorPlugin;
19
19
  import java.io.File;
20
20
  import java.util.ArrayList;
21
21
  import java.util.List;
22
+ import java.util.UUID;
22
23
  import org.json.JSONException;
23
24
 
24
25
  @CapacitorPlugin(name = "Share")
25
26
  public class SharePlugin extends Plugin {
26
27
 
28
+ private static final String NONCE_EXTRA_KEY = "_share_nonce";
29
+
27
30
  private BroadcastReceiver broadcastReceiver;
28
31
  private boolean stopped = false;
29
32
  private boolean isPresenting = false;
30
33
  private ComponentName chosenComponent;
34
+ private String expectedNonce;
31
35
 
32
36
  @Override
33
37
  public void load() {
34
38
  broadcastReceiver = new BroadcastReceiver() {
35
39
  @Override
36
40
  public void onReceive(Context context, Intent intent) {
41
+ // Validate nonce to prevent spoofing from other apps
42
+ // Reference: https://github.com/ionic-team/capacitor-plugins/pull/2592
43
+ String receivedNonce = intent.getStringExtra(NONCE_EXTRA_KEY);
44
+ if (receivedNonce == null || !receivedNonce.equals(expectedNonce)) {
45
+ // Reject broadcasts that don't have the correct nonce
46
+ return;
47
+ }
48
+
49
+ ComponentName component;
37
50
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
38
- chosenComponent = intent.getParcelableExtra(Intent.EXTRA_CHOSEN_COMPONENT, ComponentName.class);
51
+ component = intent.getParcelableExtra(Intent.EXTRA_CHOSEN_COMPONENT, ComponentName.class);
39
52
  } else {
40
- chosenComponent = getParcelableExtraLegacy(intent, Intent.EXTRA_CHOSEN_COMPONENT);
53
+ component = getParcelableExtraLegacy(intent, Intent.EXTRA_CHOSEN_COMPONENT);
54
+ }
55
+
56
+ // Only clear nonce if we successfully got the component data
57
+ if (component != null) {
58
+ chosenComponent = component;
59
+ expectedNonce = null;
41
60
  }
42
61
  }
43
62
  };
@@ -64,6 +83,7 @@ public class SharePlugin extends Plugin {
64
83
  call.resolve(callResult);
65
84
  }
66
85
  isPresenting = false;
86
+ expectedNonce = null;
67
87
  }
68
88
 
69
89
  @PluginMethod
@@ -117,6 +137,12 @@ public class SharePlugin extends Plugin {
117
137
  if (files != null && files.length() != 0) {
118
138
  shareFiles(files, intent, call);
119
139
  }
140
+
141
+ // Generate a random nonce to prevent spoofing via exported receiver
142
+ expectedNonce = UUID.randomUUID().toString();
143
+ Intent callbackIntent = new Intent(Intent.EXTRA_CHOSEN_COMPONENT);
144
+ callbackIntent.putExtra(NONCE_EXTRA_KEY, expectedNonce);
145
+
120
146
  int flags = PendingIntent.FLAG_UPDATE_CURRENT;
121
147
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
122
148
  flags = flags | PendingIntent.FLAG_MUTABLE;
@@ -126,7 +152,7 @@ public class SharePlugin extends Plugin {
126
152
  }
127
153
 
128
154
  // requestCode parameter is not used. Providing 0
129
- PendingIntent pi = PendingIntent.getBroadcast(getContext(), 0, new Intent(Intent.EXTRA_CHOSEN_COMPONENT), flags);
155
+ PendingIntent pi = PendingIntent.getBroadcast(getContext(), 0, callbackIntent, flags);
130
156
  Intent chooser = Intent.createChooser(intent, dialogTitle, pi.getIntentSender());
131
157
  chosenComponent = null;
132
158
  chooser.addCategory(Intent.CATEGORY_DEFAULT);
@@ -180,6 +206,7 @@ public class SharePlugin extends Plugin {
180
206
 
181
207
  @Override
182
208
  protected void handleOnDestroy() {
209
+ expectedNonce = null;
183
210
  if (broadcastReceiver != null) {
184
211
  getActivity().unregisterReceiver(broadcastReceiver);
185
212
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor/share",
3
- "version": "8.0.2-nightly-20260915T151241.0",
3
+ "version": "8.0.2",
4
4
  "description": "The Share API provides methods for sharing content in any sharing-enabled apps the user may have installed.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -81,5 +81,5 @@
81
81
  "publishConfig": {
82
82
  "access": "public"
83
83
  },
84
- "gitHead": "89070d432771b94c97294ed57b8d4843fc9f5392"
84
+ "gitHead": "467dafd615514c19701d75fe6edc143901e4dc93"
85
85
  }