@interlace/eslint-devkit 1.6.1 → 1.6.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@interlace/eslint-devkit",
3
- "version": "1.6.1",
3
+ "version": "1.6.2",
4
4
  "description": "Toolkit for building ESLint plugins in TypeScript — AST helpers, type utilities, rule-creation scaffolding, security benchmarks, and SARIF output.",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -3,25 +3,7 @@
3
3
  * Licensed under the MIT License. Use of this source code is governed by the
4
4
  * MIT license that can be found in the LICENSE file.
5
5
  */
6
- /**
7
- * Shared raw-SQL-injection detector (CWE-89).
8
- *
9
- * The AST work — string concatenation or an interpolated template literal
10
- * reaching a raw-SQL sink — is identical for every driver. What differs is
11
- * the sink list and the remediation copy (`$1, $2` for Postgres, `?` for
12
- * mysql2, `replacements` for Sequelize), so those are the parameters.
13
- *
14
- * This exists because the detection first shipped inside `eslint-plugin-pg`,
15
- * where it works fine on `sequelize.query()` — but nobody on Sequelize,
16
- * SQLite or MySQL installs the Postgres plugin, so textbook injections in
17
- * those stacks went unreported. Each driver plugin now instantiates this
18
- * factory, which keeps one implementation and one finding per line.
19
- *
20
- * The rule must stay in a driver-scoped plugin: it keys on driver method
21
- * names, not language primitives, so it does not belong in the code-agnostic
22
- * plugins (`secure-coding`, `node-security`, `browser-security`).
23
- */
24
- import { TSESLint } from '@typescript-eslint/utils';
6
+ import type { TSESLint } from '@typescript-eslint/utils';
25
7
  /** Message ids every rule built by this factory reports. */
26
8
  export type SqlInjectionMessageIds = 'noUnsafeQuery' | 'unsafeTemplateLiteral';
27
9
  export interface SqlInjectionRuleConfig {
@@ -1,27 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createSqlInjectionRule = createSqlInjectionRule;
4
- const utils_1 = require("@typescript-eslint/utils");
4
+ const ast_node_types_1 = require("../ast-node-types");
5
5
  const messaging_1 = require("../messaging");
6
6
  const SQL_KEYWORDS = /\b(?:select|insert|update|delete|drop|alter|truncate|union|from|where|values|set)\b/i;
7
7
  function staticText(node) {
8
- if (node.type === utils_1.AST_NODE_TYPES.TemplateLiteral) {
8
+ if (node.type === ast_node_types_1.AST_NODE_TYPES.TemplateLiteral) {
9
9
  return node.quasis.map((q) => q.value.raw).join(' ');
10
10
  }
11
- if (node.type === utils_1.AST_NODE_TYPES.BinaryExpression) {
11
+ if (node.type === ast_node_types_1.AST_NODE_TYPES.BinaryExpression) {
12
12
  return `${staticText(node.left)} ${staticText(node.right)}`;
13
13
  }
14
- if (node.type === utils_1.AST_NODE_TYPES.Literal && typeof node.value === 'string') {
14
+ if (node.type === ast_node_types_1.AST_NODE_TYPES.Literal && typeof node.value === 'string') {
15
15
  return node.value;
16
16
  }
17
17
  return '';
18
18
  }
19
19
  function classify(node, requireSqlKeywords) {
20
20
  let kind = false;
21
- if (node.type === utils_1.AST_NODE_TYPES.BinaryExpression && node.operator === '+') {
21
+ if (node.type === ast_node_types_1.AST_NODE_TYPES.BinaryExpression && node.operator === '+') {
22
22
  kind = 'concat';
23
23
  }
24
- if (node.type === utils_1.AST_NODE_TYPES.TemplateLiteral && node.expressions.length > 0) {
24
+ if (node.type === ast_node_types_1.AST_NODE_TYPES.TemplateLiteral && node.expressions.length > 0) {
25
25
  kind = 'template';
26
26
  }
27
27
  if (kind === false)
@@ -74,7 +74,7 @@ function createSqlInjectionRule(config) {
74
74
  };
75
75
  return {
76
76
  VariableDeclarator(node) {
77
- if (node.id.type === utils_1.AST_NODE_TYPES.Identifier && node.init) {
77
+ if (node.id.type === ast_node_types_1.AST_NODE_TYPES.Identifier && node.init) {
78
78
  const kind = classify(node.init, config.requireSqlKeywords);
79
79
  if (kind)
80
80
  tainted.set(node.id.name, kind);
@@ -83,7 +83,7 @@ function createSqlInjectionRule(config) {
83
83
  }
84
84
  },
85
85
  AssignmentExpression(node) {
86
- if (node.operator === '+=' && node.left.type === utils_1.AST_NODE_TYPES.Identifier) {
86
+ if (node.operator === '+=' && node.left.type === ast_node_types_1.AST_NODE_TYPES.Identifier) {
87
87
  const gate = config.requireSqlKeywords && !sqlish.has(node.left.name);
88
88
  const kind = classify(node.right, gate);
89
89
  if (kind)
@@ -91,8 +91,8 @@ function createSqlInjectionRule(config) {
91
91
  }
92
92
  },
93
93
  CallExpression(node) {
94
- if (node.callee.type !== utils_1.AST_NODE_TYPES.MemberExpression ||
95
- node.callee.property.type !== utils_1.AST_NODE_TYPES.Identifier ||
94
+ if (node.callee.type !== ast_node_types_1.AST_NODE_TYPES.MemberExpression ||
95
+ node.callee.property.type !== ast_node_types_1.AST_NODE_TYPES.Identifier ||
96
96
  !sinks.has(node.callee.property.name)) {
97
97
  return;
98
98
  }
@@ -104,7 +104,7 @@ function createSqlInjectionRule(config) {
104
104
  report(queryArg, direct);
105
105
  return;
106
106
  }
107
- if (queryArg.type === utils_1.AST_NODE_TYPES.Identifier) {
107
+ if (queryArg.type === ast_node_types_1.AST_NODE_TYPES.Identifier) {
108
108
  const taint = tainted.get(queryArg.name);
109
109
  if (taint)
110
110
  report(queryArg, taint);