Skip to content

Commit b88b2fa

Browse files
committed
fix: make grants regexp stricted, prevent unsafeWindow + other stuff from being matched
1 parent 5658483 commit b88b2fa

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { MemberExpression } from 'estree';
66

77
const META_START = '// ==UserScript==';
88
const META_END = '// ==/UserScript==';
9-
const GRANTS_REGEXP = /^unsafeWindow|GM[._][a-zA-Z0-9_]+/;
9+
const GRANTS_REGEXP = /^(unsafeWindow$|GM[._]\w+)/;
1010

1111
export function collectGrants(ast: AstNode) {
1212
let scope = attachScopes(ast, 'scope');

test/util.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ describe('collectGrants', () => {
5353
expect(result).toContain('unsafeWindow');
5454
});
5555

56+
it('should return nothing unsafeWindow when presented with unsafeWindowButNotReally', () => {
57+
const astNode = parseCodeAsEstreeAst(`unsafeWindowButNotReally`);
58+
const result = collectGrants(astNode);
59+
60+
expect(result.size).toBe(0);
61+
});
62+
5663
it('should return unsafeWindow even when a subfield is accessed', () => {
5764
const astNode = parseCodeAsEstreeAst(`unsafeWindow.anotherThing`);
5865
const result = collectGrants(astNode);

0 commit comments

Comments
 (0)