eslint-plugin-drizzle-security 0.1.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/CHANGELOG.md +24 -0
- package/LICENSE +23 -0
- package/README.md +155 -0
- package/dist/CHANGELOG.md +24 -0
- package/dist/LICENSE +23 -0
- package/dist/README.md +155 -0
- package/dist/package.json +98 -0
- package/dist/src/index.d.ts +30 -0
- package/dist/src/index.js +60 -0
- package/dist/src/oxlint.d.ts +20 -0
- package/dist/src/oxlint.js +21 -0
- package/dist/src/rules/no-unsafe-query/index.d.ts +6 -0
- package/dist/src/rules/no-unsafe-query/index.js +32 -0
- package/dist/src/types/index.d.ts +9 -0
- package/dist/src/types/index.js +7 -0
- package/package.json +98 -0
- package/src/index.test.ts +50 -0
- package/src/index.ts +78 -0
- package/src/oxlint.spec.ts +67 -0
- package/src/oxlint.ts +23 -0
- package/src/rules/no-unsafe-query/index.ts +33 -0
- package/src/rules/no-unsafe-query/no-unsafe-query.test.ts +76 -0
- package/src/types/index.ts +11 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# eslint-plugin-drizzle-security
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
Six new driver-scoped SQL-injection plugins (CWE-89), each shipping one rule —
|
|
8
|
+
`no-unsafe-query` at `error` in `recommended`:
|
|
9
|
+
|
|
10
|
+
- **`eslint-plugin-mysql-security`** — mysql2 / mysql. Sinks: `.query()`, `.execute()` (gated on SQL keywords in the static text, since these are common method names outside MySQL). Remediation names MySQL's own safe API.
|
|
11
|
+
- **`eslint-plugin-prisma-security`** — @prisma/client. Sinks: `.$queryRawUnsafe()`, `.$executeRawUnsafe()`. Remediation names Prisma's own safe API.
|
|
12
|
+
- **`eslint-plugin-drizzle-security`** — drizzle-orm. Sinks: `.raw()`. Remediation names Drizzle's own safe API.
|
|
13
|
+
- **`eslint-plugin-knex-security`** — knex. Sinks: `.raw()`. Remediation names Knex's own safe API.
|
|
14
|
+
- **`eslint-plugin-sqlite-security`** — better-sqlite3 / sqlite3. Sinks: `.prepare()`, `.exec()`, `.run()`, `.all()`, `.get()` (gated on SQL keywords in the static text, since these are common method names outside SQLite). Remediation names SQLite's own safe API.
|
|
15
|
+
- **`eslint-plugin-typeorm-security`** — typeorm. Sinks: `.query()`. Remediation names TypeORM's own safe API.
|
|
16
|
+
|
|
17
|
+
All six instantiate the shared `createSqlInjectionRule` from
|
|
18
|
+
`@interlace/eslint-devkit`, so detection is one implementation and each
|
|
19
|
+
plugin differs only in sinks, precision gate and remediation copy. Install the
|
|
20
|
+
one matching your stack and you get exactly one finding per line.
|
|
21
|
+
|
|
22
|
+
None are added to `eslint-config-interlace`'s aggregated presets: sink names
|
|
23
|
+
overlap across drivers (`.query()`, `.raw()`), so bundling them would report the
|
|
24
|
+
same line more than once.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-drizzle-security" target="blank"><img src="https://eslint.interlace.tools/icon-light.svg" alt="Interlace" height="90" /></a>
|
|
3
|
+
|
|
4
|
+
<a href="https://eslint.org" target="_blank"><img src="https://eslint.interlace.tools/eslint-logo.svg" alt="ESLint" height="90" /></a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
Security rules for drizzle-orm (SQL injection prevention in raw queries).
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://www.npmjs.com/package/eslint-plugin-drizzle-security" target="_blank"><img src="https://img.shields.io/npm/v/eslint-plugin-drizzle-security.svg" alt="NPM Version" /></a>
|
|
13
|
+
<a href="https://www.npmjs.com/package/eslint-plugin-drizzle-security" target="_blank"><img src="https://img.shields.io/npm/dm/eslint-plugin-drizzle-security.svg" alt="NPM Downloads" /></a>
|
|
14
|
+
<a href="https://opensource.org/licenses/MIT" target="_blank"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="Package License" /></a>
|
|
15
|
+
<a href="https://app.codecov.io/gh/ofri-peretz/eslint/components?components%5B0%5D=eslint-plugin-drizzle-security" target="_blank"><img src="https://codecov.io/gh/ofri-peretz/eslint/graph/badge.svg?component=eslint-plugin-drizzle-security" alt="Codecov" /></a>
|
|
16
|
+
<a href="https://github.com/ofri-peretz/eslint" target="_blank"><img src="https://img.shields.io/badge/Since-Dec_2025-blue?logo=rocket&logoColor=white" alt="Since Dec 2025" /></a>
|
|
17
|
+
</p>
|
|
18
|
+
|
|
19
|
+
> ⭐ If this plugin caught a real bug for you, [**star the repo**](https://github.com/ofri-peretz/eslint) — it's the signal that keeps these rules maintained.
|
|
20
|
+
|
|
21
|
+
## Description
|
|
22
|
+
|
|
23
|
+
This plugin provides Security rules for drizzle-orm (SQL injection prevention in raw queries).
|
|
24
|
+
|
|
25
|
+
## Why Drizzle-specific?
|
|
26
|
+
|
|
27
|
+
Being Drizzle-specific is what makes the rule precise. It knows which calls are raw-SQL sinks (`.raw()`) and which idioms are already safe, so it reports the patterns that actually lead to injection and stays quiet on parameterized queries. It also tracks variable taint across statements, so a query built on one line and executed on another is still reported.
|
|
28
|
+
|
|
29
|
+
The detection itself is shared with the other Interlace driver plugins through `createSqlInjectionRule` — install the one matching your stack and you get exactly one finding per line.
|
|
30
|
+
|
|
31
|
+
## Philosophy
|
|
32
|
+
|
|
33
|
+
**Interlace** fosters **strength through integration**. Instead of stacking isolated rules, we **interlace** security directly into your workflow to create a resilient fabric of code. We believe tools should **guide rather than gatekeep**, providing educational feedback that strengthens the developer with every interaction.
|
|
34
|
+
|
|
35
|
+
## Getting Started
|
|
36
|
+
|
|
37
|
+
- To check out the [guide](https://eslint.interlace.tools/docs/security/plugin-drizzle-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-drizzle-security), visit [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-drizzle-security). 📚
|
|
38
|
+
- 要查看中文 [指南](https://eslint.interlace.tools/docs/security/plugin-drizzle-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-drizzle-security), 请访问 [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-drizzle-security). 📚
|
|
39
|
+
- [가이드](https://eslint.interlace.tools/docs/security/plugin-drizzle-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-drizzle-security) 문서는 [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-drizzle-security)에서 확인하실 수 있습니다. 📚
|
|
40
|
+
- [ガイド](https://eslint.interlace.tools/docs/security/plugin-drizzle-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-drizzle-security)は [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-drizzle-security)でご確認ください。 📚
|
|
41
|
+
- Para ver la [guía](https://eslint.interlace.tools/docs/security/plugin-drizzle-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-drizzle-security), visita [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-drizzle-security). 📚
|
|
42
|
+
- للاطلاع على [الدليل](https://eslint.interlace.tools/docs/security/plugin-drizzle-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-drizzle-security)، قم بزيارة [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-drizzle-security). 📚
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npm install eslint-plugin-drizzle-security --save-dev
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## ⚙️ Configuration Presets
|
|
49
|
+
| Preset | Description |
|
|
50
|
+
| :------------ | :------------------------------------------------------- |
|
|
51
|
+
| `recommended` | Recommended preset - balanced security for most projects |
|
|
52
|
+
| `strict` | Strict preset - all rules as errors |
|
|
53
|
+
| `flagship` | Highest-signal rules only, for CI gates |
|
|
54
|
+
|
|
55
|
+
## 📚 Supported Libraries
|
|
56
|
+
| Library | npm | Downloads | Detection |
|
|
57
|
+
| ------- | --- | --------- | --------- |
|
|
58
|
+
| `drizzle-orm` | [](https://www.npmjs.com/package/drizzle-orm) | [](https://www.npmjs.com/package/drizzle-orm) | SQL Injection |
|
|
59
|
+
|
|
60
|
+
### Custom Configuration
|
|
61
|
+
|
|
62
|
+
```javascript
|
|
63
|
+
import drizzle from 'eslint-plugin-drizzle-security';
|
|
64
|
+
|
|
65
|
+
export default [
|
|
66
|
+
{
|
|
67
|
+
plugins: { 'sequelize-security': sequelizeSecurity },
|
|
68
|
+
rules: {
|
|
69
|
+
'drizzle-security/no-unsafe-query': 'error',
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
];
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## 💡 What You Get
|
|
76
|
+
- **Covers the escapes your ORM leaves open:** `.raw()`
|
|
77
|
+
- **Drizzle's own remediation:** every finding names Drizzle's own safe API, not a generic "use parameterized queries"
|
|
78
|
+
- **Cross-statement taint tracking:** catches queries assembled over several lines, including with `+=`
|
|
79
|
+
- **Quiet on safe code:** parameterized queries, static SQL and builder calls do not report
|
|
80
|
+
- **LLM-optimized messages:** structured 2-line errors with CWE + fixes that AI assistants can apply
|
|
81
|
+
|
|
82
|
+
Every rule produces a **structured error message**:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
src/db.ts
|
|
86
|
+
42:15 error 🔒 CWE-89 OWASP:A03-Injection CVSS:9.8 | Unsafe SQL query construction detected (template literal) | CRITICAL
|
|
87
|
+
Fix: Use the `sql` tagged template, which parameterizes interpolated values, instead of `sql.raw()`.
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## 📦 Compatibility
|
|
91
|
+
| Package | Version |
|
|
92
|
+
| :--- | :--- |
|
|
93
|
+
| ESLint | `^8.0.0 \|\| ^9.0.0 \|\| ^10.0.0` |
|
|
94
|
+
| Node.js | `>=18.0.0` |
|
|
95
|
+
|
|
96
|
+
See the [ESLint Version Support Policy](../../docs/ESLINT_VERSION_SUPPORT.md) — current ecosystem share data, the 20% gate, and the forward-looking exception that covers v10.
|
|
97
|
+
|
|
98
|
+
## Rules
|
|
99
|
+
|
|
100
|
+
**Legend**
|
|
101
|
+
|
|
102
|
+
| Icon | Description |
|
|
103
|
+
| :---: | :--- |
|
|
104
|
+
| 💼 | **Recommended**: Included in the recommended preset. |
|
|
105
|
+
| ⚠️ | **Warns**: Set to warn in recommended preset. |
|
|
106
|
+
| 🔧 | **Auto-fixable**: Automatically fixable by the `--fix` CLI option. |
|
|
107
|
+
| 💡 | **Suggestions**: Providing code suggestions in IDE. |
|
|
108
|
+
| 🚫 | **Deprecated**: This rule is deprecated. |
|
|
109
|
+
| 🟢 | **Type-unaware**: AST-only, runs in oxlint JS-plugin tier. |
|
|
110
|
+
| 🟡 | **Type-aware (refining)**: pure-AST primary path; types refine precision. |
|
|
111
|
+
| 🟠 | **Type-aware (graceful)**: requires TS program; silent without it. |
|
|
112
|
+
|
|
113
|
+
<!-- AUTO-GENERATED:RULES_TABLE:START - Do not edit manually -->
|
|
114
|
+
| Rule | CWE | OWASP | CVSS | Description | 🧠 | 💼 | ⚠️ | 🔧 | 💡 | 🚫 |
|
|
115
|
+
| :--- | :---: | :---: | :---: | :--- | :---: | :---: | :---: | :---: | :---: | :---: |
|
|
116
|
+
| [no-unsafe-query](https://eslint.interlace.tools/docs/security/plugin-drizzle-security/rules/no-unsafe-query?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-drizzle-security) | CWE-89 | A03:2021 | | Prevent SQL injection by disallowing string concatenation or interpolated template literals in Drizzle sql.… | 🟢 | 💼 | | | | |
|
|
117
|
+
<!-- AUTO-GENERATED:RULES_TABLE:END -->
|
|
118
|
+
## 🔗 Related ESLint Plugins
|
|
119
|
+
|
|
120
|
+
Part of the **Interlace ESLint Ecosystem** — AI-native security plugins with LLM-optimized error messages:
|
|
121
|
+
|
|
122
|
+
| Plugin | Downloads | Description |
|
|
123
|
+
| :--- | :---: | :--- |
|
|
124
|
+
| [`eslint-plugin-secure-coding`](https://www.npmjs.com/package/eslint-plugin-secure-coding) | [](https://www.npmjs.com/package/eslint-plugin-secure-coding) | General security rules & OWASP guidelines. |
|
|
125
|
+
| [`eslint-plugin-pg`](https://www.npmjs.com/package/eslint-plugin-pg) | [](https://www.npmjs.com/package/eslint-plugin-pg) | PostgreSQL security & best practices. |
|
|
126
|
+
| [`eslint-plugin-node-security`](https://www.npmjs.com/package/eslint-plugin-node-security) | [](https://www.npmjs.com/package/eslint-plugin-node-security) | Node.js core-module security (fs, child_process, vm, crypto, Buffer). |
|
|
127
|
+
| [`eslint-plugin-jwt`](https://www.npmjs.com/package/eslint-plugin-jwt) | [](https://www.npmjs.com/package/eslint-plugin-jwt) | JWT security & best practices. |
|
|
128
|
+
| [`eslint-plugin-browser-security`](https://www.npmjs.com/package/eslint-plugin-browser-security) | [](https://www.npmjs.com/package/eslint-plugin-browser-security) | Browser-specific security & XSS prevention. |
|
|
129
|
+
| [`eslint-plugin-express-security`](https://www.npmjs.com/package/eslint-plugin-express-security) | [](https://www.npmjs.com/package/eslint-plugin-express-security) | Express.js security hardening rules. |
|
|
130
|
+
| [`eslint-plugin-lambda-security`](https://www.npmjs.com/package/eslint-plugin-lambda-security) | [](https://www.npmjs.com/package/eslint-plugin-lambda-security) | AWS Lambda security best practices. |
|
|
131
|
+
| [`eslint-plugin-nestjs-security`](https://www.npmjs.com/package/eslint-plugin-nestjs-security) | [](https://www.npmjs.com/package/eslint-plugin-nestjs-security) | NestJS security rules & patterns. |
|
|
132
|
+
| [`eslint-plugin-mongodb-security`](https://www.npmjs.com/package/eslint-plugin-mongodb-security) | [](https://www.npmjs.com/package/eslint-plugin-mongodb-security) | MongoDB security best practices. |
|
|
133
|
+
| [`eslint-plugin-vercel-ai-security`](https://www.npmjs.com/package/eslint-plugin-vercel-ai-security) | [](https://www.npmjs.com/package/eslint-plugin-vercel-ai-security) | Vercel AI SDK security hardening. |
|
|
134
|
+
| [`eslint-plugin-import-next`](https://www.npmjs.com/package/eslint-plugin-import-next) | [](https://www.npmjs.com/package/eslint-plugin-import-next) | Next-gen import sorting & architecture. |
|
|
135
|
+
|
|
136
|
+
<!-- INTERLACE:STAR_CTA:START -->
|
|
137
|
+
## ⭐ Support & follow
|
|
138
|
+
|
|
139
|
+
If this plugin caught a real bug for you, **[star the repo](https://github.com/ofri-peretz/eslint)** — stars are the signal that keeps the Interlace ESLint ecosystem maintained — and **[follow the writeups on Dev.to](https://dev.to/ofri-peretz)** for the benchmarks and security research behind these rules.
|
|
140
|
+
|
|
141
|
+
[](https://github.com/ofri-peretz/eslint)
|
|
142
|
+
|
|
143
|
+
<!-- INTERLACE:STAR_CTA:END -->
|
|
144
|
+
|
|
145
|
+
## 📄 License
|
|
146
|
+
|
|
147
|
+
MIT © [Ofri Peretz](https://github.com/ofri-peretz)
|
|
148
|
+
|
|
149
|
+
<p align="center">
|
|
150
|
+
<a href="https://eslint.interlace.tools/docs/security/plugin-drizzle-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-drizzle-security"><img src="https://eslint.interlace.tools/images/og-drizzle-security.png" alt="ESLint Interlace Plugin" width="100%" /></a>
|
|
151
|
+
</p>
|
|
152
|
+
|
|
153
|
+
<p align="center">
|
|
154
|
+
<a href="https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-drizzle-security" target="blank"><img src="https://eslint.interlace.tools/icon-light.svg" alt="Interlace" height="70" /></a>
|
|
155
|
+
</p>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# eslint-plugin-drizzle-security
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
Six new driver-scoped SQL-injection plugins (CWE-89), each shipping one rule —
|
|
8
|
+
`no-unsafe-query` at `error` in `recommended`:
|
|
9
|
+
|
|
10
|
+
- **`eslint-plugin-mysql-security`** — mysql2 / mysql. Sinks: `.query()`, `.execute()` (gated on SQL keywords in the static text, since these are common method names outside MySQL). Remediation names MySQL's own safe API.
|
|
11
|
+
- **`eslint-plugin-prisma-security`** — @prisma/client. Sinks: `.$queryRawUnsafe()`, `.$executeRawUnsafe()`. Remediation names Prisma's own safe API.
|
|
12
|
+
- **`eslint-plugin-drizzle-security`** — drizzle-orm. Sinks: `.raw()`. Remediation names Drizzle's own safe API.
|
|
13
|
+
- **`eslint-plugin-knex-security`** — knex. Sinks: `.raw()`. Remediation names Knex's own safe API.
|
|
14
|
+
- **`eslint-plugin-sqlite-security`** — better-sqlite3 / sqlite3. Sinks: `.prepare()`, `.exec()`, `.run()`, `.all()`, `.get()` (gated on SQL keywords in the static text, since these are common method names outside SQLite). Remediation names SQLite's own safe API.
|
|
15
|
+
- **`eslint-plugin-typeorm-security`** — typeorm. Sinks: `.query()`. Remediation names TypeORM's own safe API.
|
|
16
|
+
|
|
17
|
+
All six instantiate the shared `createSqlInjectionRule` from
|
|
18
|
+
`@interlace/eslint-devkit`, so detection is one implementation and each
|
|
19
|
+
plugin differs only in sinks, precision gate and remediation copy. Install the
|
|
20
|
+
one matching your stack and you get exactly one finding per line.
|
|
21
|
+
|
|
22
|
+
None are added to `eslint-config-interlace`'s aggregated presets: sink names
|
|
23
|
+
overlap across drivers (`.query()`, `.raw()`), so bundling them would report the
|
|
24
|
+
same line more than once.
|
package/dist/LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
|
package/dist/README.md
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-drizzle-security" target="blank"><img src="https://eslint.interlace.tools/icon-light.svg" alt="Interlace" height="90" /></a>
|
|
3
|
+
|
|
4
|
+
<a href="https://eslint.org" target="_blank"><img src="https://eslint.interlace.tools/eslint-logo.svg" alt="ESLint" height="90" /></a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
Security rules for drizzle-orm (SQL injection prevention in raw queries).
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://www.npmjs.com/package/eslint-plugin-drizzle-security" target="_blank"><img src="https://img.shields.io/npm/v/eslint-plugin-drizzle-security.svg" alt="NPM Version" /></a>
|
|
13
|
+
<a href="https://www.npmjs.com/package/eslint-plugin-drizzle-security" target="_blank"><img src="https://img.shields.io/npm/dm/eslint-plugin-drizzle-security.svg" alt="NPM Downloads" /></a>
|
|
14
|
+
<a href="https://opensource.org/licenses/MIT" target="_blank"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="Package License" /></a>
|
|
15
|
+
<a href="https://app.codecov.io/gh/ofri-peretz/eslint/components?components%5B0%5D=eslint-plugin-drizzle-security" target="_blank"><img src="https://codecov.io/gh/ofri-peretz/eslint/graph/badge.svg?component=eslint-plugin-drizzle-security" alt="Codecov" /></a>
|
|
16
|
+
<a href="https://github.com/ofri-peretz/eslint" target="_blank"><img src="https://img.shields.io/badge/Since-Dec_2025-blue?logo=rocket&logoColor=white" alt="Since Dec 2025" /></a>
|
|
17
|
+
</p>
|
|
18
|
+
|
|
19
|
+
> ⭐ If this plugin caught a real bug for you, [**star the repo**](https://github.com/ofri-peretz/eslint) — it's the signal that keeps these rules maintained.
|
|
20
|
+
|
|
21
|
+
## Description
|
|
22
|
+
|
|
23
|
+
This plugin provides Security rules for drizzle-orm (SQL injection prevention in raw queries).
|
|
24
|
+
|
|
25
|
+
## Why Drizzle-specific?
|
|
26
|
+
|
|
27
|
+
Being Drizzle-specific is what makes the rule precise. It knows which calls are raw-SQL sinks (`.raw()`) and which idioms are already safe, so it reports the patterns that actually lead to injection and stays quiet on parameterized queries. It also tracks variable taint across statements, so a query built on one line and executed on another is still reported.
|
|
28
|
+
|
|
29
|
+
The detection itself is shared with the other Interlace driver plugins through `createSqlInjectionRule` — install the one matching your stack and you get exactly one finding per line.
|
|
30
|
+
|
|
31
|
+
## Philosophy
|
|
32
|
+
|
|
33
|
+
**Interlace** fosters **strength through integration**. Instead of stacking isolated rules, we **interlace** security directly into your workflow to create a resilient fabric of code. We believe tools should **guide rather than gatekeep**, providing educational feedback that strengthens the developer with every interaction.
|
|
34
|
+
|
|
35
|
+
## Getting Started
|
|
36
|
+
|
|
37
|
+
- To check out the [guide](https://eslint.interlace.tools/docs/security/plugin-drizzle-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-drizzle-security), visit [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-drizzle-security). 📚
|
|
38
|
+
- 要查看中文 [指南](https://eslint.interlace.tools/docs/security/plugin-drizzle-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-drizzle-security), 请访问 [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-drizzle-security). 📚
|
|
39
|
+
- [가이드](https://eslint.interlace.tools/docs/security/plugin-drizzle-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-drizzle-security) 문서는 [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-drizzle-security)에서 확인하실 수 있습니다. 📚
|
|
40
|
+
- [ガイド](https://eslint.interlace.tools/docs/security/plugin-drizzle-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-drizzle-security)は [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-drizzle-security)でご確認ください。 📚
|
|
41
|
+
- Para ver la [guía](https://eslint.interlace.tools/docs/security/plugin-drizzle-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-drizzle-security), visita [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-drizzle-security). 📚
|
|
42
|
+
- للاطلاع على [الدليل](https://eslint.interlace.tools/docs/security/plugin-drizzle-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-drizzle-security)، قم بزيارة [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-drizzle-security). 📚
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npm install eslint-plugin-drizzle-security --save-dev
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## ⚙️ Configuration Presets
|
|
49
|
+
| Preset | Description |
|
|
50
|
+
| :------------ | :------------------------------------------------------- |
|
|
51
|
+
| `recommended` | Recommended preset - balanced security for most projects |
|
|
52
|
+
| `strict` | Strict preset - all rules as errors |
|
|
53
|
+
| `flagship` | Highest-signal rules only, for CI gates |
|
|
54
|
+
|
|
55
|
+
## 📚 Supported Libraries
|
|
56
|
+
| Library | npm | Downloads | Detection |
|
|
57
|
+
| ------- | --- | --------- | --------- |
|
|
58
|
+
| `drizzle-orm` | [](https://www.npmjs.com/package/drizzle-orm) | [](https://www.npmjs.com/package/drizzle-orm) | SQL Injection |
|
|
59
|
+
|
|
60
|
+
### Custom Configuration
|
|
61
|
+
|
|
62
|
+
```javascript
|
|
63
|
+
import drizzle from 'eslint-plugin-drizzle-security';
|
|
64
|
+
|
|
65
|
+
export default [
|
|
66
|
+
{
|
|
67
|
+
plugins: { 'sequelize-security': sequelizeSecurity },
|
|
68
|
+
rules: {
|
|
69
|
+
'drizzle-security/no-unsafe-query': 'error',
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
];
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## 💡 What You Get
|
|
76
|
+
- **Covers the escapes your ORM leaves open:** `.raw()`
|
|
77
|
+
- **Drizzle's own remediation:** every finding names Drizzle's own safe API, not a generic "use parameterized queries"
|
|
78
|
+
- **Cross-statement taint tracking:** catches queries assembled over several lines, including with `+=`
|
|
79
|
+
- **Quiet on safe code:** parameterized queries, static SQL and builder calls do not report
|
|
80
|
+
- **LLM-optimized messages:** structured 2-line errors with CWE + fixes that AI assistants can apply
|
|
81
|
+
|
|
82
|
+
Every rule produces a **structured error message**:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
src/db.ts
|
|
86
|
+
42:15 error 🔒 CWE-89 OWASP:A03-Injection CVSS:9.8 | Unsafe SQL query construction detected (template literal) | CRITICAL
|
|
87
|
+
Fix: Use the `sql` tagged template, which parameterizes interpolated values, instead of `sql.raw()`.
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## 📦 Compatibility
|
|
91
|
+
| Package | Version |
|
|
92
|
+
| :--- | :--- |
|
|
93
|
+
| ESLint | `^8.0.0 \|\| ^9.0.0 \|\| ^10.0.0` |
|
|
94
|
+
| Node.js | `>=18.0.0` |
|
|
95
|
+
|
|
96
|
+
See the [ESLint Version Support Policy](../../docs/ESLINT_VERSION_SUPPORT.md) — current ecosystem share data, the 20% gate, and the forward-looking exception that covers v10.
|
|
97
|
+
|
|
98
|
+
## Rules
|
|
99
|
+
|
|
100
|
+
**Legend**
|
|
101
|
+
|
|
102
|
+
| Icon | Description |
|
|
103
|
+
| :---: | :--- |
|
|
104
|
+
| 💼 | **Recommended**: Included in the recommended preset. |
|
|
105
|
+
| ⚠️ | **Warns**: Set to warn in recommended preset. |
|
|
106
|
+
| 🔧 | **Auto-fixable**: Automatically fixable by the `--fix` CLI option. |
|
|
107
|
+
| 💡 | **Suggestions**: Providing code suggestions in IDE. |
|
|
108
|
+
| 🚫 | **Deprecated**: This rule is deprecated. |
|
|
109
|
+
| 🟢 | **Type-unaware**: AST-only, runs in oxlint JS-plugin tier. |
|
|
110
|
+
| 🟡 | **Type-aware (refining)**: pure-AST primary path; types refine precision. |
|
|
111
|
+
| 🟠 | **Type-aware (graceful)**: requires TS program; silent without it. |
|
|
112
|
+
|
|
113
|
+
<!-- AUTO-GENERATED:RULES_TABLE:START - Do not edit manually -->
|
|
114
|
+
| Rule | CWE | OWASP | CVSS | Description | 🧠 | 💼 | ⚠️ | 🔧 | 💡 | 🚫 |
|
|
115
|
+
| :--- | :---: | :---: | :---: | :--- | :---: | :---: | :---: | :---: | :---: | :---: |
|
|
116
|
+
| [no-unsafe-query](https://eslint.interlace.tools/docs/security/plugin-drizzle-security/rules/no-unsafe-query?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-drizzle-security) | CWE-89 | A03:2021 | | Prevent SQL injection by disallowing string concatenation or interpolated template literals in Drizzle sql.… | 🟢 | 💼 | | | | |
|
|
117
|
+
<!-- AUTO-GENERATED:RULES_TABLE:END -->
|
|
118
|
+
## 🔗 Related ESLint Plugins
|
|
119
|
+
|
|
120
|
+
Part of the **Interlace ESLint Ecosystem** — AI-native security plugins with LLM-optimized error messages:
|
|
121
|
+
|
|
122
|
+
| Plugin | Downloads | Description |
|
|
123
|
+
| :--- | :---: | :--- |
|
|
124
|
+
| [`eslint-plugin-secure-coding`](https://www.npmjs.com/package/eslint-plugin-secure-coding) | [](https://www.npmjs.com/package/eslint-plugin-secure-coding) | General security rules & OWASP guidelines. |
|
|
125
|
+
| [`eslint-plugin-pg`](https://www.npmjs.com/package/eslint-plugin-pg) | [](https://www.npmjs.com/package/eslint-plugin-pg) | PostgreSQL security & best practices. |
|
|
126
|
+
| [`eslint-plugin-node-security`](https://www.npmjs.com/package/eslint-plugin-node-security) | [](https://www.npmjs.com/package/eslint-plugin-node-security) | Node.js core-module security (fs, child_process, vm, crypto, Buffer). |
|
|
127
|
+
| [`eslint-plugin-jwt`](https://www.npmjs.com/package/eslint-plugin-jwt) | [](https://www.npmjs.com/package/eslint-plugin-jwt) | JWT security & best practices. |
|
|
128
|
+
| [`eslint-plugin-browser-security`](https://www.npmjs.com/package/eslint-plugin-browser-security) | [](https://www.npmjs.com/package/eslint-plugin-browser-security) | Browser-specific security & XSS prevention. |
|
|
129
|
+
| [`eslint-plugin-express-security`](https://www.npmjs.com/package/eslint-plugin-express-security) | [](https://www.npmjs.com/package/eslint-plugin-express-security) | Express.js security hardening rules. |
|
|
130
|
+
| [`eslint-plugin-lambda-security`](https://www.npmjs.com/package/eslint-plugin-lambda-security) | [](https://www.npmjs.com/package/eslint-plugin-lambda-security) | AWS Lambda security best practices. |
|
|
131
|
+
| [`eslint-plugin-nestjs-security`](https://www.npmjs.com/package/eslint-plugin-nestjs-security) | [](https://www.npmjs.com/package/eslint-plugin-nestjs-security) | NestJS security rules & patterns. |
|
|
132
|
+
| [`eslint-plugin-mongodb-security`](https://www.npmjs.com/package/eslint-plugin-mongodb-security) | [](https://www.npmjs.com/package/eslint-plugin-mongodb-security) | MongoDB security best practices. |
|
|
133
|
+
| [`eslint-plugin-vercel-ai-security`](https://www.npmjs.com/package/eslint-plugin-vercel-ai-security) | [](https://www.npmjs.com/package/eslint-plugin-vercel-ai-security) | Vercel AI SDK security hardening. |
|
|
134
|
+
| [`eslint-plugin-import-next`](https://www.npmjs.com/package/eslint-plugin-import-next) | [](https://www.npmjs.com/package/eslint-plugin-import-next) | Next-gen import sorting & architecture. |
|
|
135
|
+
|
|
136
|
+
<!-- INTERLACE:STAR_CTA:START -->
|
|
137
|
+
## ⭐ Support & follow
|
|
138
|
+
|
|
139
|
+
If this plugin caught a real bug for you, **[star the repo](https://github.com/ofri-peretz/eslint)** — stars are the signal that keeps the Interlace ESLint ecosystem maintained — and **[follow the writeups on Dev.to](https://dev.to/ofri-peretz)** for the benchmarks and security research behind these rules.
|
|
140
|
+
|
|
141
|
+
[](https://github.com/ofri-peretz/eslint)
|
|
142
|
+
|
|
143
|
+
<!-- INTERLACE:STAR_CTA:END -->
|
|
144
|
+
|
|
145
|
+
## 📄 License
|
|
146
|
+
|
|
147
|
+
MIT © [Ofri Peretz](https://github.com/ofri-peretz)
|
|
148
|
+
|
|
149
|
+
<p align="center">
|
|
150
|
+
<a href="https://eslint.interlace.tools/docs/security/plugin-drizzle-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-drizzle-security"><img src="https://eslint.interlace.tools/images/og-drizzle-security.png" alt="ESLint Interlace Plugin" width="100%" /></a>
|
|
151
|
+
</p>
|
|
152
|
+
|
|
153
|
+
<p align="center">
|
|
154
|
+
<a href="https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-drizzle-security" target="blank"><img src="https://eslint.interlace.tools/icon-light.svg" alt="Interlace" height="70" /></a>
|
|
155
|
+
</p>
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "eslint-plugin-drizzle-security",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "ESLint plugin for drizzle-orm — detects SQL injection in raw queries built with string concatenation or template literals.",
|
|
5
|
+
"type": "commonjs",
|
|
6
|
+
"main": "./src/index.js",
|
|
7
|
+
"types": "./src/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./src/index.d.ts",
|
|
11
|
+
"default": "./src/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./oxlint": {
|
|
14
|
+
"types": "./src/oxlint.d.ts",
|
|
15
|
+
"default": "./src/oxlint.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"author": "Ofri Peretz <ofriperetzdev@gmail.com>",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"homepage": "https://eslint.interlace.tools/docs/security/plugin-drizzle-security?utm_source=npm&utm_medium=referral&utm_campaign=eslint-plugin-drizzle-security",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/ofri-peretz/eslint.git",
|
|
24
|
+
"directory": "packages/eslint-plugin-drizzle-security"
|
|
25
|
+
},
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/ofri-peretz/eslint/issues"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"src/",
|
|
34
|
+
"dist/",
|
|
35
|
+
"README.md",
|
|
36
|
+
"LICENSE",
|
|
37
|
+
"CHANGELOG.md"
|
|
38
|
+
],
|
|
39
|
+
"keywords": [
|
|
40
|
+
"eslint",
|
|
41
|
+
"eslintplugin",
|
|
42
|
+
"eslint-plugin",
|
|
43
|
+
"static-analysis",
|
|
44
|
+
"linting",
|
|
45
|
+
"code-quality",
|
|
46
|
+
"security",
|
|
47
|
+
"sast",
|
|
48
|
+
"appsec",
|
|
49
|
+
"vulnerability",
|
|
50
|
+
"owasp",
|
|
51
|
+
"cwe",
|
|
52
|
+
"interlace-security",
|
|
53
|
+
"drizzle",
|
|
54
|
+
"drizzle-orm",
|
|
55
|
+
"sql",
|
|
56
|
+
"sql-injection",
|
|
57
|
+
"cwe-89",
|
|
58
|
+
"raw-query",
|
|
59
|
+
"database",
|
|
60
|
+
"database-security",
|
|
61
|
+
"mysql",
|
|
62
|
+
"sqlite",
|
|
63
|
+
"postgres",
|
|
64
|
+
"llm-optimized",
|
|
65
|
+
"ai-assistant",
|
|
66
|
+
"typescript"
|
|
67
|
+
],
|
|
68
|
+
"engines": {
|
|
69
|
+
"node": ">=18.0.0"
|
|
70
|
+
},
|
|
71
|
+
"peerDependencies": {
|
|
72
|
+
"eslint": "^8.0.0 || ^9.0.0 || ^10.0.0",
|
|
73
|
+
"drizzle-orm": "^0.29.0 || ^0.30.0 || ^1.0.0"
|
|
74
|
+
},
|
|
75
|
+
"peerDependenciesMeta": {
|
|
76
|
+
"drizzle-orm": {
|
|
77
|
+
"optional": true
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"dependencies": {
|
|
81
|
+
"tslib": "^2.3.0",
|
|
82
|
+
"@interlace/eslint-devkit": "^1.4.3"
|
|
83
|
+
},
|
|
84
|
+
"devDependencies": {
|
|
85
|
+
"@typescript-eslint/parser": "^8.46.2",
|
|
86
|
+
"@typescript-eslint/rule-tester": "^8.46.2"
|
|
87
|
+
},
|
|
88
|
+
"scripts": {
|
|
89
|
+
"build": "tsx ../../scripts/build-package.ts",
|
|
90
|
+
"test": "vitest run",
|
|
91
|
+
"test:coverage": "vitest run --coverage",
|
|
92
|
+
"typecheck": "tsc -p tsconfig.lib.json --noEmit"
|
|
93
|
+
},
|
|
94
|
+
"funding": {
|
|
95
|
+
"type": "github",
|
|
96
|
+
"url": "git+https://github.com/ofri-peretz/eslint.git"
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* eslint-plugin-drizzle-security
|
|
8
|
+
*
|
|
9
|
+
* ESLint plugin with security rules for Drizzle.
|
|
10
|
+
*
|
|
11
|
+
* @see https://github.com/ofri-peretz/eslint/tree/main/packages/eslint-plugin-drizzle-security
|
|
12
|
+
*/
|
|
13
|
+
import { TSESLint } from '@interlace/eslint-devkit';
|
|
14
|
+
/**
|
|
15
|
+
* Collection of all rules
|
|
16
|
+
*/
|
|
17
|
+
export declare const rules: Record<string, TSESLint.RuleModule<string, readonly unknown[]>>;
|
|
18
|
+
/**
|
|
19
|
+
* ESLint Plugin object
|
|
20
|
+
*/
|
|
21
|
+
export declare const plugin: TSESLint.FlatConfig.Plugin;
|
|
22
|
+
/**
|
|
23
|
+
* Preset configurations
|
|
24
|
+
*/
|
|
25
|
+
export declare const configs: Record<string, TSESLint.FlatConfig.Config>;
|
|
26
|
+
/**
|
|
27
|
+
* Default export for ESLint plugin
|
|
28
|
+
*/
|
|
29
|
+
export default plugin;
|
|
30
|
+
export type { AllDrizzleRulesOptions, NoUnsafeQueryOptions } from './types/index';
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.configs = exports.plugin = exports.rules = void 0;
|
|
9
|
+
const no_unsafe_query_1 = require("./rules/no-unsafe-query");
|
|
10
|
+
/**
|
|
11
|
+
* Collection of all rules
|
|
12
|
+
*/
|
|
13
|
+
exports.rules = {
|
|
14
|
+
'no-unsafe-query': no_unsafe_query_1.noUnsafeQuery,
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* ESLint Plugin object
|
|
18
|
+
*/
|
|
19
|
+
exports.plugin = {
|
|
20
|
+
meta: {
|
|
21
|
+
name: 'eslint-plugin-drizzle-security',
|
|
22
|
+
version: '0.1.0',
|
|
23
|
+
},
|
|
24
|
+
rules: exports.rules,
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Preset configurations
|
|
28
|
+
*/
|
|
29
|
+
exports.configs = {
|
|
30
|
+
/**
|
|
31
|
+
* Flagship preset — the highest-signal rule(s) from this plugin, shippable
|
|
32
|
+
* in a CI gate. Currently identical to `recommended`.
|
|
33
|
+
*/
|
|
34
|
+
flagship: {
|
|
35
|
+
plugins: { 'drizzle-security': exports.plugin },
|
|
36
|
+
rules: {
|
|
37
|
+
'drizzle-security/no-unsafe-query': 'error',
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
/**
|
|
41
|
+
* Recommended preset — balanced security for most projects
|
|
42
|
+
*/
|
|
43
|
+
recommended: {
|
|
44
|
+
plugins: { 'drizzle-security': exports.plugin },
|
|
45
|
+
rules: {
|
|
46
|
+
'drizzle-security/no-unsafe-query': 'error',
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
/**
|
|
50
|
+
* Strict preset — all rules as errors
|
|
51
|
+
*/
|
|
52
|
+
strict: {
|
|
53
|
+
plugins: { 'drizzle-security': exports.plugin },
|
|
54
|
+
rules: Object.fromEntries(Object.keys(exports.rules).map((ruleName) => [`drizzle-security/${ruleName}`, 'error'])),
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Default export for ESLint plugin
|
|
59
|
+
*/
|
|
60
|
+
exports.default = exports.plugin;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* oxlint sub-export.
|
|
8
|
+
*
|
|
9
|
+
* Consumers wire oxlint to this entry via:
|
|
10
|
+
* { "jsPlugins": ["eslint-plugin-drizzle-security/oxlint"] }
|
|
11
|
+
*
|
|
12
|
+
* oxlint's JS plugin loader does `require('eslint-plugin-drizzle-security/oxlint')` and reads
|
|
13
|
+
* `.rules` off the result. The compiled output of `export = plugin` is
|
|
14
|
+
* `module.exports = plugin`, which gives oxlint the plugin object directly
|
|
15
|
+
* (`{ meta, rules }`) — no wrapper, no `.default` indirection.
|
|
16
|
+
*
|
|
17
|
+
* Generated by scripts/generate-oxlint-shims.mjs. Do not edit by hand.
|
|
18
|
+
*/
|
|
19
|
+
import { plugin } from './index';
|
|
20
|
+
export = plugin;
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
/**
|
|
8
|
+
* oxlint sub-export.
|
|
9
|
+
*
|
|
10
|
+
* Consumers wire oxlint to this entry via:
|
|
11
|
+
* { "jsPlugins": ["eslint-plugin-drizzle-security/oxlint"] }
|
|
12
|
+
*
|
|
13
|
+
* oxlint's JS plugin loader does `require('eslint-plugin-drizzle-security/oxlint')` and reads
|
|
14
|
+
* `.rules` off the result. The compiled output of `export = plugin` is
|
|
15
|
+
* `module.exports = plugin`, which gives oxlint the plugin object directly
|
|
16
|
+
* (`{ meta, rules }`) — no wrapper, no `.default` indirection.
|
|
17
|
+
*
|
|
18
|
+
* Generated by scripts/generate-oxlint-shims.mjs. Do not edit by hand.
|
|
19
|
+
*/
|
|
20
|
+
const index_1 = require("./index");
|
|
21
|
+
module.exports = index_1.plugin;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
export declare const noUnsafeQuery: import("@typescript-eslint/utils/ts-eslint").RuleModule<import("@interlace/eslint-devkit").SqlInjectionMessageIds, [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.noUnsafeQuery = void 0;
|
|
9
|
+
/**
|
|
10
|
+
* no-unsafe-query — Drizzle-flavoured CWE-89.
|
|
11
|
+
*
|
|
12
|
+
* Instantiates the shared detector (`createSqlInjectionRule` in
|
|
13
|
+
* @interlace/eslint-devkit) with Drizzle's raw-SQL sinks and its own
|
|
14
|
+
* remediation copy. See docs/rules/no-unsafe-query.md.
|
|
15
|
+
*/
|
|
16
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
17
|
+
exports.noUnsafeQuery = (0, eslint_devkit_1.createSqlInjectionRule)({
|
|
18
|
+
meta: {
|
|
19
|
+
type: 'problem',
|
|
20
|
+
docs: {
|
|
21
|
+
description: 'Prevent SQL injection by disallowing string concatenation or interpolated template literals in Drizzle sql.raw() calls.',
|
|
22
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-drizzle-security/docs/rules/no-unsafe-query.md',
|
|
23
|
+
cwe: 'CWE-89',
|
|
24
|
+
cvss: 9.8,
|
|
25
|
+
confidence: 'high',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
methods: ['raw'],
|
|
29
|
+
requireSqlKeywords: false,
|
|
30
|
+
fix: 'Use the `sql` tagged template, which parameterizes interpolated values, instead of `sql.raw()`.',
|
|
31
|
+
documentationLink: 'https://orm.drizzle.team/docs/sql#sqlraw',
|
|
32
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
export type NoUnsafeQueryOptions = [];
|
|
7
|
+
export interface AllDrizzleRulesOptions {
|
|
8
|
+
'drizzle-security/no-unsafe-query': NoUnsafeQueryOptions;
|
|
9
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "eslint-plugin-drizzle-security",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "ESLint plugin for drizzle-orm \u2014 detects SQL injection in raw queries built with string concatenation or template literals.",
|
|
5
|
+
"type": "commonjs",
|
|
6
|
+
"main": "./dist/src/index.js",
|
|
7
|
+
"types": "./dist/src/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/src/index.d.ts",
|
|
11
|
+
"default": "./dist/src/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./oxlint": {
|
|
14
|
+
"types": "./src/oxlint.d.ts",
|
|
15
|
+
"default": "./src/oxlint.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"author": "Ofri Peretz <ofriperetzdev@gmail.com>",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"homepage": "https://eslint.interlace.tools/docs/security/plugin-drizzle-security?utm_source=npm&utm_medium=referral&utm_campaign=eslint-plugin-drizzle-security",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/ofri-peretz/eslint.git",
|
|
24
|
+
"directory": "packages/eslint-plugin-drizzle-security"
|
|
25
|
+
},
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/ofri-peretz/eslint/issues"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"src/",
|
|
34
|
+
"dist/",
|
|
35
|
+
"README.md",
|
|
36
|
+
"LICENSE",
|
|
37
|
+
"CHANGELOG.md"
|
|
38
|
+
],
|
|
39
|
+
"keywords": [
|
|
40
|
+
"eslint",
|
|
41
|
+
"eslintplugin",
|
|
42
|
+
"eslint-plugin",
|
|
43
|
+
"static-analysis",
|
|
44
|
+
"linting",
|
|
45
|
+
"code-quality",
|
|
46
|
+
"security",
|
|
47
|
+
"sast",
|
|
48
|
+
"appsec",
|
|
49
|
+
"vulnerability",
|
|
50
|
+
"owasp",
|
|
51
|
+
"cwe",
|
|
52
|
+
"interlace-security",
|
|
53
|
+
"drizzle",
|
|
54
|
+
"drizzle-orm",
|
|
55
|
+
"sql",
|
|
56
|
+
"sql-injection",
|
|
57
|
+
"cwe-89",
|
|
58
|
+
"raw-query",
|
|
59
|
+
"database",
|
|
60
|
+
"database-security",
|
|
61
|
+
"mysql",
|
|
62
|
+
"sqlite",
|
|
63
|
+
"postgres",
|
|
64
|
+
"llm-optimized",
|
|
65
|
+
"ai-assistant",
|
|
66
|
+
"typescript"
|
|
67
|
+
],
|
|
68
|
+
"engines": {
|
|
69
|
+
"node": ">=18.0.0"
|
|
70
|
+
},
|
|
71
|
+
"peerDependencies": {
|
|
72
|
+
"eslint": "^8.0.0 || ^9.0.0 || ^10.0.0",
|
|
73
|
+
"drizzle-orm": "^0.29.0 || ^0.30.0 || ^1.0.0"
|
|
74
|
+
},
|
|
75
|
+
"peerDependenciesMeta": {
|
|
76
|
+
"drizzle-orm": {
|
|
77
|
+
"optional": true
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"dependencies": {
|
|
81
|
+
"tslib": "^2.3.0",
|
|
82
|
+
"@interlace/eslint-devkit": "^1.4.3"
|
|
83
|
+
},
|
|
84
|
+
"devDependencies": {
|
|
85
|
+
"@typescript-eslint/parser": "^8.46.2",
|
|
86
|
+
"@typescript-eslint/rule-tester": "^8.46.2"
|
|
87
|
+
},
|
|
88
|
+
"scripts": {
|
|
89
|
+
"build": "tsx ../../scripts/build-package.ts",
|
|
90
|
+
"test": "vitest run",
|
|
91
|
+
"test:coverage": "vitest run --coverage",
|
|
92
|
+
"typecheck": "tsc -p tsconfig.lib.json --noEmit"
|
|
93
|
+
},
|
|
94
|
+
"funding": {
|
|
95
|
+
"type": "github",
|
|
96
|
+
"url": "git+https://github.com/ofri-peretz/eslint.git"
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import plugin from './index';
|
|
3
|
+
import { rules, configs } from './index';
|
|
4
|
+
|
|
5
|
+
describe('eslint-plugin-drizzle-security plugin interface', () => {
|
|
6
|
+
it('should export correct meta information', () => {
|
|
7
|
+
expect(plugin.meta).toBeDefined();
|
|
8
|
+
expect(plugin.meta?.name).toBe('eslint-plugin-drizzle-security');
|
|
9
|
+
expect(plugin.meta?.version).toBeDefined();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('should export all sequelize-security rules', () => {
|
|
13
|
+
expect(plugin.rules).toBeDefined();
|
|
14
|
+
const ruleKeys = Object.keys(plugin.rules || {});
|
|
15
|
+
expect(ruleKeys).toEqual(['no-unsafe-query']);
|
|
16
|
+
expect(ruleKeys.length).toBe(1);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe('configurations', () => {
|
|
20
|
+
it('should provide recommended configuration', () => {
|
|
21
|
+
expect(configs.recommended).toBeDefined();
|
|
22
|
+
expect(configs.recommended.plugins?.['drizzle-security']).toBeDefined();
|
|
23
|
+
|
|
24
|
+
const recommendedRules = configs.recommended.rules || {};
|
|
25
|
+
Object.keys(recommendedRules).forEach((ruleName) => {
|
|
26
|
+
expect(ruleName).toMatch(/^drizzle-security\//);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
expect(recommendedRules['drizzle-security/no-unsafe-query']).toBe('error');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should provide flagship configuration', () => {
|
|
33
|
+
expect(configs.flagship).toBeDefined();
|
|
34
|
+
expect(configs.flagship.rules?.['drizzle-security/no-unsafe-query']).toBe('error');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should provide strict configuration', () => {
|
|
38
|
+
expect(configs.strict).toBeDefined();
|
|
39
|
+
expect(configs.strict.plugins?.['drizzle-security']).toBeDefined();
|
|
40
|
+
|
|
41
|
+
const strictRules = configs.strict.rules || {};
|
|
42
|
+
Object.keys(strictRules).forEach((ruleName) => {
|
|
43
|
+
expect(ruleName).toMatch(/^drizzle-security\//);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
expect(strictRules['drizzle-security/no-unsafe-query']).toBe('error');
|
|
47
|
+
expect(Object.keys(strictRules).length).toBe(Object.keys(rules).length);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* eslint-plugin-drizzle-security
|
|
9
|
+
*
|
|
10
|
+
* ESLint plugin with security rules for Drizzle.
|
|
11
|
+
*
|
|
12
|
+
* @see https://github.com/ofri-peretz/eslint/tree/main/packages/eslint-plugin-drizzle-security
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { TSESLint } from '@interlace/eslint-devkit';
|
|
16
|
+
|
|
17
|
+
import { noUnsafeQuery } from './rules/no-unsafe-query';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Collection of all rules
|
|
21
|
+
*/
|
|
22
|
+
export const rules: Record<string, TSESLint.RuleModule<string, readonly unknown[]>> = {
|
|
23
|
+
'no-unsafe-query': noUnsafeQuery,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* ESLint Plugin object
|
|
28
|
+
*/
|
|
29
|
+
export const plugin: TSESLint.FlatConfig.Plugin = {
|
|
30
|
+
meta: {
|
|
31
|
+
name: 'eslint-plugin-drizzle-security',
|
|
32
|
+
version: '0.1.0',
|
|
33
|
+
},
|
|
34
|
+
rules,
|
|
35
|
+
} satisfies TSESLint.FlatConfig.Plugin;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Preset configurations
|
|
39
|
+
*/
|
|
40
|
+
export const configs: Record<string, TSESLint.FlatConfig.Config> = {
|
|
41
|
+
/**
|
|
42
|
+
* Flagship preset — the highest-signal rule(s) from this plugin, shippable
|
|
43
|
+
* in a CI gate. Currently identical to `recommended`.
|
|
44
|
+
*/
|
|
45
|
+
flagship: {
|
|
46
|
+
plugins: { 'drizzle-security': plugin },
|
|
47
|
+
rules: {
|
|
48
|
+
'drizzle-security/no-unsafe-query': 'error',
|
|
49
|
+
},
|
|
50
|
+
} satisfies TSESLint.FlatConfig.Config,
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Recommended preset — balanced security for most projects
|
|
54
|
+
*/
|
|
55
|
+
recommended: {
|
|
56
|
+
plugins: { 'drizzle-security': plugin },
|
|
57
|
+
rules: {
|
|
58
|
+
'drizzle-security/no-unsafe-query': 'error',
|
|
59
|
+
},
|
|
60
|
+
} satisfies TSESLint.FlatConfig.Config,
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Strict preset — all rules as errors
|
|
64
|
+
*/
|
|
65
|
+
strict: {
|
|
66
|
+
plugins: { 'drizzle-security': plugin },
|
|
67
|
+
rules: Object.fromEntries(
|
|
68
|
+
Object.keys(rules).map((ruleName) => [`drizzle-security/${ruleName}`, 'error']),
|
|
69
|
+
),
|
|
70
|
+
} satisfies TSESLint.FlatConfig.Config,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Default export for ESLint plugin
|
|
75
|
+
*/
|
|
76
|
+
export default plugin;
|
|
77
|
+
|
|
78
|
+
export type { AllDrizzleRulesOptions, NoUnsafeQueryOptions } from './types/index';
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { describe, it, expect } from 'vitest';
|
|
8
|
+
import * as fs from 'node:fs';
|
|
9
|
+
import * as path from 'node:path';
|
|
10
|
+
import { plugin as mainPlugin } from './index';
|
|
11
|
+
import * as typeExports from './types';
|
|
12
|
+
|
|
13
|
+
type Plugin = typeof mainPlugin;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Smoke tests for the `./oxlint` sub-export.
|
|
17
|
+
*
|
|
18
|
+
* Runtime shape: `oxlint.ts` uses `export = plugin`, which compiles to
|
|
19
|
+
* `module.exports = plugin`. From an ESM dynamic `import('./oxlint')` view,
|
|
20
|
+
* Node's CJS interop surfaces that value at `.default`. From oxlint's
|
|
21
|
+
* `require('eslint-plugin-drizzle-security/oxlint')` view, it sits at the top of
|
|
22
|
+
* `module.exports` — the `{ meta, rules }` shape oxlint's JS plugin loader
|
|
23
|
+
* expects.
|
|
24
|
+
*/
|
|
25
|
+
describe('eslint-plugin-drizzle-security/oxlint sub-export', () => {
|
|
26
|
+
it('declares the ./oxlint sub-export in package.json', () => {
|
|
27
|
+
const pkgJson = JSON.parse(
|
|
28
|
+
fs.readFileSync(path.resolve(__dirname, '..', 'package.json'), 'utf8'),
|
|
29
|
+
);
|
|
30
|
+
expect(pkgJson.exports['./oxlint']).toEqual({
|
|
31
|
+
types: './src/oxlint.d.ts',
|
|
32
|
+
default: './src/oxlint.js',
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('re-exports the plugin object (meta + rules at top level)', async () => {
|
|
37
|
+
const oxlintModule = await import('./oxlint.js');
|
|
38
|
+
const oxlintPlugin = (oxlintModule as unknown as { default: Plugin }).default;
|
|
39
|
+
expect(oxlintPlugin).toBeDefined();
|
|
40
|
+
expect(oxlintPlugin.meta?.name).toBe('eslint-plugin-drizzle-security');
|
|
41
|
+
expect(oxlintPlugin.rules).toBeDefined();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('exposes the same rule names as the main entry (no rules dropped)', async () => {
|
|
45
|
+
const oxlintModule = await import('./oxlint.js');
|
|
46
|
+
const oxlintPlugin = (oxlintModule as unknown as { default: Plugin }).default;
|
|
47
|
+
expect(Object.keys(oxlintPlugin.rules || {}).toSorted()).toEqual(
|
|
48
|
+
Object.keys(mainPlugin.rules || {}).toSorted(),
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('exposes the same rule references (pass-through, not a copy)', async () => {
|
|
53
|
+
const oxlintModule = await import('./oxlint.js');
|
|
54
|
+
const oxlintPlugin = (oxlintModule as unknown as { default: Plugin }).default;
|
|
55
|
+
for (const ruleName of Object.keys(mainPlugin.rules || {})) {
|
|
56
|
+
expect(oxlintPlugin.rules?.[ruleName]).toBe(
|
|
57
|
+
(mainPlugin.rules as Record<string, unknown>)[ruleName],
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe('types sub-export', () => {
|
|
64
|
+
it('is a type-only module with no runtime exports', () => {
|
|
65
|
+
expect(Object.keys(typeExports)).toEqual([]);
|
|
66
|
+
});
|
|
67
|
+
});
|
package/src/oxlint.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* oxlint sub-export.
|
|
9
|
+
*
|
|
10
|
+
* Consumers wire oxlint to this entry via:
|
|
11
|
+
* { "jsPlugins": ["eslint-plugin-drizzle-security/oxlint"] }
|
|
12
|
+
*
|
|
13
|
+
* oxlint's JS plugin loader does `require('eslint-plugin-drizzle-security/oxlint')` and reads
|
|
14
|
+
* `.rules` off the result. The compiled output of `export = plugin` is
|
|
15
|
+
* `module.exports = plugin`, which gives oxlint the plugin object directly
|
|
16
|
+
* (`{ meta, rules }`) — no wrapper, no `.default` indirection.
|
|
17
|
+
*
|
|
18
|
+
* Generated by scripts/generate-oxlint-shims.mjs. Do not edit by hand.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { plugin } from './index';
|
|
22
|
+
|
|
23
|
+
export = plugin;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* no-unsafe-query — Drizzle-flavoured CWE-89.
|
|
9
|
+
*
|
|
10
|
+
* Instantiates the shared detector (`createSqlInjectionRule` in
|
|
11
|
+
* @interlace/eslint-devkit) with Drizzle's raw-SQL sinks and its own
|
|
12
|
+
* remediation copy. See docs/rules/no-unsafe-query.md.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { createSqlInjectionRule } from '@interlace/eslint-devkit';
|
|
16
|
+
|
|
17
|
+
export const noUnsafeQuery = createSqlInjectionRule({
|
|
18
|
+
meta: {
|
|
19
|
+
type: 'problem',
|
|
20
|
+
docs: {
|
|
21
|
+
description:
|
|
22
|
+
'Prevent SQL injection by disallowing string concatenation or interpolated template literals in Drizzle sql.raw() calls.',
|
|
23
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-drizzle-security/docs/rules/no-unsafe-query.md',
|
|
24
|
+
cwe: 'CWE-89',
|
|
25
|
+
cvss: 9.8,
|
|
26
|
+
confidence: 'high',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
methods: ['raw'],
|
|
30
|
+
requireSqlKeywords: false,
|
|
31
|
+
fix: 'Use the `sql` tagged template, which parameterizes interpolated values, instead of `sql.raw()`.',
|
|
32
|
+
documentationLink: 'https://orm.drizzle.team/docs/sql#sqlraw',
|
|
33
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for drizzle-security/no-unsafe-query
|
|
3
|
+
* CWE-89 — SQL injection through Drizzle's raw-SQL escapes.
|
|
4
|
+
*/
|
|
5
|
+
import { RuleTester } from '@typescript-eslint/rule-tester';
|
|
6
|
+
import { describe, it, afterAll } from 'vitest';
|
|
7
|
+
import * as parser from '@typescript-eslint/parser';
|
|
8
|
+
import { noUnsafeQuery } from './index';
|
|
9
|
+
|
|
10
|
+
RuleTester.afterAll = afterAll;
|
|
11
|
+
RuleTester.it = it;
|
|
12
|
+
RuleTester.itOnly = it.only;
|
|
13
|
+
RuleTester.describe = describe;
|
|
14
|
+
|
|
15
|
+
const ruleTester = new RuleTester({
|
|
16
|
+
languageOptions: {
|
|
17
|
+
parser,
|
|
18
|
+
parserOptions: { ecmaVersion: 2022, sourceType: 'module' },
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe('no-unsafe-query', () => {
|
|
23
|
+
describe('Valid — parameterized and static SQL', () => {
|
|
24
|
+
ruleTester.run('valid', noUnsafeQuery, {
|
|
25
|
+
valid: [
|
|
26
|
+
{
|
|
27
|
+
name: 'safe idiom',
|
|
28
|
+
code: 'db.select().from(users).where(sql`id = ${userId}`);',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: 'static SQL, no interpolation',
|
|
32
|
+
code: "sql.raw('SELECT * FROM users');",
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'no arguments',
|
|
36
|
+
code: 'sql.raw();',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: 'unrelated code',
|
|
40
|
+
code: 'const x = 1;',
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: 'safe variable passed through',
|
|
44
|
+
code: "const sql = 'SELECT * FROM users'; sql.raw(sql);",
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
invalid: [],
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe('Invalid — interpolated raw SQL', () => {
|
|
52
|
+
ruleTester.run('invalid', noUnsafeQuery, {
|
|
53
|
+
valid: [],
|
|
54
|
+
invalid: [
|
|
55
|
+
{
|
|
56
|
+
name: 'template interpolation',
|
|
57
|
+
code: 'sql.raw(`SELECT * FROM users WHERE id = ${userId}`);',
|
|
58
|
+
errors: [{ messageId: 'unsafeTemplateLiteral' }],
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: 'string concatenation',
|
|
62
|
+
code: "sql.raw('SELECT * FROM users WHERE id = ' + userId);",
|
|
63
|
+
errors: [{ messageId: 'noUnsafeQuery' }],
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: 'tainted variable reaches the sink',
|
|
67
|
+
code: [
|
|
68
|
+
'const sql = `SELECT * FROM users WHERE id = ${id}`;',
|
|
69
|
+
'sql.raw(sql);',
|
|
70
|
+
].join('\n'),
|
|
71
|
+
errors: [{ messageId: 'unsafeTemplateLiteral' }],
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export type NoUnsafeQueryOptions = [];
|
|
8
|
+
|
|
9
|
+
export interface AllDrizzleRulesOptions {
|
|
10
|
+
'drizzle-security/no-unsafe-query': NoUnsafeQueryOptions;
|
|
11
|
+
}
|