Skip to content

Commit 5d558a8

Browse files
committed
feat: protect RegExp.prototype.test from overriding pollution
1 parent 1dc8261 commit 5d558a8

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@list-kr/tinyshield",
3-
"version": "1.6.4",
3+
"version": "1.7.0",
44
"description": "",
55
"type": "module",
66
"scripts": {

sources/banner.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// @downloadURL https://cdn.jsdelivr.net/npm/@list-kr/tinyshield@latest/dist/tinyShield.user.js
99
// @license MIT
1010
//
11-
// @version 1.6.4
11+
// @version 1.7.0
1212
// @author PiQuark6046 and contributors
1313
//
1414
// @match *://ygosu.com/*

sources/src/index.ts

Lines changed: 3 additions & 2 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 OriginalArrayToString = Win.Array.prototype.toString
8+
const OriginalRegExpTest = Win.RegExp.prototype.test
89

910
const ProtectedFunctionStrings = ['toString', 'get', 'set']
1011

@@ -31,7 +32,7 @@ Win.Map.prototype.get = new Proxy(Win.Map.prototype.get, {
3132
}
3233

3334
let ArgText = OriginalArrayToString.call(Args) as string
34-
if (ASInitPositiveRegExps.filter(ASInitPositiveRegExp => ASInitPositiveRegExp.filter(Index => Index.test(ArgText)).length >= 2).length === 1) {
35+
if (ASInitPositiveRegExps.filter(ASInitPositiveRegExp => ASInitPositiveRegExp.filter(Index => OriginalRegExpTest.call(Index, ArgText) as boolean).length >= 2).length === 1) {
3536
console.debug('[tinyShield]: Map.prototype.get:', ThisArg, Args)
3637
throw new Error()
3738
}
@@ -51,7 +52,7 @@ Win.Map.prototype.set = new Proxy(Win.Map.prototype.set, {
5152
} catch {
5253
console.warn('[tinyShield]: Map.prototype.get:', ThisArg, Args)
5354
}
54-
if (ASReinsertedAdvInvenPositiveRegExps.filter(ASReinsertedAdvInvenPositiveRegExp => ASReinsertedAdvInvenPositiveRegExp.filter(Index => Index.test(ArgText)).length >= 1).length === 1) {
55+
if (ASReinsertedAdvInvenPositiveRegExps.filter(ASReinsertedAdvInvenPositiveRegExp => ASReinsertedAdvInvenPositiveRegExp.filter(Index => OriginalRegExpTest.call(Index, ArgText) as boolean).length >= 1).length === 1) {
5556
console.debug('[tinyShield]: Map.prototype.set:', ThisArg, Args)
5657
throw new Error()
5758
}

0 commit comments

Comments
 (0)