eslint-plugin-prisma-security 0.2.1 → 0.3.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 CHANGED
@@ -117,6 +117,8 @@ See the [ESLint Version Support Policy](../../docs/ESLINT_VERSION_SUPPORT.md)
117
117
  <!-- AUTO-GENERATED:RULES_TABLE:START - Do not edit manually -->
118
118
  | Rule | CWE | OWASP | CVSS | Description | 🧠 | 💼 | ⚠️ | 🔧 | 💡 | 🚫 |
119
119
  | :--- | :---: | :---: | :---: | :--- | :---: | :---: | :---: | :---: | :---: | :---: |
120
+ | [no-mass-assignment](https://eslint.interlace.tools/docs/security/plugin-prisma-security/rules/no-mass-assignment?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-prisma-security) | CWE-915 | A04:2021 | | Disallow writing an inbound request object straight to the database through Prisma, which lets the caller s… | 🟢 | | | | | |
121
+ | [no-raw-identifier-interpolation](https://eslint.interlace.tools/docs/security/plugin-prisma-security/rules/no-raw-identifier-interpolation?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-prisma-security) | CWE-89 | A03:2021 | | Disallow interpolating table, column or sort identifiers into a Prisma $queryRaw / $executeRaw template, wh… | 🟢 | | | | | |
120
122
  | [no-unsafe-query](https://eslint.interlace.tools/docs/security/plugin-prisma-security/rules/no-unsafe-query?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-prisma-security) | CWE-89 | A03:2021 | | Prevent SQL injection by disallowing string concatenation or interpolated template literals in Prisma raw q… | 🟢 | 💼 | | | | |
121
123
  | [no-unscoped-mutation](https://eslint.interlace.tools/docs/security/plugin-prisma-security/rules/no-unscoped-mutation?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-prisma-security) | CWE-284 | A01:2021 | | Require a `where` filter on Prisma bulk mutations, so deleteMany and updateMany cannot rewrite or delete ev… | 🟢 | | | | | |
122
124
  <!-- AUTO-GENERATED:RULES_TABLE:END -->
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-prisma-security",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "ESLint plugin for @prisma/client — detects SQL injection in raw queries built with string concatenation or template literals.",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -76,8 +76,7 @@
76
76
  }
77
77
  },
78
78
  "dependencies": {
79
- "tslib": "^2.3.0",
80
- "@interlace/eslint-devkit": "^1.7.0"
79
+ "@interlace/eslint-devkit": "^1.9.0"
81
80
  },
82
81
  "funding": {
83
82
  "type": "github",
package/src/index.js CHANGED
@@ -1,16 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.configs = exports.plugin = exports.rules = void 0;
4
- const no_unsafe_query_1 = require("./rules/no-unsafe-query");
5
- const no_unscoped_mutation_1 = require("./rules/no-unscoped-mutation");
6
4
  exports.rules = {
7
- 'no-unsafe-query': no_unsafe_query_1.noUnsafeQuery,
8
- 'no-unscoped-mutation': no_unscoped_mutation_1.noUnscopedMutation,
5
+ get 'no-mass-assignment'() { return require("./rules/no-mass-assignment").noMassAssignment; },
6
+ get 'no-raw-identifier-interpolation'() { return require("./rules/no-raw-identifier-interpolation").noRawIdentifierInterpolation; },
7
+ get 'no-unsafe-query'() { return require("./rules/no-unsafe-query").noUnsafeQuery; },
8
+ get 'no-unscoped-mutation'() { return require("./rules/no-unscoped-mutation").noUnscopedMutation; },
9
+
9
10
  };
10
11
  exports.plugin = {
11
12
  meta: {
12
13
  name: 'eslint-plugin-prisma-security',
13
- version: '0.2.1',
14
+ version: '0.3.0',
14
15
  },
15
16
  rules: exports.rules,
16
17
  };
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.noMassAssignment = void 0;
4
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
+ exports.noMassAssignment = (0, eslint_devkit_1.createMassAssignmentRule)({
6
+ meta: {
7
+ type: 'problem',
8
+ docs: {
9
+ description: 'Disallow writing an inbound request object straight to the database through Prisma, which lets the caller set every column the model exposes.',
10
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-prisma-security/docs/rules/no-mass-assignment.md',
11
+ cwe: 'CWE-915',
12
+ cvss: 8.1,
13
+ confidence: 'high',
14
+ },
15
+ },
16
+ methods: ['create', 'update', 'upsert', 'createMany', 'updateMany'],
17
+ payloadKeys: ['data', 'create', 'update'],
18
+ receiverPattern: /^(prisma|db|database|client|tx|trx)$|[Pp]risma$|[Cc]lient$/,
19
+ modules: ['@prisma/client'],
20
+ fix: 'Name the columns you accept — `data: { name: req.body.name }` — or validate into a typed object first (`const input = UserUpdate.parse(req.body)`). Prisma will happily write any column in the model.',
21
+ documentationLink: 'https://www.prisma.io/docs/orm/prisma-client/queries/crud',
22
+ });
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.noRawIdentifierInterpolation = void 0;
4
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
+ exports.noRawIdentifierInterpolation = (0, eslint_devkit_1.createRawIdentifierRule)({
6
+ meta: {
7
+ type: 'problem',
8
+ docs: {
9
+ description: 'Disallow interpolating table, column or sort identifiers into a Prisma $queryRaw / $executeRaw template, where bind parameters cannot reach them.',
10
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-prisma-security/docs/rules/no-raw-identifier-interpolation.md',
11
+ cwe: 'CWE-89',
12
+ cvss: 9.8,
13
+ confidence: 'high',
14
+ },
15
+ },
16
+ tags: ['$queryRaw', '$executeRaw'],
17
+ modules: ['@prisma/client'],
18
+ requireImport: false,
19
+ identifierHelpers: [],
20
+ fix: 'Map the input through a fixed allowlist before it reaches the query — `const column = ALLOWED[input] ?? "id"`. Prisma has no identifier escaper, so an allowlist is the only safe construction.',
21
+ sortDirectionFix: 'Resolve the direction to a literal: `const dir = input === "desc" ? "desc" : "asc"`, or move the sort into the type-safe `orderBy` argument.',
22
+ documentationLink: 'https://www.prisma.io/docs/orm/prisma-client/using-raw-sql/raw-queries#considerations',
23
+ });
@@ -3,6 +3,20 @@
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
+ * Options for `no-mass-assignment`.
8
+ *
9
+ * The rule takes none. An allowlist option would let a project re-approve the
10
+ * dangerous shape wholesale, one config file further from the call site.
11
+ */
12
+ export type NoMassAssignmentOptions = [];
13
+ /**
14
+ * Options for `no-raw-identifier-interpolation`.
15
+ *
16
+ * The rule takes none. Which SQL positions can accept a bind parameter is
17
+ * fixed by the database's grammar, not by project preference.
18
+ */
19
+ export type NoRawIdentifierInterpolationOptions = [];
6
20
  export type NoUnsafeQueryOptions = [];
7
21
  /**
8
22
  * Options for `no-unscoped-mutation`.
@@ -12,6 +26,8 @@ export type NoUnsafeQueryOptions = [];
12
26
  */
13
27
  export type NoUnscopedMutationOptions = [];
14
28
  export interface AllPrismaRulesOptions {
29
+ 'prisma-security/no-mass-assignment': NoMassAssignmentOptions;
30
+ 'prisma-security/no-raw-identifier-interpolation': NoRawIdentifierInterpolationOptions;
15
31
  'prisma-security/no-unsafe-query': NoUnsafeQueryOptions;
16
32
  'prisma-security/no-unscoped-mutation': NoUnscopedMutationOptions;
17
33
  }