tabsmith-lint 0.1.1 → 0.2.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 +13 -3
- package/dist/cli.js +2 -1
- package/dist/rules/mv3.js +111 -5
- package/dist/rules/permissions.js +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
# tabsmith-lint
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<p>
|
|
4
|
+
<a href="https://www.npmjs.com/package/tabsmith-lint"><img alt="npm version" height="28" src="https://img.shields.io/npm/v/tabsmith-lint?logo=npm&color=cb3837"></a>
|
|
5
|
+
<a href="https://www.npmjs.com/package/tabsmith-lint"><img alt="npm downloads" height="28" src="https://img.shields.io/npm/dt/tabsmith-lint?logo=npm&color=cb3837"></a>
|
|
6
|
+
<a href="https://github.com/rsub122/tabsmith-lint/actions/workflows/ci.yml"><img alt="CI" height="28" src="https://img.shields.io/github/actions/workflow/status/rsub122/tabsmith-lint/ci.yml?branch=main&logo=github&label=CI"></a>
|
|
7
|
+
<a href="https://github.com/rsub122/tabsmith-lint/blob/main/package.json"><img alt="node" height="28" src="https://img.shields.io/node/v/tabsmith-lint?logo=node.js"></a>
|
|
8
|
+
<a href="LICENSE"><img alt="license" height="28" src="https://img.shields.io/npm/l/tabsmith-lint?color=blue"></a>
|
|
9
|
+
<a href="https://packagephobia.com/result?p=tabsmith-lint"><img alt="install size" height="28" src="https://packagephobia.com/badge?p=tabsmith-lint"></a>
|
|
10
|
+
<a href="https://github.com/rsub122/tabsmith-lint/stargazers"><img alt="GitHub stars" height="28" src="https://img.shields.io/github/stars/rsub122/tabsmith-lint?style=flat&logo=github"></a>
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
A pre-submission compliance linter for browser extensions. It analyzes an unpacked
|
|
4
14
|
Manifest V3 Chrome extension directory and reports likely Chrome Web Store rejection
|
|
5
15
|
risks **before** you submit — unused/excessive permissions, missing permissions, MV3
|
|
6
16
|
violations, and broken file references — with a clear verdict and actionable fixes.
|
|
@@ -14,7 +24,7 @@ Chrome reviewers flag:
|
|
|
14
24
|
| Violation ID | What it means | tabsmith rules |
|
|
15
25
|
|---|---|---|
|
|
16
26
|
| Purple Potassium | Excessive / unused permissions | PERM001, PERM003, PERM004, PERM005 |
|
|
17
|
-
| Blue Argon | Remotely hosted code / string execution | MV3001, MV3002 |
|
|
27
|
+
| Blue Argon | Remotely hosted code / string execution / forbidden CSP | MV3001, MV3002, MV3004 |
|
|
18
28
|
| Yellow Magnesium | Functionality / broken packaging | FUNC001, FUNC002 |
|
|
19
29
|
|
|
20
30
|
```bash
|
|
@@ -72,7 +82,7 @@ exists, leave the severity at `fix`.
|
|
|
72
82
|
|
|
73
83
|
## Status
|
|
74
84
|
|
|
75
|
-
|
|
85
|
+
Chrome-only, directory input, 12 rules (PERM001-005, MV3001-004, FUNC001-002).
|
|
76
86
|
|
|
77
87
|
Firefox/Edge, ZIP/CRX input, SARIF, and a GitHub Action are on the roadmap.
|
|
78
88
|
|
package/dist/cli.js
CHANGED
|
@@ -23,7 +23,8 @@ function helpText() {
|
|
|
23
23
|
Point it at an unpacked extension directory and it flags likely Chrome Web Store
|
|
24
24
|
rejection risks before you submit:
|
|
25
25
|
- unused / excessive permissions (the "Purple Potassium" rejection)
|
|
26
|
-
- Manifest V3 violations: remotely hosted code
|
|
26
|
+
- Manifest V3 violations: remotely hosted code (script tags, import, importScripts),
|
|
27
|
+
string execution, forbidden extension-page CSP, Manifest V2
|
|
27
28
|
- broken packaging: missing or wrong-case file references
|
|
28
29
|
|
|
29
30
|
${USAGE}
|
package/dist/rules/mv3.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { walk } from "../parse/parse-script.js";
|
|
2
|
-
import { findLineByIndex } from "../engine/source-lines.js";
|
|
2
|
+
import { findLine, findLineByIndex } from "../engine/source-lines.js";
|
|
3
3
|
// MV3002 (string execution: eval/new Function/string timers) ships at `fix`, not
|
|
4
4
|
// `reject`, in v0.1. The pattern is a real MV3 CSP concern, but static analysis
|
|
5
5
|
// cannot tell whether the call is reachable or runs in a sandboxed context — and
|
|
@@ -42,6 +42,16 @@ function mv3001(model) {
|
|
|
42
42
|
if (node.type === "CallExpression" && node.callee?.type === "Import" && isRemote(node.arguments?.[0]?.value)) {
|
|
43
43
|
findings.push(remoteImport(script.relPath, node, node.arguments[0].value));
|
|
44
44
|
}
|
|
45
|
+
// importScripts("https://...") — the classic service-worker remote loader.
|
|
46
|
+
// Only string-literal (or expression-free template) arguments are judged;
|
|
47
|
+
// computed URLs are left alone (no guessing).
|
|
48
|
+
if (node.type === "CallExpression" && isImportScriptsCallee(node.callee)) {
|
|
49
|
+
for (const arg of node.arguments ?? []) {
|
|
50
|
+
const url = staticString(arg);
|
|
51
|
+
if (isRemote(url))
|
|
52
|
+
findings.push(remoteImport(script.relPath, node, url, "importScripts"));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
45
55
|
});
|
|
46
56
|
}
|
|
47
57
|
return findings;
|
|
@@ -49,17 +59,41 @@ function mv3001(model) {
|
|
|
49
59
|
function isRemote(v) {
|
|
50
60
|
return typeof v === "string" && /^(https?:)?\/\//i.test(v);
|
|
51
61
|
}
|
|
52
|
-
|
|
62
|
+
/** importScripts, self.importScripts, globalThis.importScripts. */
|
|
63
|
+
function isImportScriptsCallee(callee) {
|
|
64
|
+
if (callee?.type === "Identifier")
|
|
65
|
+
return callee.name === "importScripts";
|
|
66
|
+
return (callee?.type === "MemberExpression" &&
|
|
67
|
+
!callee.computed &&
|
|
68
|
+
callee.property?.type === "Identifier" &&
|
|
69
|
+
callee.property.name === "importScripts" &&
|
|
70
|
+
callee.object?.type === "Identifier" &&
|
|
71
|
+
(callee.object.name === "self" || callee.object.name === "globalThis"));
|
|
72
|
+
}
|
|
73
|
+
/** The value of a string literal or an expression-free template literal, else null. */
|
|
74
|
+
function staticString(arg) {
|
|
75
|
+
if (arg?.type === "StringLiteral")
|
|
76
|
+
return arg.value;
|
|
77
|
+
if (arg?.type === "TemplateLiteral" && arg.expressions?.length === 0 && arg.quasis?.length === 1) {
|
|
78
|
+
return arg.quasis[0].value?.cooked ?? null;
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
function remoteImport(file, node, url, via = "import") {
|
|
53
83
|
return {
|
|
54
84
|
ruleId: "MV3001",
|
|
55
85
|
severity: "reject",
|
|
56
86
|
confidence: "high",
|
|
57
87
|
title: "Remotely hosted code referenced",
|
|
58
|
-
message:
|
|
88
|
+
message: via === "importScripts"
|
|
89
|
+
? `importScripts("${url}") loads code from a remote URL, which Manifest V3 forbids.`
|
|
90
|
+
: `import of "${url}" loads code from a remote URL, which Manifest V3 forbids.`,
|
|
59
91
|
file,
|
|
60
92
|
line: node.loc?.start.line,
|
|
61
93
|
chromeViolationId: "Blue Argon",
|
|
62
|
-
fixHint:
|
|
94
|
+
fixHint: via === "importScripts"
|
|
95
|
+
? "Bundle the script inside the extension package and importScripts() the local copy."
|
|
96
|
+
: "Bundle the dependency inside the extension package instead of importing it remotely.",
|
|
63
97
|
};
|
|
64
98
|
}
|
|
65
99
|
const STRING_TIMERS = new Set(["setTimeout", "setInterval"]);
|
|
@@ -118,4 +152,76 @@ function mv3003(model) {
|
|
|
118
152
|
fixHint: "Migrate the extension to Manifest V3.",
|
|
119
153
|
}];
|
|
120
154
|
}
|
|
121
|
-
|
|
155
|
+
// MV3004 — extension-page CSP that Chrome's Manifest V3 forbids. For
|
|
156
|
+
// `content_security_policy.extension_pages`, script-src / object-src / worker-src
|
|
157
|
+
// may only contain 'self', 'none', 'wasm-unsafe-eval', 'inline-speculation-rules'
|
|
158
|
+
// and localhost sources; anything laxer (unsafe-eval, unsafe-inline, remote
|
|
159
|
+
// origins) makes Chrome refuse to load the extension. The `sandbox` policy is
|
|
160
|
+
// exempt and is never inspected. Nonces/hashes are not judged (conservative).
|
|
161
|
+
const CSP_RESTRICTED = new Set(["script-src", "object-src", "worker-src"]);
|
|
162
|
+
const CSP_ALLOWED_KEYWORDS = new Set(["'self'", "'none'", "'wasm-unsafe-eval'", "'inline-speculation-rules'"]);
|
|
163
|
+
const CSP_LOCALHOST_RE = /^(https?:\/\/)?(localhost|127\.0\.0\.1)(:(\d+|\*))?(\/.*)?$/i;
|
|
164
|
+
function cspViolations(policy) {
|
|
165
|
+
const bad = [];
|
|
166
|
+
for (const directive of policy.split(";")) {
|
|
167
|
+
const [rawName, ...sources] = directive.trim().split(/\s+/);
|
|
168
|
+
const name = rawName?.toLowerCase();
|
|
169
|
+
if (!name || !CSP_RESTRICTED.has(name))
|
|
170
|
+
continue;
|
|
171
|
+
for (const src of sources) {
|
|
172
|
+
const lower = src.toLowerCase();
|
|
173
|
+
if (CSP_ALLOWED_KEYWORDS.has(lower))
|
|
174
|
+
continue;
|
|
175
|
+
if (lower.startsWith("'nonce-") || lower.startsWith("'sha"))
|
|
176
|
+
continue; // not judged
|
|
177
|
+
if (lower === "'unsafe-eval'" || lower === "'unsafe-inline'") {
|
|
178
|
+
bad.push(`${name} ${src}`);
|
|
179
|
+
}
|
|
180
|
+
else if (lower.startsWith("'")) {
|
|
181
|
+
continue; // unknown keyword — don't guess
|
|
182
|
+
}
|
|
183
|
+
else if (!CSP_LOCALHOST_RE.test(src)) {
|
|
184
|
+
bad.push(`${name} ${src}`); // remote origin, wildcard, or scheme source
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return bad;
|
|
189
|
+
}
|
|
190
|
+
function mv3004(model) {
|
|
191
|
+
if (model.manifest.manifest_version !== 3)
|
|
192
|
+
return [];
|
|
193
|
+
const csp = model.manifest.content_security_policy;
|
|
194
|
+
if (csp === undefined || csp === null)
|
|
195
|
+
return [];
|
|
196
|
+
const line = findLine(model.manifestRaw, "content_security_policy");
|
|
197
|
+
if (typeof csp === "string") {
|
|
198
|
+
return [{
|
|
199
|
+
ruleId: "MV3004",
|
|
200
|
+
severity: "reject",
|
|
201
|
+
confidence: "high",
|
|
202
|
+
title: "content_security_policy must be an object in Manifest V3",
|
|
203
|
+
message: 'content_security_policy is a string (the Manifest V2 form). Manifest V3 requires an object such as {"extension_pages": "script-src \'self\'; object-src \'self\'"}.',
|
|
204
|
+
file: "manifest.json",
|
|
205
|
+
line,
|
|
206
|
+
fixHint: 'Use {"extension_pages": "..."} (and "sandbox" if needed) instead of a single string.',
|
|
207
|
+
}];
|
|
208
|
+
}
|
|
209
|
+
const pages = csp && typeof csp === "object" ? csp.extension_pages : undefined;
|
|
210
|
+
if (typeof pages !== "string")
|
|
211
|
+
return [];
|
|
212
|
+
const bad = cspViolations(pages);
|
|
213
|
+
if (bad.length === 0)
|
|
214
|
+
return [];
|
|
215
|
+
return [{
|
|
216
|
+
ruleId: "MV3004",
|
|
217
|
+
severity: "reject",
|
|
218
|
+
confidence: "high",
|
|
219
|
+
title: "extension_pages CSP is looser than Manifest V3 allows",
|
|
220
|
+
message: `content_security_policy.extension_pages contains ${bad.map((b) => `"${b}"`).join(", ")}. Manifest V3 only allows 'self', 'none', 'wasm-unsafe-eval' and localhost sources for script-src, object-src and worker-src, so Chrome will not load or accept this extension.`,
|
|
221
|
+
file: "manifest.json",
|
|
222
|
+
line: findLine(model.manifestRaw, "extension_pages") ?? line,
|
|
223
|
+
chromeViolationId: "Blue Argon",
|
|
224
|
+
fixHint: "Remove the remote origins and 'unsafe-*' keywords; bundle code locally. If eval is unavoidable, move that code to a sandboxed page (content_security_policy.sandbox).",
|
|
225
|
+
}];
|
|
226
|
+
}
|
|
227
|
+
export const mv3Rules = [mv3001, mv3002, mv3003, mv3004];
|
|
@@ -58,20 +58,20 @@ function perm001(model) {
|
|
|
58
58
|
if (mapping.namespace) {
|
|
59
59
|
const used = apiCalls.some((c) => c.namespace === mapping.namespace) || isUsedViaManifest(perm, manifest);
|
|
60
60
|
if (!used) {
|
|
61
|
-
findings.push(unusedFinding(model, perm, dynamicConfidence, `No chrome.${mapping.namespace}
|
|
61
|
+
findings.push(unusedFinding(model, perm, dynamicConfidence, `No chrome.${mapping.namespace} usage found. It would count as used if your code calls chrome.${mapping.namespace}.* (directly, via an alias or destructure, or after a chrome.permissions.request).`));
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
else if (mapping.special === "sensitiveTabProperties") {
|
|
65
65
|
// `tabs` is "used" only via sensitive Tab property reads. When broad host
|
|
66
66
|
// is present, redundancy is owned by PERM004 — don't double-flag here.
|
|
67
67
|
if (!broad && model.sensitiveTabReads.length === 0) {
|
|
68
|
-
findings.push(unusedFinding(model, perm, dynamicConfidence, `The "tabs" permission only grants sensitive Tab properties (url, title,
|
|
68
|
+
findings.push(unusedFinding(model, perm, dynamicConfidence, `The "tabs" permission only grants sensitive Tab properties (url, pendingUrl, title, favIconUrl), and none are read. It would count as used if your code reads one of those, e.g. tab.url, including off a chrome.tabs.onUpdated changeInfo.`));
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
else if (mapping.special === "temporaryHostAccess") {
|
|
72
72
|
// `activeTab` is plausibly used only behind a user-gesture entry point.
|
|
73
73
|
if (!hasGestureEntryPoint(manifest, declared)) {
|
|
74
|
-
findings.push(unusedFinding(model, perm, "medium", `"activeTab" has no user-gesture entry point
|
|
74
|
+
findings.push(unusedFinding(model, perm, "medium", `"activeTab" has no user-gesture entry point to trigger it. It would count as used if the manifest exposes an action, command, or context menu.`));
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tabsmith-lint",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Pre-submission compliance linter for Manifest V3 Chrome extensions: flags likely Chrome Web Store rejection risks (unused/excessive permissions, MV3 violations, broken packaging) before you submit.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|