Skip to content

Commit c14ed41

Browse files
authored
block GWT smuggling
1 parent b517efc commit c14ed41

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

SmuggleShield/content.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ class HTMLSmugglingBlocker {
4343
{ pattern: /[^\w](\w+)\s*=\s*(\w+)\s*\^\s*(\w+)/i, weight: 2 },
4444
{ pattern: /\.slice\(\s*\w+\s*-\s*\d+\s*,\s*\w+\s*-\s*\d+\s*\)/i, weight: 2 },
4545
{ pattern: /for\s*\([^)]+\)\s*\{[^}]*string\.fromcharcode\([^)]+\)/i, weight: 3 },
46+
{ pattern: /\$wnd\s*=\s*window;\s*\$doc\s*=\s*\$wnd\.document/i, weight: 4 },
47+
{ pattern: /__gwt_(?:isKnownPropertyValue|getMetaProperty|marker|stylesLoaded|scriptsLoaded)/i, weight: 4 },
48+
{ pattern: /\$strongName\s*=\s*['"][0-9A-F]{32}['"]/i, weight: 3 },
49+
{ pattern: /\$gwt_version\s*=\s*['"][0-9.]+['"]/i, weight: 3 },
50+
{ pattern: /(?:function|var)\s+[a-zA-Z$_]+\s*=\s*\{\s*[a-zA-Z$_]+:\s*window,\s*[a-zA-Z$_]+:\s*document\s*\}/i, weight: 4 },
51+
{ pattern: /\b(?:gwtOnLoad|__gwtStatsEvent|gwtOnLoadFunc)\b/i, weight: 3 },
52+
{ pattern: /\.setAttribute\(['"]__gwt_property['"]/i, weight: 3 },
53+
{ pattern: /document\.createElement\(['"]script['"]\).*?\.src\s*=.*?\.cache\.js/i, weight: 4 }
4654
];
4755
this.threshold = 4;
4856
this.cache = new Map();
@@ -82,7 +90,8 @@ class HTMLSmugglingBlocker {
8290

8391
getCacheKey(content) {
8492
let hash = 0;
85-
for (let i = 0; i < Math.min(content.length, 1000); i++) {
93+
const len = Math.min(content.length, 500);
94+
for (let i = 0; i < len; i++) {
8695
hash = ((hash << 5) - hash) + content.charCodeAt(i);
8796
hash = hash & hash;
8897
}

0 commit comments

Comments
 (0)