Skip to content

Only allow AngularDart DevTools to send Dart Debug Extension messages #1678

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions dwds/debug_extension/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.31
- Replace manual extension allowlist by configuring `externally_connectable` in
the `manifest.json`. See https://developer.chrome.com/docs/extensions/mv3/manifest/externally_connectable/
for details.

## 1.30
- Batch extension `Debugger.scriptParsed` events and send batches every 1000ms
Expand Down
2 changes: 1 addition & 1 deletion dwds/debug_extension/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: extension
publish_to: none
version: 1.30.0
version: 1.31.0
homepage: https://github.com/dart-lang/webdev
description: >-
A chrome extension for Dart debugging.
Expand Down
55 changes: 28 additions & 27 deletions dwds/debug_extension/web/background.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ const _notADartAppAlert = 'No Dart application detected.'
' see https://bugs.chromium.org/p/chromium/issues/detail?id=885025#c11.';

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

void _handleMessageFromExternalExtensions(
Request request, Sender sender, Function sendResponse) async {
if (_allowedExtensions.contains(sender.id)) {
if (request.name == 'chrome.debugger.sendCommand') {
try {
final options = request.options as SendCommandOptions;

void sendResponseOrError([e]) {
// No arguments indicate that an error occurred.
if (e == null) {
sendResponse(ErrorResponse()..error = stringify(lastError));
} else {
sendResponse(e);
}
}
if (request.name == 'chrome.debugger.sendCommand') {
try {
final options = request.options as SendCommandOptions;

sendCommand(Debuggee(tabId: request.tabId), options.method,
options.commandParams, allowInterop(sendResponseOrError));
} catch (e) {
sendResponse(ErrorResponse()..error = '$e');
void sendResponseOrError([e]) {
// No arguments indicate that an error occurred.
if (e == null) {
sendResponse(ErrorResponse()..error = stringify(lastError));
} else {
sendResponse(e);
}
}
} else if (request.name == 'dwds.encodedUri') {
sendResponse(_tabIdToEncodedUri[request.tabId] ?? '');
} else if (request.name == 'dwds.startDebugging') {
_startDebugging(DebuggerTrigger.dwds);
// TODO(grouma) - Actually determine if debugging initiated
// successfully.
sendResponse(true);
} else {
sendResponse(
ErrorResponse()..error = 'Unknown request name: ${request.name}');

sendCommand(Debuggee(tabId: request.tabId), options.method,
options.commandParams, allowInterop(sendResponseOrError));
} catch (e) {
sendResponse(ErrorResponse()..error = '$e');
}
} else if (request.name == 'dwds.encodedUri') {
sendResponse(_tabIdToEncodedUri[request.tabId] ?? '');
} else if (request.name == 'dwds.startDebugging') {
_startDebugging(DebuggerTrigger.dwds);
// TODO(grouma) - Actually determine if debugging initiated
// successfully.
sendResponse(true);
} else {
sendResponse(
ErrorResponse()..error = 'Unknown request name: ${request.name}');
}
}

Expand Down
Loading