eslint-plugin-chrome-extensions 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +377 -28
- package/package.json +2 -2
- package/src/data/deprecations.js +10 -0
- package/src/index.js +25 -3
- package/src/rules/manifest-key-order.js +3 -2
- package/src/rules/no-duplicate-manifest-keys.js +36 -0
- package/src/rules/no-insecure-fetch.js +52 -0
- package/src/rules/no-insecure-messaging.js +44 -7
- package/src/rules/no-invalid-permissions.js +2 -2
- package/src/rules/no-missing-web-accessible-resources.js +51 -0
- package/src/rules/no-remote-code.js +11 -9
- package/src/rules/no-unrestricted-host-permissions.js +54 -0
- package/src/rules/no-unused-permissions.js +1 -1
- package/src/rules/require-mv3.js +2 -2
- package/src/rules/valid-manifest-icons.js +85 -0
- package/src/rules/valid-mv3-schema.js +3 -2
- package/src/rules/valid-service-worker.js +1 -1
- package/src/rules/valid-version-field.js +3 -3
- package/src/utils.js +16 -2
package/src/index.js
CHANGED
|
@@ -1,29 +1,41 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { bundles as oldBundles } from './data/deprecations.js'
|
|
2
2
|
|
|
3
3
|
import manifestKeyOrder from './rules/manifest-key-order.js'
|
|
4
4
|
import noContentStyleLeak from './rules/no-content-style-leak.js'
|
|
5
5
|
import noDeprecatedAPIs from './rules/no-deprecated-apis.js'
|
|
6
|
+
import noDuplicateManifestKeys from './rules/no-duplicate-manifest-keys.js'
|
|
7
|
+
import noInsecureFetch from './rules/no-insecure-fetch.js'
|
|
6
8
|
import noInsecureMessaging from './rules/no-insecure-messaging.js'
|
|
7
9
|
import noInvalidPermissions from './rules/no-invalid-permissions.js'
|
|
8
10
|
import noMissingPermissions from './rules/no-missing-permissions.js'
|
|
11
|
+
import noMissingWebAccessibleResources from './rules/no-missing-web-accessible-resources.js'
|
|
9
12
|
import noRemoteCode from './rules/no-remote-code.js'
|
|
13
|
+
import noUnrestrictedHostPermissions from './rules/no-unrestricted-host-permissions.js'
|
|
10
14
|
import noUnusedPermissions from './rules/no-unused-permissions.js'
|
|
11
15
|
import requireMV3 from './rules/require-mv3.js'
|
|
16
|
+
import validManifestIcons from './rules/valid-manifest-icons.js'
|
|
12
17
|
import validMV3schema from './rules/valid-mv3-schema.js'
|
|
13
18
|
import validServiceWorker from './rules/valid-service-worker.js'
|
|
14
19
|
import validVersionField from './rules/valid-version-field.js'
|
|
15
20
|
|
|
21
|
+
import { bundleRules, deprecatedFrom, initBundleDeprecation } from './utils.js'
|
|
22
|
+
|
|
16
23
|
const plugin = {
|
|
17
24
|
rules: {
|
|
18
25
|
'manifest-key-order': manifestKeyOrder,
|
|
19
26
|
'no-content-style-leak': noContentStyleLeak,
|
|
20
27
|
'no-deprecated-apis': noDeprecatedAPIs,
|
|
28
|
+
'no-duplicate-manifest-keys': noDuplicateManifestKeys,
|
|
29
|
+
'no-insecure-fetch': noInsecureFetch,
|
|
21
30
|
'no-insecure-messaging': noInsecureMessaging,
|
|
22
31
|
'no-invalid-permissions': noInvalidPermissions,
|
|
23
32
|
'no-missing-permissions': noMissingPermissions,
|
|
33
|
+
'no-missing-web-accessible-resources': noMissingWebAccessibleResources,
|
|
24
34
|
'no-remote-code': noRemoteCode,
|
|
35
|
+
'no-unrestricted-host-permissions': noUnrestrictedHostPermissions,
|
|
25
36
|
'no-unused-permissions': noUnusedPermissions,
|
|
26
37
|
'require-mv3': requireMV3,
|
|
38
|
+
'valid-manifest-icons': validManifestIcons,
|
|
27
39
|
'valid-mv3-schema': validMV3schema,
|
|
28
40
|
'valid-service-worker': validServiceWorker,
|
|
29
41
|
'valid-version-field': validVersionField
|
|
@@ -36,7 +48,8 @@ for (const [ruleId, rule] of Object.entries(plugin.rules))
|
|
|
36
48
|
plugin.configs = {
|
|
37
49
|
recommended: {
|
|
38
50
|
plugins: { 'chrome-extensions': plugin },
|
|
39
|
-
rules: bundleRules(plugin.rules, rule => rule.meta.docs.recommended,
|
|
51
|
+
rules: bundleRules(plugin.rules, rule => rule.meta.docs.recommended,
|
|
52
|
+
'chrome-extensions', deprecatedFrom(oldBundles, 'recommended'))
|
|
40
53
|
},
|
|
41
54
|
strict: {
|
|
42
55
|
plugins: { 'chrome-extensions': plugin },
|
|
@@ -46,10 +59,19 @@ plugin.configs = {
|
|
|
46
59
|
plugins: { 'chrome-extensions': plugin },
|
|
47
60
|
rules: bundleRules(plugin.rules, rule => rule.meta.type == 'problem', 'chrome-extensions')
|
|
48
61
|
},
|
|
62
|
+
security: {
|
|
63
|
+
plugins: { 'chrome-extensions': plugin },
|
|
64
|
+
rules: bundleRules(plugin.rules, rule => rule.meta.docs.security,
|
|
65
|
+
'chrome-extensions', deprecatedFrom(oldBundles, 'security'))
|
|
66
|
+
},
|
|
49
67
|
manifest: {
|
|
50
68
|
plugins: { 'chrome-extensions': plugin },
|
|
51
|
-
rules: bundleRules(plugin.rules, rule => rule.meta.docs.manifest,
|
|
69
|
+
rules: bundleRules(plugin.rules, rule => rule.meta.docs.manifest,
|
|
70
|
+
'chrome-extensions', deprecatedFrom(oldBundles, 'manifest'))
|
|
52
71
|
}
|
|
53
72
|
}
|
|
54
73
|
|
|
74
|
+
for (const entry of Object.entries(oldBundles))
|
|
75
|
+
initBundleDeprecation(plugin, entry, 'chrome-extensions')
|
|
76
|
+
|
|
55
77
|
export { plugin as default, plugin as chromeExtensions }
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { manifestKeyOrder } from '../data/manifest.js'
|
|
2
|
+
|
|
2
3
|
import { getFilename } from '../utils.js'
|
|
3
4
|
|
|
4
5
|
const re = { manifestFilename: /manifest\.json$/ }
|
|
@@ -23,7 +24,7 @@ export default {
|
|
|
23
24
|
meta: {
|
|
24
25
|
type: 'layout',
|
|
25
26
|
docs: {
|
|
26
|
-
description: '
|
|
27
|
+
description: 'Enforces a preferred order for manifest keys',
|
|
27
28
|
category: 'Stylistic Issues',
|
|
28
29
|
recommended: false,
|
|
29
30
|
manifest: true
|
|
@@ -40,7 +41,7 @@ export default {
|
|
|
40
41
|
additionalProperties: false
|
|
41
42
|
}],
|
|
42
43
|
defaultOptions: [{ order: [] }],
|
|
43
|
-
messages: { wrongOrder: '`{{first}}` should appear before `{{second}}
|
|
44
|
+
messages: { wrongOrder: '`{{first}}` should appear before `{{second}}`.' }
|
|
44
45
|
},
|
|
45
46
|
|
|
46
47
|
create(context) {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { getFilename } from '../utils.js'
|
|
2
|
+
|
|
3
|
+
const re = { manifestFilename: /manifest\.json$/ }
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
meta: {
|
|
7
|
+
type: 'problem',
|
|
8
|
+
docs: {
|
|
9
|
+
description: 'Disallow duplicate keys in manifest.json',
|
|
10
|
+
category: 'Possible Errors',
|
|
11
|
+
recommended: false,
|
|
12
|
+
manifest: true
|
|
13
|
+
},
|
|
14
|
+
schema: [],
|
|
15
|
+
messages: {
|
|
16
|
+
duplicateKey: 'Duplicate manifest key "{{key}}".'
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
create(context) {
|
|
21
|
+
if (!re.manifestFilename.test(getFilename(context))) return {}
|
|
22
|
+
return {
|
|
23
|
+
Object(node) {
|
|
24
|
+
const members = node.members || node.properties || [],
|
|
25
|
+
seen = new Set()
|
|
26
|
+
for (const member of members) {
|
|
27
|
+
const keyNode = member.name || member.key ; if (!keyNode) continue
|
|
28
|
+
const keyName = keyNode.value ?? keyNode.name ; if (typeof keyName != 'string') continue
|
|
29
|
+
if (seen.has(keyName))
|
|
30
|
+
context.report({ node: keyNode, messageId: 'duplicateKey', data: { key: keyName } })
|
|
31
|
+
else seen.add(keyName)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const re = { insecureURL: /^http:\/\/(?!localhost\b|127\.0\.0\.1\b|\[::1\])/i }
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
meta: {
|
|
5
|
+
type: 'problem',
|
|
6
|
+
docs: {
|
|
7
|
+
description: 'Flags `fetch()` and `XMLHttpRequest.open()` calls that use `http://`',
|
|
8
|
+
category: 'Possible Errors',
|
|
9
|
+
recommended: true,
|
|
10
|
+
security: true
|
|
11
|
+
},
|
|
12
|
+
schema: [],
|
|
13
|
+
messages: {
|
|
14
|
+
insecureFetch: '`fetch()` to "{{url}}" insecure. Use HTTPS or a relative path instead.',
|
|
15
|
+
insecureXHR: '`XMLHttpRequest.open()` to "{{url}}" insecure. Use HTTPS or a relative path instead.'
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
create(context) {
|
|
20
|
+
const xhrVars = new Set()
|
|
21
|
+
function urlFromLiteral(node) {
|
|
22
|
+
return ( node?.type == 'Literal'
|
|
23
|
+
&& typeof node.value == 'string'
|
|
24
|
+
&& re.insecureURL.test(node.value)
|
|
25
|
+
) ? node.value : null
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
VariableDeclarator(node) {
|
|
29
|
+
if (node.init?.type == 'NewExpression'
|
|
30
|
+
&& node.init.callee?.name == 'XMLHttpRequest'
|
|
31
|
+
&& node.id.type == 'Identifier'
|
|
32
|
+
) xhrVars.add(node.id.name)
|
|
33
|
+
},
|
|
34
|
+
CallExpression(node) {
|
|
35
|
+
if (node.callee.type == 'Identifier' && node.callee.name == 'fetch') {
|
|
36
|
+
const url = urlFromLiteral(node.arguments[0])
|
|
37
|
+
if (url)
|
|
38
|
+
context.report({ node: node.arguments[0], messageId: 'insecureFetch', data: { url }})
|
|
39
|
+
}
|
|
40
|
+
if (node.callee.type == 'MemberExpression'
|
|
41
|
+
&& node.callee.property?.name == 'open'
|
|
42
|
+
&& node.callee.object?.type == 'Identifier'
|
|
43
|
+
&& xhrVars.has(node.callee.object.name)
|
|
44
|
+
) {
|
|
45
|
+
const url = urlFromLiteral(node.arguments[1])
|
|
46
|
+
if (url)
|
|
47
|
+
context.report({ node: node.arguments[1], messageId: 'insecureXHR', data: { url }})
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -1,24 +1,46 @@
|
|
|
1
|
-
import { isExternalMessagingListener } from '../data/apis.js'
|
|
2
1
|
import { getMemberPath } from '../utils.js'
|
|
2
|
+
import { isExternalMessagingListener } from '../data/apis.js'
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const re = { postmsgValidation: /\b\w+\.(?:origin|source)\b/, senderValidation: /sender\.(?:id|origin)/ }
|
|
5
5
|
|
|
6
6
|
export default {
|
|
7
7
|
meta: {
|
|
8
8
|
type: 'problem',
|
|
9
9
|
docs: {
|
|
10
|
-
description: '
|
|
10
|
+
description: 'Requires sender/origin validation + filtered `tabs.query()` + explicit `window.postMessage()` target',
|
|
11
11
|
category: 'Possible Errors',
|
|
12
|
-
recommended: true
|
|
12
|
+
recommended: true,
|
|
13
|
+
security: true
|
|
13
14
|
},
|
|
14
|
-
|
|
15
|
+
defaultOptions: [{ disallowWildcardTarget: true }],
|
|
16
|
+
schema: [{
|
|
17
|
+
type: 'object',
|
|
18
|
+
properties: {
|
|
19
|
+
disallowWildcardTarget: {
|
|
20
|
+
type: 'boolean',
|
|
21
|
+
description: 'Flag postMessage calls that use "*" as targetOrigin'
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
additionalProperties: false
|
|
25
|
+
}],
|
|
15
26
|
messages: {
|
|
16
27
|
unvalidatedExternal: '`{{listener}}` handler must validate `sender.<id|origin>` before processing messages.',
|
|
17
|
-
unfilteredBroadcast: '`chrome.tabs.query({})`
|
|
28
|
+
unfilteredBroadcast: '`chrome.tabs.query({})` w/ no filter broadcasts to every open tab. Add `url` or `currentWindow` instead.',
|
|
29
|
+
unvalidatedPostMessage: '`{{target}}` message handler must validate `event.origin`/`event.source` before processing messages.',
|
|
30
|
+
wildcardTarget: '`postMessage` to `"*"` leaks data to any origin. Explicitly specify `targetOrigin` instead.'
|
|
18
31
|
}
|
|
19
32
|
},
|
|
20
33
|
|
|
21
34
|
create(context) {
|
|
35
|
+
const opts = context.options[0] || {},
|
|
36
|
+
disallowWildcard = opts.disallowWildcardTarget !== false
|
|
37
|
+
function checkPostMessageHandler(node, handlerNode, target) {
|
|
38
|
+
if (!handlerNode) return
|
|
39
|
+
const body = context.sourceCode.getText(handlerNode)
|
|
40
|
+
if (re.postmsgValidation.test(body)) return
|
|
41
|
+
context.report({ node, messageId: 'unvalidatedPostMessage', data: { target }})
|
|
42
|
+
}
|
|
43
|
+
function isMessageTarget(obj) { return obj?.type == 'Identifier' && ['self', 'window'].includes(obj.name) }
|
|
22
44
|
return {
|
|
23
45
|
CallExpression(node) {
|
|
24
46
|
if (node.callee.type != 'MemberExpression') return
|
|
@@ -27,7 +49,7 @@ export default {
|
|
|
27
49
|
if (listenerRoot && isExternalMessagingListener(listenerRoot)) {
|
|
28
50
|
const handler = node.arguments[0] ; if (!handler) return
|
|
29
51
|
const body = context.sourceCode.getText(handler)
|
|
30
|
-
if (!
|
|
52
|
+
if (!re.senderValidation.test(body))
|
|
31
53
|
context.report({ node, messageId: 'unvalidatedExternal', data: { listener: listenerRoot }})
|
|
32
54
|
}
|
|
33
55
|
if (path == 'chrome.tabs.query') {
|
|
@@ -36,6 +58,21 @@ export default {
|
|
|
36
58
|
if (isEmpty)
|
|
37
59
|
context.report({ node, messageId: 'unfilteredBroadcast' })
|
|
38
60
|
}
|
|
61
|
+
if (node.callee.property?.name == 'addEventListener'
|
|
62
|
+
&& node.arguments[0]?.value == 'message'
|
|
63
|
+
&& isMessageTarget(node.callee.object)
|
|
64
|
+
) checkPostMessageHandler(node, node.arguments[1], node.callee.object.name)
|
|
65
|
+
if (disallowWildcard && node.callee.property?.name == 'postMessage') {
|
|
66
|
+
const target = node.arguments[1]
|
|
67
|
+
if (target?.type == 'Literal' && target.value == '*')
|
|
68
|
+
context.report({ node: target, messageId: 'wildcardTarget' })
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
AssignmentExpression(node) {
|
|
72
|
+
if (node.left.type == 'MemberExpression'
|
|
73
|
+
&& node.left.property?.name == 'onmessage'
|
|
74
|
+
&& isMessageTarget(node.left.object)
|
|
75
|
+
) checkPostMessageHandler(node, node.right, node.left.object.name)
|
|
39
76
|
}
|
|
40
77
|
}
|
|
41
78
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isValidPermission } from '../data/permissions.js'
|
|
2
1
|
import { getFilename, readManifest } from '../utils.js'
|
|
2
|
+
import { isValidPermission } from '../data/permissions.js'
|
|
3
3
|
|
|
4
4
|
const re = { manifestFilename: /manifest\.json$/ }
|
|
5
5
|
|
|
@@ -9,7 +9,7 @@ export default {
|
|
|
9
9
|
docs: {
|
|
10
10
|
description: 'Disallow invalid or unsupported manifest permission names',
|
|
11
11
|
category: 'Possible Errors',
|
|
12
|
-
recommended:
|
|
12
|
+
recommended: false,
|
|
13
13
|
manifest: true
|
|
14
14
|
},
|
|
15
15
|
defaultOptions: [{ target: 'mv3', allowedPermissions: [] }],
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { getMemberPath, isContentScriptFile, readManifest } from '../utils.js'
|
|
2
|
+
|
|
3
|
+
const re = { leadingSlash: /^\//, regexSpecial: /[.+?^${}()|[\]\\]/g }
|
|
4
|
+
|
|
5
|
+
function collectWarPatterns(manifest) {
|
|
6
|
+
const war = manifest.web_accessible_resources
|
|
7
|
+
if (!Array.isArray(war)) return []
|
|
8
|
+
const patterns = []
|
|
9
|
+
for (const entry of war) {
|
|
10
|
+
if (typeof entry == 'string') patterns.push(entry) // MV2 flat
|
|
11
|
+
else if (Array.isArray(entry?.resources))
|
|
12
|
+
for (const res of entry.resources) patterns.push(res) // MV3 object
|
|
13
|
+
}
|
|
14
|
+
return patterns
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function patternToRegex(pattern) {
|
|
18
|
+
const escaped = pattern.replace(re.regexSpecial, '\\$&').replace(/\*/g, '.*')
|
|
19
|
+
return new RegExp(`^${escaped}$`) // eslint-disable-line security/detect-non-literal-regexp
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default {
|
|
23
|
+
meta: {
|
|
24
|
+
type: 'problem',
|
|
25
|
+
docs: {
|
|
26
|
+
description: 'Require content-script getURL() paths to be listed in `web_accessible_resources`',
|
|
27
|
+
category: 'Possible Errors',
|
|
28
|
+
recommended: true
|
|
29
|
+
},
|
|
30
|
+
schema: [],
|
|
31
|
+
messages: {
|
|
32
|
+
missingWar: '`{{path}}` is not in `web_accessible_resources`.'
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
create(context) {
|
|
37
|
+
const manifest = readManifest(context) ; if (!manifest) return {}
|
|
38
|
+
if (!isContentScriptFile(context, manifest)) return {}
|
|
39
|
+
const regexes = collectWarPatterns(manifest).map(patternToRegex)
|
|
40
|
+
return {
|
|
41
|
+
CallExpression(node) {
|
|
42
|
+
if (node.callee.type != 'MemberExpression') return
|
|
43
|
+
if (getMemberPath(node.callee) != 'chrome.runtime.getURL') return
|
|
44
|
+
const arg = node.arguments[0] ; if (arg?.type != 'Literal' || typeof arg.value != 'string') return
|
|
45
|
+
const resourcePath = arg.value.replace(re.leadingSlash, '')
|
|
46
|
+
for (const regex of regexes) if (regex.test(resourcePath)) return
|
|
47
|
+
context.report({ node: arg, messageId: 'missingWar', data: { path: arg.value }})
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { remoteCodePatterns } from '../data/manifest.js'
|
|
2
|
+
|
|
2
3
|
import { getMemberPath } from '../utils.js'
|
|
3
4
|
|
|
4
5
|
const re = { url: /^https?:\/\// }
|
|
@@ -7,9 +8,10 @@ export default {
|
|
|
7
8
|
meta: {
|
|
8
9
|
type: 'problem',
|
|
9
10
|
docs: {
|
|
10
|
-
description: 'Disallow remote or dynamically-evaluated code, per
|
|
11
|
+
description: 'Disallow remote or dynamically-evaluated code, per MV3\'s CSP',
|
|
11
12
|
category: 'Possible Errors',
|
|
12
|
-
recommended: true
|
|
13
|
+
recommended: true,
|
|
14
|
+
security: true
|
|
13
15
|
},
|
|
14
16
|
defaultOptions: [{
|
|
15
17
|
patterns: ['eval', 'new-function', 'string-timer',
|
|
@@ -26,19 +28,19 @@ export default {
|
|
|
26
28
|
},
|
|
27
29
|
checkExecuteScriptClosures: {
|
|
28
30
|
type: 'boolean',
|
|
29
|
-
description: 'Flag chrome.scripting.executeScript calls whose func captures outer scope'
|
|
31
|
+
description: 'Flag `chrome.scripting.executeScript` calls whose func captures outer scope'
|
|
30
32
|
}
|
|
31
33
|
},
|
|
32
34
|
additionalProperties: false
|
|
33
35
|
}],
|
|
34
36
|
messages: {
|
|
35
|
-
eval: '`eval()` is forbidden under MV3\'s CSP
|
|
36
|
-
newFunction: '`new Function()` is forbidden under MV3\'s CSP
|
|
37
|
-
stringTimer: 'String-argument `{{fn}}` is forbidden under MV3\'s CSP
|
|
38
|
-
dynamicImport: 'Remote dynamic `import()` is forbidden under MV3\'s CSP
|
|
39
|
-
remoteScriptSrc: 'Injecting remote `<script src>` is forbidden under MV3\'s CSP
|
|
37
|
+
eval: '`eval()` is forbidden under MV3\'s CSP. Use static code instead.',
|
|
38
|
+
newFunction: '`new Function()` is forbidden under MV3\'s CSP. Use a real function instead.',
|
|
39
|
+
stringTimer: 'String-argument `{{fn}}` is forbidden under MV3\'s CSP. Pass a function reference instead.',
|
|
40
|
+
dynamicImport: 'Remote dynamic `import()` is forbidden under MV3\'s CSP. Use a relative path instead.',
|
|
41
|
+
remoteScriptSrc: 'Injecting remote `<script src>` is forbidden under MV3\'s CSP. Use `chrome.runtime.getURL()` for bundled scripts instead.',
|
|
40
42
|
executeScriptURL: '`chrome.scripting.executeScript` must use local `files`, not a remote URL.',
|
|
41
|
-
executeScriptClosure: '`chrome.scripting.executeScript({ func })` captures outer-scope variables that fail after serialization
|
|
43
|
+
executeScriptClosure: '`chrome.scripting.executeScript({ func })` captures outer-scope variables that fail after serialization. Pass them via `args` instead.'
|
|
42
44
|
}
|
|
43
45
|
},
|
|
44
46
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { getFilename } from '../utils.js'
|
|
2
|
+
|
|
3
|
+
const re = { broadHost: /^(?:<all_urls>|\*:\/\/\*\/\*|\w+:\/\/\*\/\*)$/, manifestFilename: /manifest\.json$/ },
|
|
4
|
+
hostKeys = new Set(['host_permissions', 'optional_host_permissions', 'optional_permissions', 'permissions'])
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
meta: {
|
|
8
|
+
type: 'problem',
|
|
9
|
+
docs: {
|
|
10
|
+
description: 'Disallow broad host permissions that grant access to every site',
|
|
11
|
+
category: 'Possible Errors',
|
|
12
|
+
recommended: false,
|
|
13
|
+
manifest: true
|
|
14
|
+
},
|
|
15
|
+
defaultOptions: [{ allowedPatterns: [] }],
|
|
16
|
+
schema: [{
|
|
17
|
+
type: 'object',
|
|
18
|
+
properties: {
|
|
19
|
+
allowedPatterns: {
|
|
20
|
+
type: 'array',
|
|
21
|
+
items: { type: 'string' },
|
|
22
|
+
description: 'Host patterns to explicitly allow despite being broad'
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
additionalProperties: false
|
|
26
|
+
}],
|
|
27
|
+
messages: {
|
|
28
|
+
unrestrictedHost: 'Host permission "{{pattern}}" grants access to every site. Narrow to specific origins or allow explicitly instead.'
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
create(context) {
|
|
33
|
+
if (!re.manifestFilename.test(getFilename(context))) return {}
|
|
34
|
+
const allowed = new Set(context.options[0]?.allowedPatterns || [])
|
|
35
|
+
return {
|
|
36
|
+
'*'(node) {
|
|
37
|
+
const keyNode = node.name || node.key ; if (!keyNode) return
|
|
38
|
+
const keyName = keyNode.value ?? keyNode.name
|
|
39
|
+
if (!hostKeys.has(keyName)) return
|
|
40
|
+
const arrNode = node.value ; if (arrNode?.type != 'Array') return
|
|
41
|
+
const elements = arrNode.elements || arrNode.items || []
|
|
42
|
+
for (const el of elements) {
|
|
43
|
+
const valueNode = el.value || el,
|
|
44
|
+
pattern = valueNode?.value
|
|
45
|
+
if (typeof pattern != 'string'
|
|
46
|
+
|| allowed.has(pattern)
|
|
47
|
+
|| !re.broadHost.test(pattern)
|
|
48
|
+
) continue
|
|
49
|
+
context.report({ node: valueNode, messageId: 'unrestrictedHost', data: { pattern }})
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
package/src/rules/require-mv3.js
CHANGED
|
@@ -8,12 +8,12 @@ export default {
|
|
|
8
8
|
docs: {
|
|
9
9
|
description: 'Require manifest_version 3',
|
|
10
10
|
category: 'Possible Errors',
|
|
11
|
-
recommended:
|
|
11
|
+
recommended: false,
|
|
12
12
|
manifest: true
|
|
13
13
|
},
|
|
14
14
|
schema: [],
|
|
15
15
|
messages: {
|
|
16
|
-
notMV3: 'manifest.json must declare `"manifest_version": 3
|
|
16
|
+
notMV3: 'manifest.json must declare `"manifest_version": 3`.'
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
|
|
4
|
+
import { findExtensionRoot, getFilename } from '../utils.js'
|
|
5
|
+
|
|
6
|
+
const re = { manifestFilename: /manifest\.json$/, svg: /\.svg$/i },
|
|
7
|
+
sizes = { recommended: ['16', '32', '48', '128'], required: '128' }
|
|
8
|
+
|
|
9
|
+
export default {
|
|
10
|
+
meta: {
|
|
11
|
+
type: 'problem',
|
|
12
|
+
docs: {
|
|
13
|
+
description: 'Validate manifest icons: sizes, existing files, no SVG',
|
|
14
|
+
category: 'Possible Errors',
|
|
15
|
+
recommended: false,
|
|
16
|
+
manifest: true
|
|
17
|
+
},
|
|
18
|
+
defaultOptions: [{
|
|
19
|
+
requireRecommendedSizes: true,
|
|
20
|
+
checkIconExists: true,
|
|
21
|
+
noSVG: true
|
|
22
|
+
}],
|
|
23
|
+
schema: [{
|
|
24
|
+
type: 'object',
|
|
25
|
+
properties: {
|
|
26
|
+
requireRecommendedSizes: {
|
|
27
|
+
type: 'boolean',
|
|
28
|
+
description: 'Require all recommended sizes (16, 32, 48, 128)'
|
|
29
|
+
},
|
|
30
|
+
checkIconExists: {
|
|
31
|
+
type: 'boolean',
|
|
32
|
+
description: 'Flag icon paths that do not resolve to a file'
|
|
33
|
+
},
|
|
34
|
+
noSVG: {
|
|
35
|
+
type: 'boolean',
|
|
36
|
+
description: 'Flag SVG icon paths (unsupported by Chrome)'
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
additionalProperties: false
|
|
40
|
+
}],
|
|
41
|
+
messages: {
|
|
42
|
+
missingSize: 'Recommended icon size "{{size}}" is missing (16, 32, 48, 128).',
|
|
43
|
+
missingRequiredSize: 'Icons must include a 128x128 icon.',
|
|
44
|
+
missingFile: 'Icon file "{{file}}" does not exist in the extension root.',
|
|
45
|
+
svgNotSupported: 'SVG icons are not supported by Chrome. Use PNG instead.'
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
create(context) {
|
|
50
|
+
if (!re.manifestFilename.test(getFilename(context))) return {}
|
|
51
|
+
const opts = context.options[0] || {},
|
|
52
|
+
requireRecommended = opts.requireRecommendedSizes !== false,
|
|
53
|
+
checkFiles = opts.checkIconExists !== false,
|
|
54
|
+
checkSVG = opts.noSVG !== false
|
|
55
|
+
const root = checkFiles ? findExtensionRoot(context) : null
|
|
56
|
+
return {
|
|
57
|
+
'*'(node) {
|
|
58
|
+
const keyNode = node.name || node.key ; if (!keyNode) return
|
|
59
|
+
const keyName = keyNode.value ?? keyNode.name ; if (keyName != 'icons') return
|
|
60
|
+
const iconsObj = node.value ; if (iconsObj?.type != 'Object') return
|
|
61
|
+
const members = iconsObj.members || iconsObj.properties || []
|
|
62
|
+
const declaredSizes = new Set()
|
|
63
|
+
for (const member of members) {
|
|
64
|
+
const sizeNode = member.name || member.key,
|
|
65
|
+
size = sizeNode?.value ?? sizeNode?.name,
|
|
66
|
+
fileNode = member.value,
|
|
67
|
+
file = fileNode?.value
|
|
68
|
+
if (typeof size == 'string') declaredSizes.add(size)
|
|
69
|
+
if (typeof file != 'string') continue
|
|
70
|
+
if (checkSVG && re.svg.test(file))
|
|
71
|
+
context.report({ node: fileNode, messageId: 'svgNotSupported' })
|
|
72
|
+
else if (checkFiles && root // eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
73
|
+
&& !fs.existsSync(path.resolve(root, file))
|
|
74
|
+
) context.report({ node: fileNode, messageId: 'missingFile', data: { file }})
|
|
75
|
+
}
|
|
76
|
+
if (requireRecommended) {
|
|
77
|
+
for (const size of sizes.recommended)
|
|
78
|
+
if (!declaredSizes.has(size))
|
|
79
|
+
context.report({ node: iconsObj, messageId: 'missingSize', data: { size }})
|
|
80
|
+
} else if (!declaredSizes.has(sizes.required))
|
|
81
|
+
context.report({ node: iconsObj, messageId: 'missingRequiredSize' })
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { mv2OnlyKeys, forbiddenCSPdirectives } from '../data/manifest.js'
|
|
2
|
+
|
|
2
3
|
import { getFilename, readManifest } from '../utils.js'
|
|
3
4
|
|
|
4
5
|
const re = { manifestFilename: /manifest\.json$/ }
|
|
@@ -9,12 +10,12 @@ export default {
|
|
|
9
10
|
docs: {
|
|
10
11
|
description: 'Validate manifest against the MV3 schema',
|
|
11
12
|
category: 'Possible Errors',
|
|
12
|
-
recommended:
|
|
13
|
+
recommended: false,
|
|
13
14
|
manifest: true
|
|
14
15
|
},
|
|
15
16
|
schema: [],
|
|
16
17
|
messages: {
|
|
17
|
-
mv2Key: '`{{key}}` is not allowed in MV3
|
|
18
|
+
mv2Key: '`{{key}}` is not allowed in MV3. {{reason}}.',
|
|
18
19
|
unsafeCSP: 'MV3 CSP must not include `{{directive}}`.',
|
|
19
20
|
wrongCSPType: '`content_security_policy` must be an object in MV3, not a string.'
|
|
20
21
|
}
|
|
@@ -12,7 +12,7 @@ export default {
|
|
|
12
12
|
schema: [],
|
|
13
13
|
messages: {
|
|
14
14
|
listenerNotTopLevel: '`chrome.*.addListener()` must be registered at module top level so it attaches on service worker wake-up.',
|
|
15
|
-
keepaliveTimer: 'Sub-30s `{{fn}}` will not keep the MV3 service worker alive
|
|
15
|
+
keepaliveTimer: 'Sub-30s `{{fn}}` will not keep the MV3 service worker alive. Use `chrome.alarms` instead.',
|
|
16
16
|
domInSW: '`{{global}}` is not available in a service worker.'
|
|
17
17
|
}
|
|
18
18
|
},
|
|
@@ -13,7 +13,7 @@ export default {
|
|
|
13
13
|
docs: {
|
|
14
14
|
description: 'Validate the manifest version field format',
|
|
15
15
|
category: 'Possible Errors',
|
|
16
|
-
recommended:
|
|
16
|
+
recommended: false,
|
|
17
17
|
manifest: true
|
|
18
18
|
},
|
|
19
19
|
schema: [{
|
|
@@ -37,8 +37,8 @@ export default {
|
|
|
37
37
|
}],
|
|
38
38
|
defaultOptions: [{}],
|
|
39
39
|
messages: {
|
|
40
|
-
invalidVersion: 'Invalid manifest `version`: must be a valid {{versionType}} version (expected format: {{example}})',
|
|
41
|
-
futureVersion: 'Invalid manifest `version`: date cannot be in the future'
|
|
40
|
+
invalidVersion: 'Invalid manifest `version`: must be a valid {{versionType}} version (expected format: {{example}}).',
|
|
41
|
+
futureVersion: 'Invalid manifest `version`: date cannot be in the future.'
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
44
|
|
package/src/utils.js
CHANGED
|
@@ -4,12 +4,26 @@ import path from 'node:path'
|
|
|
4
4
|
const re = { chromeAPI: /\bchrome(?:\.\w+)+/g }, // eslint-disable-line security/detect-unsafe-regex
|
|
5
5
|
manifestCache = new Map()
|
|
6
6
|
|
|
7
|
-
export function bundleRules(rules, predicate, pluginName) {
|
|
7
|
+
export function bundleRules(rules, predicate, pluginName, removals = []) {
|
|
8
8
|
return Object.fromEntries(Object.entries(rules)
|
|
9
|
-
.filter(([, rule]) => predicate(rule))
|
|
9
|
+
.filter(([ruleId, rule]) => predicate(rule) || removals.includes(ruleId))
|
|
10
10
|
.map(([ruleId]) => [`${pluginName}/${ruleId}`, 'error']))
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
export function deprecatedFrom(bundles, bundleName) {
|
|
14
|
+
const ruleIds = []
|
|
15
|
+
for (const [ruleId, [bundle]] of Object.entries(bundles))
|
|
16
|
+
if (bundle === bundleName) ruleIds.push(ruleId)
|
|
17
|
+
return ruleIds
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function initBundleDeprecation(plugin, [ruleId, [bundleName, note]], pluginName) {
|
|
21
|
+
if (!process.env.DEBUG_MODE) return
|
|
22
|
+
if (plugin.rules[ruleId]) // eslint-disable-line security/detect-object-injection
|
|
23
|
+
console.warn(`[${pluginName}] '${ruleId}' will be removed from '${
|
|
24
|
+
bundleName}' in a future major release${note ? ` (${note})` : ''}`)
|
|
25
|
+
}
|
|
26
|
+
|
|
13
27
|
export function findExtensionRoot(context) {
|
|
14
28
|
let dir = path.dirname(getFilename(context))
|
|
15
29
|
while (dir) {
|