@interlace/eslint-devkit 1.5.0 → 1.6.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/package.json +21 -11
- package/src/aria-definitions.js +0 -14
- package/src/ast/ast-utils.js +0 -72
- package/src/ast/index.js +0 -6
- package/src/ast-node-types.d.ts +29 -0
- package/src/ast-node-types.js +174 -0
- package/src/index.d.ts +11 -2
- package/src/index.js +5 -38
- package/src/messaging/config.js +0 -88
- package/src/messaging/constants.js +20 -142
- package/src/messaging/formatters-ai.js +0 -89
- package/src/messaging/formatters-v2.js +0 -151
- package/src/messaging/formatters.js +2 -145
- package/src/messaging/index.js +0 -6
- package/src/messaging/types-v2.js +0 -5
- package/src/messaging/types.js +0 -5
- package/src/node/fs.js +0 -61
- package/src/node/index.js +0 -6
- package/src/node/os.js +0 -33
- package/src/node/path.js +0 -126
- package/src/resolver/dependency-analysis.js +64 -562
- package/src/resolver/index.js +0 -6
- package/src/resolver/resolver-adapter.js +0 -39
- package/src/resolver/resolver-detection.js +0 -48
- package/src/resolver/resolver.d.ts +11 -0
- package/src/resolver/resolver.js +49 -112
- package/src/resolver.js +0 -5
- package/src/rule-creation/index.js +0 -8
- package/src/rule-creation/mock-context.js +0 -9
- package/src/rule-creation/rule-creator.d.ts +59 -10
- package/src/rule-creation/rule-creator.js +64 -40
- package/src/rule-creation/sql-injection-rule.js +0 -52
- package/src/security/index.js +0 -6
- package/src/security/security-utils.js +9 -287
- package/src/types/index.js +0 -9
- package/src/types/meta-augmentation.js +0 -5
- package/src/types/type-utils.d.ts +1 -1
- package/src/types/type-utils.js +34 -145
- package/AGENTS.md +0 -151
- package/CHANGELOG.md +0 -181
|
@@ -6,14 +6,60 @@
|
|
|
6
6
|
/**
|
|
7
7
|
* Rule Creator - Main utility for creating well-typed ESLint rules
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* Ported from typescript-eslint's ESLintUtils.RuleCreator.
|
|
10
10
|
* Provides a factory function for creating rules with proper types and documentation
|
|
11
|
+
*
|
|
12
|
+
* ponytail: this ~40-line port is the whole reason `@typescript-eslint/utils`
|
|
13
|
+
* can be an OPTIONAL peer instead of a hard dependency. `RuleCreator` was the
|
|
14
|
+
* only runtime import we ever made from it, and pulling it in as a dependency
|
|
15
|
+
* dragged its non-optional `typescript` peer — 24 MB of compiler — into every
|
|
16
|
+
* install of every plugin built on this devkit, including plain-JS projects.
|
|
17
|
+
* Types still come from the package (type-only imports cost nothing at
|
|
18
|
+
* runtime); `rule-creator.parity.test.ts` diffs this implementation against
|
|
19
|
+
* the upstream one on every run so the port can't silently drift.
|
|
11
20
|
*/
|
|
12
|
-
import {
|
|
21
|
+
import type { TSESLint } from '@typescript-eslint/utils';
|
|
13
22
|
/**
|
|
14
23
|
* Documentation URL resolver function type
|
|
15
24
|
*/
|
|
16
25
|
type DocsUrl = (ruleName: string) => string;
|
|
26
|
+
/**
|
|
27
|
+
* Pure function - doesn't mutate either parameter!
|
|
28
|
+
* Uses the default options and overrides with the options provided by the user
|
|
29
|
+
*/
|
|
30
|
+
export declare function applyDefault<Options extends readonly unknown[]>(defaultOptions: Options, userOptions: readonly unknown[] | null): Options;
|
|
31
|
+
/**
|
|
32
|
+
* Rule shapes, mirroring `ESLintUtils`'s own. Reconstructed from the
|
|
33
|
+
* `TSESLint` type namespace so they survive `@typescript-eslint/utils` being
|
|
34
|
+
* an optional peer — these are type-only and emit nothing.
|
|
35
|
+
*/
|
|
36
|
+
export type NamedCreateRuleMeta<MessageIds extends string, PluginDocs = unknown, Options extends readonly unknown[] = []> = {
|
|
37
|
+
docs: PluginDocs & TSESLint.RuleMetaDataDocs;
|
|
38
|
+
} & Omit<TSESLint.RuleMetaData<MessageIds, PluginDocs, Options>, 'docs'>;
|
|
39
|
+
export interface RuleCreateAndOptions<Options extends readonly unknown[], MessageIds extends string> {
|
|
40
|
+
create: (context: Readonly<TSESLint.RuleContext<MessageIds, Options>>, optionsWithDefault: Readonly<Options>) => TSESLint.RuleListener;
|
|
41
|
+
defaultOptions?: Readonly<Options>;
|
|
42
|
+
}
|
|
43
|
+
export interface RuleWithMeta<Options extends readonly unknown[], MessageIds extends string, Docs = unknown> extends RuleCreateAndOptions<Options, MessageIds> {
|
|
44
|
+
meta: TSESLint.RuleMetaData<MessageIds, Docs, Options>;
|
|
45
|
+
name?: string;
|
|
46
|
+
}
|
|
47
|
+
export interface RuleWithMetaAndName<Options extends readonly unknown[], MessageIds extends string, Docs = unknown> extends RuleCreateAndOptions<Options, MessageIds> {
|
|
48
|
+
meta: NamedCreateRuleMeta<MessageIds, Docs, Options>;
|
|
49
|
+
name: string;
|
|
50
|
+
}
|
|
51
|
+
export type RuleModuleWithName<MessageIds extends string, Options extends readonly unknown[] = [], Docs = unknown> = TSESLint.RuleModule<MessageIds, Options, Docs> & {
|
|
52
|
+
name: string;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Port of `ESLintUtils.RuleCreator`.
|
|
56
|
+
*
|
|
57
|
+
* Creates a reusable factory for rules with default options and docs URLs.
|
|
58
|
+
*/
|
|
59
|
+
export declare function RuleCreator<PluginDocs = unknown>(urlCreator: DocsUrl): <Options extends readonly unknown[], MessageIds extends string>({ meta, name, ...rule }: Readonly<RuleWithMetaAndName<Options, MessageIds, PluginDocs>>) => RuleModuleWithName<MessageIds, Options, PluginDocs>;
|
|
60
|
+
export declare namespace RuleCreator {
|
|
61
|
+
var withoutDocs: <Options extends readonly unknown[], MessageIds extends string>(args: Readonly<RuleWithMeta<Options, MessageIds>>) => TSESLint.RuleModule<MessageIds, Options>;
|
|
62
|
+
}
|
|
17
63
|
/**
|
|
18
64
|
* Create a rule creator with a custom documentation URL resolver
|
|
19
65
|
*
|
|
@@ -34,18 +80,21 @@ type DocsUrl = (ruleName: string) => string;
|
|
|
34
80
|
* });
|
|
35
81
|
* ```
|
|
36
82
|
*/
|
|
37
|
-
export declare function createRuleCreator(urlCreator: DocsUrl): <Options extends readonly unknown[], MessageIds extends string>({ meta, name, ...rule }: Readonly<
|
|
38
|
-
name: string;
|
|
39
|
-
};
|
|
83
|
+
export declare function createRuleCreator<PluginDocs = unknown>(urlCreator: DocsUrl): <Options extends readonly unknown[], MessageIds extends string>({ meta, name, ...rule }: Readonly<RuleWithMetaAndName<Options, MessageIds, PluginDocs>>) => RuleModuleWithName<MessageIds, Options, PluginDocs>;
|
|
40
84
|
/**
|
|
41
85
|
* Default rule creator with a generic documentation URL pattern
|
|
42
86
|
*
|
|
43
87
|
* This can be used directly if you don't need custom URL generation
|
|
44
88
|
*/
|
|
45
|
-
export declare const createRule: <Options extends readonly unknown[], MessageIds extends string>({ meta, name, ...rule }: Readonly<
|
|
46
|
-
name: string;
|
|
47
|
-
};
|
|
89
|
+
export declare const createRule: <Options extends readonly unknown[], MessageIds extends string>({ meta, name, ...rule }: Readonly<RuleWithMetaAndName<Options, MessageIds, unknown>>) => RuleModuleWithName<MessageIds, Options, unknown>;
|
|
48
90
|
/**
|
|
49
|
-
*
|
|
91
|
+
* Drop-in replacement for the `ESLintUtils` namespace this module used to
|
|
92
|
+
* re-export from `@typescript-eslint/utils`. Only `RuleCreator` was ever used
|
|
93
|
+
* by this ecosystem; anything else should import `@typescript-eslint/utils`
|
|
94
|
+
* directly.
|
|
50
95
|
*/
|
|
51
|
-
export
|
|
96
|
+
export declare const ESLintUtils: {
|
|
97
|
+
RuleCreator: typeof RuleCreator;
|
|
98
|
+
applyDefault: typeof applyDefault;
|
|
99
|
+
};
|
|
100
|
+
export type { TSESLint };
|
|
@@ -1,46 +1,70 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
-
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
-
* MIT license that can be found in the LICENSE file.
|
|
6
|
-
*/
|
|
7
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
3
|
exports.ESLintUtils = exports.createRule = void 0;
|
|
4
|
+
exports.applyDefault = applyDefault;
|
|
5
|
+
exports.RuleCreator = RuleCreator;
|
|
9
6
|
exports.createRuleCreator = createRuleCreator;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
7
|
+
function isObjectNotArray(obj) {
|
|
8
|
+
return typeof obj === 'object' && obj != null && !Array.isArray(obj);
|
|
9
|
+
}
|
|
10
|
+
function deepMerge(first, second) {
|
|
11
|
+
const keys = new Set([...Object.keys(first), ...Object.keys(second)]);
|
|
12
|
+
return Object.fromEntries([...keys].map((key) => {
|
|
13
|
+
const firstHasKey = key in first;
|
|
14
|
+
const secondHasKey = key in second;
|
|
15
|
+
const firstValue = first[key];
|
|
16
|
+
const secondValue = second[key];
|
|
17
|
+
if (firstHasKey && secondHasKey) {
|
|
18
|
+
return [
|
|
19
|
+
key,
|
|
20
|
+
isObjectNotArray(firstValue) && isObjectNotArray(secondValue)
|
|
21
|
+
? deepMerge(firstValue, secondValue)
|
|
22
|
+
: secondValue,
|
|
23
|
+
];
|
|
24
|
+
}
|
|
25
|
+
return [key, firstHasKey ? firstValue : secondValue];
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
function applyDefault(defaultOptions, userOptions) {
|
|
29
|
+
const options = structuredClone(defaultOptions);
|
|
30
|
+
if (userOptions == null) {
|
|
31
|
+
return options;
|
|
32
|
+
}
|
|
33
|
+
options.forEach((opt, i) => {
|
|
34
|
+
if (userOptions[i] !== undefined) {
|
|
35
|
+
const userOpt = userOptions[i];
|
|
36
|
+
options[i] =
|
|
37
|
+
isObjectNotArray(userOpt) && isObjectNotArray(opt)
|
|
38
|
+
? deepMerge(opt, userOpt)
|
|
39
|
+
: userOpt;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
return options;
|
|
43
|
+
}
|
|
44
|
+
function createRuleInternal({ create, defaultOptions, meta, name, }) {
|
|
45
|
+
const resolvedDefaultOptions = (defaultOptions ?? []);
|
|
46
|
+
return {
|
|
47
|
+
create(context) {
|
|
48
|
+
return create(context, applyDefault(resolvedDefaultOptions, context.options));
|
|
49
|
+
},
|
|
50
|
+
defaultOptions: resolvedDefaultOptions,
|
|
51
|
+
meta,
|
|
52
|
+
name: name,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function RuleCreator(urlCreator) {
|
|
56
|
+
return ({ meta, name, ...rule }) => createRuleInternal({
|
|
57
|
+
meta: {
|
|
58
|
+
...meta,
|
|
59
|
+
docs: { ...meta.docs, url: urlCreator(name) },
|
|
60
|
+
},
|
|
61
|
+
name,
|
|
62
|
+
...rule,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
RuleCreator.withoutDocs = (args) => createRuleInternal(args);
|
|
38
66
|
function createRuleCreator(urlCreator) {
|
|
39
|
-
return
|
|
67
|
+
return RuleCreator(urlCreator);
|
|
40
68
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
*
|
|
44
|
-
* This can be used directly if you don't need custom URL generation
|
|
45
|
-
*/
|
|
46
|
-
exports.createRule = utils_1.ESLintUtils.RuleCreator((name) => `https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin/docs/rules/${name}.md`);
|
|
69
|
+
exports.createRule = RuleCreator((name) => `https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin/docs/rules/${name}.md`);
|
|
70
|
+
exports.ESLintUtils = { RuleCreator, applyDefault };
|
|
@@ -1,33 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
-
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
-
* MIT license that can be found in the LICENSE file.
|
|
6
|
-
*/
|
|
7
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
3
|
exports.createSqlInjectionRule = createSqlInjectionRule;
|
|
9
|
-
/**
|
|
10
|
-
* Shared raw-SQL-injection detector (CWE-89).
|
|
11
|
-
*
|
|
12
|
-
* The AST work — string concatenation or an interpolated template literal
|
|
13
|
-
* reaching a raw-SQL sink — is identical for every driver. What differs is
|
|
14
|
-
* the sink list and the remediation copy (`$1, $2` for Postgres, `?` for
|
|
15
|
-
* mysql2, `replacements` for Sequelize), so those are the parameters.
|
|
16
|
-
*
|
|
17
|
-
* This exists because the detection first shipped inside `eslint-plugin-pg`,
|
|
18
|
-
* where it works fine on `sequelize.query()` — but nobody on Sequelize,
|
|
19
|
-
* SQLite or MySQL installs the Postgres plugin, so textbook injections in
|
|
20
|
-
* those stacks went unreported. Each driver plugin now instantiates this
|
|
21
|
-
* factory, which keeps one implementation and one finding per line.
|
|
22
|
-
*
|
|
23
|
-
* The rule must stay in a driver-scoped plugin: it keys on driver method
|
|
24
|
-
* names, not language primitives, so it does not belong in the code-agnostic
|
|
25
|
-
* plugins (`secure-coding`, `node-security`, `browser-security`).
|
|
26
|
-
*/
|
|
27
4
|
const utils_1 = require("@typescript-eslint/utils");
|
|
28
5
|
const messaging_1 = require("../messaging");
|
|
29
6
|
const SQL_KEYWORDS = /\b(?:select|insert|update|delete|drop|alter|truncate|union|from|where|values|set)\b/i;
|
|
30
|
-
/** Literal text of a string expression, ignoring interpolated/concatenated values. */
|
|
31
7
|
function staticText(node) {
|
|
32
8
|
if (node.type === utils_1.AST_NODE_TYPES.TemplateLiteral) {
|
|
33
9
|
return node.quasis.map((q) => q.value.raw).join(' ');
|
|
@@ -40,44 +16,27 @@ function staticText(node) {
|
|
|
40
16
|
}
|
|
41
17
|
return '';
|
|
42
18
|
}
|
|
43
|
-
/** Classify an expression as unsafe SQL construction, or `false` if it is not. */
|
|
44
19
|
function classify(node, requireSqlKeywords) {
|
|
45
20
|
let kind = false;
|
|
46
|
-
// Concatenation: "SELECT ... " + value
|
|
47
21
|
if (node.type === utils_1.AST_NODE_TYPES.BinaryExpression && node.operator === '+') {
|
|
48
22
|
kind = 'concat';
|
|
49
23
|
}
|
|
50
|
-
// Interpolation: `SELECT ... ${value}`
|
|
51
24
|
if (node.type === utils_1.AST_NODE_TYPES.TemplateLiteral && node.expressions.length > 0) {
|
|
52
25
|
kind = 'template';
|
|
53
26
|
}
|
|
54
27
|
if (kind === false)
|
|
55
28
|
return false;
|
|
56
|
-
// `+` is also numeric addition. Without at least one string literal in the
|
|
57
|
-
// expression there is no evidence this builds SQL at all, and an ungated
|
|
58
|
-
// instance would report `db.query(1 + offset)`. Templates are exempt: a
|
|
59
|
-
// template literal is always a string.
|
|
60
29
|
if (kind === 'concat' && staticText(node).trim() === '')
|
|
61
30
|
return false;
|
|
62
31
|
if (requireSqlKeywords && !SQL_KEYWORDS.test(staticText(node)))
|
|
63
32
|
return false;
|
|
64
33
|
return kind;
|
|
65
34
|
}
|
|
66
|
-
/**
|
|
67
|
-
* Build a CWE-89 rule for the given sinks and remediation copy.
|
|
68
|
-
*
|
|
69
|
-
* Detects three shapes: direct concatenation into a sink, direct
|
|
70
|
-
* interpolation into a sink, and a variable tainted by either (including via
|
|
71
|
-
* `+=`) that is later passed to a sink.
|
|
72
|
-
*/
|
|
73
35
|
function createSqlInjectionRule(config) {
|
|
74
36
|
const sinks = new Set(config.methods);
|
|
75
37
|
return {
|
|
76
38
|
meta: {
|
|
77
39
|
type: config.meta.type,
|
|
78
|
-
// CWE / CVSS surface in @interlace/eslint-formatter (devkit augments
|
|
79
|
-
// RuleMetaDataDocs) and are locked against the emitted message by
|
|
80
|
-
// security-cvss-docs-consistency.lock.test.ts.
|
|
81
40
|
docs: { ...config.meta.docs },
|
|
82
41
|
messages: {
|
|
83
42
|
noUnsafeQuery: (0, messaging_1.formatLLMMessage)({
|
|
@@ -85,8 +44,6 @@ function createSqlInjectionRule(config) {
|
|
|
85
44
|
issueName: 'SQL Injection Risk',
|
|
86
45
|
description: 'Unsafe SQL query detected. Variable interpolation found.',
|
|
87
46
|
severity: 'CRITICAL',
|
|
88
|
-
// Same source as meta.docs.cwe, so the emitted CVSS can never drift
|
|
89
|
-
// from the documented one (security-cvss-docs-consistency.lock).
|
|
90
47
|
cwe: config.meta.docs.cwe,
|
|
91
48
|
owasp: 'A03:2021',
|
|
92
49
|
compliance: ['SOC2', 'PCI-DSS', 'NIST-CSF'],
|
|
@@ -108,10 +65,6 @@ function createSqlInjectionRule(config) {
|
|
|
108
65
|
defaultOptions: [],
|
|
109
66
|
create(context) {
|
|
110
67
|
const tainted = new Map();
|
|
111
|
-
// Variables seeded with SQL-looking text. A dynamic-query builder puts
|
|
112
|
-
// the keywords in the seed (`let sql = 'SELECT * FROM t WHERE 1=1'`)
|
|
113
|
-
// and the injection in the appended fragment (`sql += ` AND n =
|
|
114
|
-
// ${n}``), which carries no keyword of its own.
|
|
115
68
|
const sqlish = new Set();
|
|
116
69
|
const report = (node, kind) => {
|
|
117
70
|
context.report({
|
|
@@ -120,8 +73,6 @@ function createSqlInjectionRule(config) {
|
|
|
120
73
|
});
|
|
121
74
|
};
|
|
122
75
|
return {
|
|
123
|
-
// const query = "SELECT ..." + userId;
|
|
124
|
-
// const query = `SELECT ...${email}`;
|
|
125
76
|
VariableDeclarator(node) {
|
|
126
77
|
if (node.id.type === utils_1.AST_NODE_TYPES.Identifier && node.init) {
|
|
127
78
|
const kind = classify(node.init, config.requireSqlKeywords);
|
|
@@ -131,11 +82,8 @@ function createSqlInjectionRule(config) {
|
|
|
131
82
|
sqlish.add(node.id.name);
|
|
132
83
|
}
|
|
133
84
|
},
|
|
134
|
-
// query += ` AND name = '${name}'`;
|
|
135
85
|
AssignmentExpression(node) {
|
|
136
86
|
if (node.operator === '+=' && node.left.type === utils_1.AST_NODE_TYPES.Identifier) {
|
|
137
|
-
// Skip the keyword gate when the target was already seeded with
|
|
138
|
-
// SQL — the fragment alone rarely contains a keyword.
|
|
139
87
|
const gate = config.requireSqlKeywords && !sqlish.has(node.left.name);
|
|
140
88
|
const kind = classify(node.right, gate);
|
|
141
89
|
if (kind)
|
package/src/security/index.js
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
-
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
-
* MIT license that can be found in the LICENSE file.
|
|
6
|
-
*/
|
|
7
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
3
|
const tslib_1 = require("tslib");
|
|
9
|
-
// Security utilities for reducing false positives in security rules
|
|
10
4
|
tslib_1.__exportStar(require("./security-utils"), exports);
|