Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8e83db9

Browse files
committed
fix(devtools): Enhance message bus with event tagging and spam protection
One common problem encountered by the devtools content script is that it accepted almost any message send over the message bus. Some websites like `auth.openai.com` were spamming the bus and DDOS the devtools app.This commit introduces 2 defensives strategies :* event tagging : Only Event sent by the devtools app will make it to its backend* Bailout out when the event throughput is too high (we're getting spammed).fixes#62471#62450#55854
1 parente8c5603 commit8e83db9

File tree

5 files changed

+23
-1
lines changed

5 files changed

+23
-1
lines changed

‎devtools/projects/shell-browser/src/app/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ ts_project(
186186
deps= [
187187
":chrome_message_bus_rjs",
188188
":same_page_message_bus_rjs",
189+
"//:node_modules/rxjs",
189190
"//devtools/projects/protocol:protocol_rjs",
190191
],
191192
)

‎devtools/projects/shell-browser/src/app/chrome-message-bus.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export class ChromeMessageBus extends MessageBus<Events> {
7474
topic,
7575
args,
7676
__ignore_ng_zone__:true,
77+
__NG_DEVTOOLS_EVENT__:true,
7778
});
7879
returntrue;
7980
}

‎devtools/projects/shell-browser/src/app/content-script.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
/// <reference types="chrome"/>
1010

11+
import{bufferTime,fromEvent,tap}from'rxjs';
1112
import{ChromeMessageBus}from'./chrome-message-bus';
1213
import{SamePageMessageBus}from'./same-page-message-bus';
1314

@@ -94,7 +95,7 @@ if (!backendInitialized) {
9495
}
9596

9697
constproxyEventFromWindowToDevToolsExtension=(event:MessageEvent)=>{
97-
if(event.source===window&&event.data){
98+
if(event.source===window&&event.data&&event.data.__NG_DEVTOOLS_EVENT__){
9899
try{
99100
chrome.runtime.sendMessage(event.data);
100101
}catch(e){
@@ -111,3 +112,20 @@ const proxyEventFromWindowToDevToolsExtension = (event: MessageEvent) => {
111112
};
112113

113114
window.addEventListener('message',proxyEventFromWindowToDevToolsExtension);
115+
116+
/**
117+
* This introduces a spam protection mechanism for the message bus.
118+
*/
119+
fromEvent(window,'message')
120+
.pipe(
121+
bufferTime(1000),// Collect emissions for 1 second
122+
tap((buffer):void=>{
123+
if(buffer.length>100){
124+
window.removeEventListener('message',proxyEventFromWindowToDevToolsExtension);
125+
thrownewError(
126+
`Message stream is getting spammed - Angular extension is bailing out (${buffer.length} msgs/s)`,
127+
);
128+
}
129+
}),
130+
)
131+
.subscribe();

‎devtools/projects/shell-browser/src/app/same-page-message-bus.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export class SamePageMessageBus extends MessageBus<Events> {
7474
topic,
7575
args,
7676
__ignore_ng_zone__:true,
77+
__NG_DEVTOOLS_EVENT__:true,
7778
},
7879
'*',
7980
);

‎devtools/src/iframe-message-bus.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export class IFrameMessageBus extends MessageBus<Events> {
7878
// event listeners but also not prevent the NgZone in the devtools app
7979
// from updating its UI.
8080
__ignore_ng_zone__:this._source==='angular-devtools',
81+
__NG_DEVTOOLS_EVENT__:true,
8182
},
8283
'*',
8384
);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp