Skip to content

Commit 4ad0252

Browse files
committed
feat: blocking debug calling with Function.prototype.call
1 parent 33ea4c3 commit 4ad0252

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

sources/src/index.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
type unsafeWindow = typeof window
2+
// eslint-disable-next-line @typescript-eslint/naming-convention
3+
declare const unsafeWindow: unsafeWindow
4+
5+
const Win = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window
6+
7+
const ProtectedFunctionStrings = ['toString', 'apply']
8+
9+
Win.Function.prototype.toString = new Proxy(Win.Function.prototype.toString, {
10+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
11+
apply(Target: () => string, ThisArg: Function, Args: null) {
12+
if (ProtectedFunctionStrings.includes(ThisArg.name)) {
13+
return `function ${ThisArg.name}() { [native code] }`
14+
} else {
15+
return Reflect.apply(Target, ThisArg, Args)
16+
}
17+
}
18+
})
19+
20+
Win.Function.prototype.apply = new Proxy(Win.Function.prototype.apply, {
21+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
22+
apply(Target: typeof Function.prototype.apply, ThisArg: Function, Args: unknown[]) {
23+
if (Args.toString().includes('debug,')) {
24+
throw new Error()
25+
}
26+
27+
return Reflect.apply(Target, ThisArg, Args)
28+
}
29+
})

0 commit comments

Comments
 (0)