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

Commit20fa9d5

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 commit20fa9d5

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-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: 23 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,11 @@ if (!backendInitialized) {
9495
}
9596

9697
constproxyEventFromWindowToDevToolsExtension=(event:MessageEvent)=>{
97-
if(event.source===window&&event.data){
98+
// We check for the __NG_DEVTOOLS_EVENT__ property to ensure that we only forward
99+
// messages that are intended for the Angular DevTools extension.
100+
// This prevents the content script from forwarding arbitrary messages that could
101+
// potentially DDOS the extension or cause other issues.
102+
if(event.source===window&&event.data&&event.data.__NG_DEVTOOLS_EVENT__){
98103
try{
99104
chrome.runtime.sendMessage(event.data);
100105
}catch(e){
@@ -111,3 +116,20 @@ const proxyEventFromWindowToDevToolsExtension = (event: MessageEvent) => {
111116
};
112117

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