Skip to content

Commit 703c788

Browse files
authored
Only allow AngularDart DevTools to send Dart Debug Extension messages (#1678)
* Only allow incoming connections from AngularDart DevTools extension This ensures Dart AngularDart DevTools is the only extension that can connect to Dart Debug Extension via runtime.sendMessage and removes the need to manually check the sender on each message. https://developer.chrome.com/docs/extensions/mv3/manifest/externally_connectable/ * Update extension version to 1.31 for release
1 parent 84e197e commit 703c788

File tree

5 files changed

+2882
-2780
lines changed

5 files changed

+2882
-2780
lines changed

dwds/debug_extension/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.31
2+
- Replace manual extension allowlist by configuring `externally_connectable` in
3+
the `manifest.json`. See https://developer.chrome.com/docs/extensions/mv3/manifest/externally_connectable/
4+
for details.
15

26
## 1.30
37
- Batch extension `Debugger.scriptParsed` events and send batches every 1000ms

dwds/debug_extension/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: extension
22
publish_to: none
3-
version: 1.30.0
3+
version: 1.31.0
44
homepage: https://github.com/dart-lang/webdev
55
description: >-
66
A chrome extension for Dart debugging.

dwds/debug_extension/web/background.dart

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ const _notADartAppAlert = 'No Dart application detected.'
3434
' see https://bugs.chromium.org/p/chromium/issues/detail?id=885025#c11.';
3535

3636
// Extensions allowed for cross-extension communication.
37+
//
38+
// This is only used to forward outgoing messages, as incoming messages are
39+
// restricted by `externally_connectable` in the extension manijest.json.
3740
const _allowedExtensions = {
3841
'nbkbficgbembimioedhceniahniffgpl', // AngularDart DevTools
3942
};
@@ -362,36 +365,34 @@ void _maybeSaveDevToolsTabId(Tab tab) async {
362365

363366
void _handleMessageFromExternalExtensions(
364367
Request request, Sender sender, Function sendResponse) async {
365-
if (_allowedExtensions.contains(sender.id)) {
366-
if (request.name == 'chrome.debugger.sendCommand') {
367-
try {
368-
final options = request.options as SendCommandOptions;
369-
370-
void sendResponseOrError([e]) {
371-
// No arguments indicate that an error occurred.
372-
if (e == null) {
373-
sendResponse(ErrorResponse()..error = stringify(lastError));
374-
} else {
375-
sendResponse(e);
376-
}
377-
}
368+
if (request.name == 'chrome.debugger.sendCommand') {
369+
try {
370+
final options = request.options as SendCommandOptions;
378371

379-
sendCommand(Debuggee(tabId: request.tabId), options.method,
380-
options.commandParams, allowInterop(sendResponseOrError));
381-
} catch (e) {
382-
sendResponse(ErrorResponse()..error = '$e');
372+
void sendResponseOrError([e]) {
373+
// No arguments indicate that an error occurred.
374+
if (e == null) {
375+
sendResponse(ErrorResponse()..error = stringify(lastError));
376+
} else {
377+
sendResponse(e);
378+
}
383379
}
384-
} else if (request.name == 'dwds.encodedUri') {
385-
sendResponse(_tabIdToEncodedUri[request.tabId] ?? '');
386-
} else if (request.name == 'dwds.startDebugging') {
387-
_startDebugging(DebuggerTrigger.dwds);
388-
// TODO(grouma) - Actually determine if debugging initiated
389-
// successfully.
390-
sendResponse(true);
391-
} else {
392-
sendResponse(
393-
ErrorResponse()..error = 'Unknown request name: ${request.name}');
380+
381+
sendCommand(Debuggee(tabId: request.tabId), options.method,
382+
options.commandParams, allowInterop(sendResponseOrError));
383+
} catch (e) {
384+
sendResponse(ErrorResponse()..error = '$e');
394385
}
386+
} else if (request.name == 'dwds.encodedUri') {
387+
sendResponse(_tabIdToEncodedUri[request.tabId] ?? '');
388+
} else if (request.name == 'dwds.startDebugging') {
389+
_startDebugging(DebuggerTrigger.dwds);
390+
// TODO(grouma) - Actually determine if debugging initiated
391+
// successfully.
392+
sendResponse(true);
393+
} else {
394+
sendResponse(
395+
ErrorResponse()..error = 'Unknown request name: ${request.name}');
395396
}
396397
}
397398

0 commit comments

Comments
 (0)