Skip to content

Commit 692e9e2

Browse files
committed
style: protect String.prototype.includes and avoid the layer
1 parent 61c354f commit 692e9e2

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

sources/src/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ declare const unsafeWindow: unsafeWindow
55
const Win = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window
66

77
const OriginalFunctionToString = Win.Function.prototype.toString
8+
const OriginalStringIncludes = Win.String.prototype.includes
89

910
const ProtectedFunctionStrings = ['toString', 'apply']
1011

@@ -23,10 +24,13 @@ Win.Function.prototype.apply = new Proxy(Win.Function.prototype.apply, {
2324
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
2425
apply(Target: typeof Function.prototype.apply, ThisArg: Function, Args: unknown[]) {
2526
let FunctionText = OriginalFunctionToString.call(ThisArg) as string
26-
if ([',inventoryId:', ':if("#adshield"===', ':_.ADS_FRAME,', '[new ad(this,'].some(Item => FunctionText.includes(Item))) {
27-
console.debug('[tinyShield]:', FunctionText, Args)
28-
throw new Error()
27+
for (const Item of [',inventoryId:', ':if("#adshield"===', ':_.ADS_FRAME,', '[new ad(this,']) {
28+
if (OriginalStringIncludes.call(FunctionText, Item) as boolean) {
29+
console.debug('[tinyShield]:', FunctionText, Args)
30+
throw new Error()
31+
}
2932
}
33+
3034
return Reflect.apply(Target, ThisArg, Args)
3135
}
3236
})

0 commit comments

Comments
 (0)