tabsmith-lint 0.1.0 → 0.1.3
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 +1 -4
- package/dist/engine/analyze.js +1 -0
- package/dist/parse/extract-api-calls.js +26 -1
- package/dist/rules/permissions.js +9 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -25,10 +25,7 @@ npx tabsmith-lint ./my-extension --min-severity reject
|
|
|
25
25
|
|
|
26
26
|
Exit codes: `0` pass · `1` needs fixes · `2` high rejection risk · `3` tool error.
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
> but **not yet on npm**, so `npx tabsmith-lint` resolves only after the first
|
|
30
|
-
> `npm publish`. Until then, run it from a clone: `npm install && npm run build &&
|
|
31
|
-
> node dist/cli.js ./my-extension`.
|
|
28
|
+
No install needed — `npx` runs the latest published version. Or install it: `npm i -g tabsmith-lint`.
|
|
32
29
|
|
|
33
30
|
## Develop
|
|
34
31
|
|
package/dist/engine/analyze.js
CHANGED
|
@@ -32,6 +32,7 @@ export function analyze(rootDir, options) {
|
|
|
32
32
|
dynamicApiAccess: extraction.dynamicApiAccess,
|
|
33
33
|
hostAccessSignals,
|
|
34
34
|
manifestRefs: manifestRefs.all,
|
|
35
|
+
runtimeRequestedPermissions: extraction.runtimeRequestedPermissions,
|
|
35
36
|
};
|
|
36
37
|
const ruleFindings = runRules(model);
|
|
37
38
|
const parseFindings = scriptFiles
|
|
@@ -139,11 +139,29 @@ function isTabish(obj) {
|
|
|
139
139
|
function isAbsoluteUrlArg(arg) {
|
|
140
140
|
return arg?.type === "StringLiteral" && /^https?:\/\//i.test(arg.value);
|
|
141
141
|
}
|
|
142
|
+
/** Pull permission-name string literals out of a `{ permissions: [...] }` object
|
|
143
|
+
* literal (the argument to chrome.permissions.request/contains/remove). */
|
|
144
|
+
function collectRequestedPerms(arg, out) {
|
|
145
|
+
if (arg?.type !== "ObjectExpression")
|
|
146
|
+
return;
|
|
147
|
+
for (const prop of arg.properties ?? []) {
|
|
148
|
+
const key = prop.key;
|
|
149
|
+
const keyName = key?.type === "Identifier" ? key.name : key?.type === "StringLiteral" ? key.value : undefined;
|
|
150
|
+
if (keyName === "permissions" && prop.value?.type === "ArrayExpression") {
|
|
151
|
+
for (const el of prop.value.elements) {
|
|
152
|
+
if (el?.type === "StringLiteral")
|
|
153
|
+
out.push(el.value);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
const PERMISSION_REQUEST_METHODS = new Set(["request", "contains", "remove"]);
|
|
142
159
|
export function extractFromScripts(scripts) {
|
|
143
160
|
const apiCalls = [];
|
|
144
161
|
const sensitiveTabReads = [];
|
|
145
162
|
const dynamicApiAccess = [];
|
|
146
163
|
const hostAccessSignals = [];
|
|
164
|
+
const runtimeRequestedPermissions = [];
|
|
147
165
|
for (const script of scripts) {
|
|
148
166
|
if (!script.ast || script.parseError)
|
|
149
167
|
continue;
|
|
@@ -183,7 +201,14 @@ export function extractFromScripts(scripts) {
|
|
|
183
201
|
if (node.type === "NewExpression" && node.callee?.type === "Identifier" && node.callee.name === "XMLHttpRequest") {
|
|
184
202
|
hostAccessSignals.push({ kind: "xhr", file, line: node.loc?.start.line });
|
|
185
203
|
}
|
|
204
|
+
// Runtime permission requests: chrome.permissions.request/contains({ permissions: [...] })
|
|
205
|
+
if (node.type === "CallExpression" && node.callee && MEMBER.has(node.callee.type)) {
|
|
206
|
+
const r = resolveChain(node.callee, aliases);
|
|
207
|
+
if (r && !r.dynamic && r.path[0] === "permissions" && r.path.some((p) => PERMISSION_REQUEST_METHODS.has(p))) {
|
|
208
|
+
collectRequestedPerms(node.arguments?.[0], runtimeRequestedPermissions);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
186
211
|
});
|
|
187
212
|
}
|
|
188
|
-
return { apiCalls, sensitiveTabReads, dynamicApiAccess, hostAccessSignals };
|
|
213
|
+
return { apiCalls, sensitiveTabReads, dynamicApiAccess, hostAccessSignals, runtimeRequestedPermissions };
|
|
189
214
|
}
|
|
@@ -44,28 +44,34 @@ function perm001(model) {
|
|
|
44
44
|
const declared = declaredPermissions(manifest);
|
|
45
45
|
const broad = hasBroadHost(manifest);
|
|
46
46
|
const dynamicConfidence = dynamicApiAccess.length > 0 ? "low" : "high";
|
|
47
|
+
// Permissions asked for at runtime via chrome.permissions.request/contains are
|
|
48
|
+
// used by definition — common for optional_permissions gated behind a user
|
|
49
|
+
// gesture, where the namespace call may be dynamic or in a lazily-loaded module.
|
|
50
|
+
const runtimeRequested = new Set(model.runtimeRequestedPermissions);
|
|
47
51
|
const findings = [];
|
|
48
52
|
for (const perm of declared) {
|
|
49
53
|
const mapping = chromePermissionMap[perm];
|
|
50
54
|
if (!mapping)
|
|
51
55
|
continue; // unknown permission → no claim (avoid false positives)
|
|
56
|
+
if (runtimeRequested.has(perm))
|
|
57
|
+
continue; // requested at runtime → used
|
|
52
58
|
if (mapping.namespace) {
|
|
53
59
|
const used = apiCalls.some((c) => c.namespace === mapping.namespace) || isUsedViaManifest(perm, manifest);
|
|
54
60
|
if (!used) {
|
|
55
|
-
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).`));
|
|
56
62
|
}
|
|
57
63
|
}
|
|
58
64
|
else if (mapping.special === "sensitiveTabProperties") {
|
|
59
65
|
// `tabs` is "used" only via sensitive Tab property reads. When broad host
|
|
60
66
|
// is present, redundancy is owned by PERM004 — don't double-flag here.
|
|
61
67
|
if (!broad && model.sensitiveTabReads.length === 0) {
|
|
62
|
-
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.`));
|
|
63
69
|
}
|
|
64
70
|
}
|
|
65
71
|
else if (mapping.special === "temporaryHostAccess") {
|
|
66
72
|
// `activeTab` is plausibly used only behind a user-gesture entry point.
|
|
67
73
|
if (!hasGestureEntryPoint(manifest, declared)) {
|
|
68
|
-
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.`));
|
|
69
75
|
}
|
|
70
76
|
}
|
|
71
77
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tabsmith-lint",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
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": {
|
|
@@ -56,6 +56,6 @@
|
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@types/node": "^20.12.0",
|
|
58
58
|
"typescript": "^5.4.0",
|
|
59
|
-
"vitest": "^
|
|
59
|
+
"vitest": "^3.2.6"
|
|
60
60
|
}
|
|
61
61
|
}
|