eslint-plugin-postgresql-security 1.5.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.
Files changed (95) hide show
  1. package/CHANGELOG.md +150 -0
  2. package/LICENSE +23 -0
  3. package/README.md +169 -0
  4. package/dist/AGENTS.md +118 -0
  5. package/dist/CHANGELOG.md +150 -0
  6. package/dist/LICENSE +23 -0
  7. package/dist/README.md +169 -0
  8. package/dist/package.json +99 -0
  9. package/dist/src/constants.d.ts +6 -0
  10. package/dist/src/constants.js +13 -0
  11. package/dist/src/index.d.ts +26 -0
  12. package/dist/src/index.js +116 -0
  13. package/dist/src/oxlint.d.ts +20 -0
  14. package/dist/src/oxlint.js +21 -0
  15. package/dist/src/rules/check-query-params/index.d.ts +8 -0
  16. package/dist/src/rules/check-query-params/index.js +90 -0
  17. package/dist/src/rules/no-batch-insert-loop/index.d.ts +8 -0
  18. package/dist/src/rules/no-batch-insert-loop/index.js +90 -0
  19. package/dist/src/rules/no-floating-query/index.d.ts +8 -0
  20. package/dist/src/rules/no-floating-query/index.js +74 -0
  21. package/dist/src/rules/no-hardcoded-credentials/index.d.ts +8 -0
  22. package/dist/src/rules/no-hardcoded-credentials/index.js +86 -0
  23. package/dist/src/rules/no-insecure-ssl/index.d.ts +8 -0
  24. package/dist/src/rules/no-insecure-ssl/index.js +66 -0
  25. package/dist/src/rules/no-missing-client-release/index.d.ts +8 -0
  26. package/dist/src/rules/no-missing-client-release/index.js +85 -0
  27. package/dist/src/rules/no-select-all/index.d.ts +8 -0
  28. package/dist/src/rules/no-select-all/index.js +79 -0
  29. package/dist/src/rules/no-transaction-on-pool/index.d.ts +8 -0
  30. package/dist/src/rules/no-transaction-on-pool/index.js +71 -0
  31. package/dist/src/rules/no-unsafe-copy-from/index.d.ts +10 -0
  32. package/dist/src/rules/no-unsafe-copy-from/index.js +205 -0
  33. package/dist/src/rules/no-unsafe-query/index.d.ts +8 -0
  34. package/dist/src/rules/no-unsafe-query/index.js +132 -0
  35. package/dist/src/rules/no-unsafe-search-path/index.d.ts +8 -0
  36. package/dist/src/rules/no-unsafe-search-path/index.js +144 -0
  37. package/dist/src/rules/prefer-pool-query/index.d.ts +8 -0
  38. package/dist/src/rules/prefer-pool-query/index.js +104 -0
  39. package/dist/src/rules/prevent-double-release/index.d.ts +8 -0
  40. package/dist/src/rules/prevent-double-release/index.js +456 -0
  41. package/dist/src/types/index.d.ts +54 -0
  42. package/dist/src/types/index.js +7 -0
  43. package/package.json +99 -0
  44. package/src/__compatibility__/pg-interface.spec.ts +495 -0
  45. package/src/constants.ts +11 -0
  46. package/src/index.spec.ts +14 -0
  47. package/src/index.test.ts +59 -0
  48. package/src/index.ts +130 -0
  49. package/src/oxlint.spec.ts +70 -0
  50. package/src/oxlint.ts +23 -0
  51. package/src/rules/check-query-params/check-query-params.test.ts +68 -0
  52. package/src/rules/check-query-params/index.spec.ts +117 -0
  53. package/src/rules/check-query-params/index.ts +106 -0
  54. package/src/rules/no-batch-insert-loop/index.spec.ts +105 -0
  55. package/src/rules/no-batch-insert-loop/index.ts +105 -0
  56. package/src/rules/no-batch-insert-loop/no-batch-insert-loop.test.ts +68 -0
  57. package/src/rules/no-floating-query/index.spec.ts +112 -0
  58. package/src/rules/no-floating-query/index.ts +81 -0
  59. package/src/rules/no-floating-query/no-floating-query.test.ts +68 -0
  60. package/src/rules/no-hardcoded-credentials/index.spec.ts +38 -0
  61. package/src/rules/no-hardcoded-credentials/index.ts +93 -0
  62. package/src/rules/no-hardcoded-credentials/no-hardcoded-credentials.test.ts +68 -0
  63. package/src/rules/no-insecure-ssl/index.spec.ts +40 -0
  64. package/src/rules/no-insecure-ssl/index.ts +81 -0
  65. package/src/rules/no-insecure-ssl/no-insecure-ssl.test.ts +68 -0
  66. package/src/rules/no-missing-client-release/coverage-gaps.spec.ts +42 -0
  67. package/src/rules/no-missing-client-release/index.spec.ts +52 -0
  68. package/src/rules/no-missing-client-release/index.ts +100 -0
  69. package/src/rules/no-missing-client-release/no-missing-client-release.test.ts +68 -0
  70. package/src/rules/no-select-all/index.spec.ts +44 -0
  71. package/src/rules/no-select-all/index.ts +92 -0
  72. package/src/rules/no-select-all/no-select-all.test.ts +68 -0
  73. package/src/rules/no-transaction-on-pool/index.spec.ts +36 -0
  74. package/src/rules/no-transaction-on-pool/index.ts +85 -0
  75. package/src/rules/no-transaction-on-pool/no-transaction-on-pool.test.ts +68 -0
  76. package/src/rules/no-unsafe-copy-from/coverage-gaps.spec.ts +76 -0
  77. package/src/rules/no-unsafe-copy-from/index.spec.ts +274 -0
  78. package/src/rules/no-unsafe-copy-from/index.ts +226 -0
  79. package/src/rules/no-unsafe-copy-from/no-unsafe-copy-from.test.ts +78 -0
  80. package/src/rules/no-unsafe-query/coverage-gaps.spec.ts +61 -0
  81. package/src/rules/no-unsafe-query/index.spec.ts +103 -0
  82. package/src/rules/no-unsafe-query/index.ts +149 -0
  83. package/src/rules/no-unsafe-query/no-unsafe-query.test.ts +73 -0
  84. package/src/rules/no-unsafe-search-path/index.spec.ts +46 -0
  85. package/src/rules/no-unsafe-search-path/index.ts +164 -0
  86. package/src/rules/no-unsafe-search-path/no-unsafe-search-path.test.ts +68 -0
  87. package/src/rules/prefer-pool-query/coverage-gaps.spec.ts +76 -0
  88. package/src/rules/prefer-pool-query/index.spec.ts +97 -0
  89. package/src/rules/prefer-pool-query/index.ts +118 -0
  90. package/src/rules/prefer-pool-query/prefer-pool-query.test.ts +68 -0
  91. package/src/rules/prevent-double-release/coverage-gaps.spec.ts +538 -0
  92. package/src/rules/prevent-double-release/index.spec.ts +824 -0
  93. package/src/rules/prevent-double-release/index.ts +534 -0
  94. package/src/rules/prevent-double-release/prevent-double-release.test.ts +70 -0
  95. package/src/types/index.ts +58 -0
@@ -0,0 +1,85 @@
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 { TSESLint, AST_NODE_TYPES, formatLLMMessage, MessageIcons } from '@interlace/eslint-devkit';
8
+ import { NoTransactionOnPoolOptions } from '../../types';
9
+
10
+ // Pre-defined set of transaction keywords for fast lookup
11
+ const TRANSACTION_KEYWORDS = new Set(['BEGIN', 'COMMIT', 'ROLLBACK']);
12
+
13
+ export const noTransactionOnPool: TSESLint.RuleModule<
14
+ 'noTransactionOnPool',
15
+ NoTransactionOnPoolOptions
16
+ > = {
17
+ meta: {
18
+ type: 'problem',
19
+ docs: {
20
+ description: 'Prevent starting transactions directly on the Pool, which is unsafe due to lack of client affinity.',
21
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/no-transaction-on-pool.md',
22
+ cwe: 'CWE-662',
23
+ cweJustification: 'CWE-662 (Improper Synchronization) — running BEGIN/COMMIT on a connection pool can split a logical transaction across different physical clients, breaking ACID atomicity.',
24
+ confidence: 'high',
25
+ },
26
+ messages: {
27
+ noTransactionOnPool: formatLLMMessage({
28
+ icon: MessageIcons.WARNING,
29
+ issueName: 'Transaction on Pool',
30
+ description: 'Transactions should not be started on the Pool directly.',
31
+ severity: 'HIGH',
32
+ effort: 'low',
33
+ fix: 'Use "await pool.connect()" to get a client, then start the transaction on the client.',
34
+ documentationLink: 'https://node-postgres.com/features/transactions',
35
+ }),
36
+ },
37
+ schema: [],
38
+ },
39
+ defaultOptions: [],
40
+ create(context) {
41
+ return {
42
+ CallExpression(node) {
43
+ if (
44
+ node.callee.type !== AST_NODE_TYPES.MemberExpression ||
45
+ node.callee.property.type !== AST_NODE_TYPES.Identifier ||
46
+ node.callee.property.name !== 'query'
47
+ ) {
48
+ return;
49
+ }
50
+
51
+ const args = node.arguments;
52
+ if (args.length === 0) return;
53
+
54
+ const queryArg = args[0];
55
+
56
+ // Only check literals
57
+ if (queryArg.type !== AST_NODE_TYPES.Literal || typeof queryArg.value !== 'string') {
58
+ return;
59
+ }
60
+
61
+ const queryText = queryArg.value.toUpperCase().trim();
62
+
63
+ // Extract first word (handles "BEGIN", "BEGIN;", "BEGIN TRANSACTION", etc.)
64
+ const firstWord = queryText.split(/[;\s]/)[0];
65
+
66
+ if (TRANSACTION_KEYWORDS.has(firstWord)) {
67
+ // Heuristic: If the variable name is 'pool' or ends with 'Pool', stronger signal.
68
+ // However, for safety, if we see pool.query('BEGIN'), it's almost always wrong unless it's a test mock.
69
+ // Let's rely on variable name hint for false positive reduction, or just flag it generally.
70
+ // The most common error is `pool.query('BEGIN')`.
71
+
72
+ if (
73
+ node.callee.object.type === AST_NODE_TYPES.Identifier &&
74
+ (node.callee.object.name === 'pool' || node.callee.object.name.toLowerCase().includes('pool'))
75
+ ) {
76
+ context.report({
77
+ node: queryArg,
78
+ messageId: 'noTransactionOnPool',
79
+ });
80
+ }
81
+ }
82
+ },
83
+ };
84
+ },
85
+ };
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Tests for no-transaction-on-pool
3
+ * Prevent starting transactions directly on the Pool, which is unsafe due to lack of client affinity.
4
+ *
5
+ * Generated by: node scripts/generate-rule-tests.mjs
6
+ * Standard: Engineering Standards §5 (side-by-side), §6 (≥5 valid + ≥5 invalid), §8 (RuleTester at describe level)
7
+ */
8
+ import { RuleTester } from '@typescript-eslint/rule-tester';
9
+ import { describe, it, afterAll } from 'vitest';
10
+ import parser from '@typescript-eslint/parser';
11
+ import { noTransactionOnPool } from './index';
12
+
13
+ RuleTester.afterAll = afterAll;
14
+ RuleTester.it = it;
15
+ RuleTester.itOnly = it.only;
16
+ RuleTester.describe = describe;
17
+
18
+ const ruleTester = new RuleTester({
19
+ languageOptions: {
20
+ parser,
21
+ ecmaVersion: 2022,
22
+ sourceType: 'module',
23
+ parserOptions: { ecmaFeatures: { jsx: true } },
24
+ },
25
+ });
26
+
27
+ describe('no-transaction-on-pool', () => {
28
+ describe('Valid Code', () => {
29
+ ruleTester.run('valid - safe patterns', noTransactionOnPool, {
30
+ valid: [
31
+ // Unrelated code should not trigger
32
+ {
33
+ code: `const x = 1;`,
34
+ },
35
+ // Array operations are safe
36
+ {
37
+ code: `const arr = [1, 2, 3];`,
38
+ },
39
+ // Non-targeted method calls are safe
40
+ {
41
+ code: `obj.safeMethod();`,
42
+ },
43
+ // Properly configured connection
44
+ {
45
+ code: `mongoose.connect(uri, { tls: true });`,
46
+ },
47
+ // Environment variable usage is safe (padding case 5)
48
+ {
49
+ code: `const safe4 = process.env.DB_HOST;`,
50
+ },
51
+ ],
52
+ invalid: [],
53
+ });
54
+ });
55
+
56
+ describe('Invalid Code', () => {
57
+ ruleTester.run('invalid - dangerous patterns', noTransactionOnPool, {
58
+ valid: [],
59
+ invalid: [
60
+ // Triggers noTransactionOnPool
61
+ {
62
+ code: `pool.query('BEGIN')`,
63
+ errors: [{ messageId: 'noTransactionOnPool' }],
64
+ },
65
+ ],
66
+ });
67
+ });
68
+ });
@@ -0,0 +1,76 @@
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
+ * Coverage-gap tests for no-unsafe-copy-from: allowlist matching on the
9
+ * template-literal and concatenation paths, unextractable file paths, and
10
+ * statically unverifiable query arguments.
11
+ */
12
+ import { RuleTester } from '@typescript-eslint/rule-tester';
13
+ import { describe, it, afterAll } from 'vitest';
14
+ import * as parser from '@typescript-eslint/parser';
15
+ import { noUnsafeCopyFrom } from './index';
16
+
17
+ RuleTester.afterAll = afterAll;
18
+ RuleTester.it = it;
19
+ RuleTester.itOnly = it.only;
20
+ RuleTester.describe = describe;
21
+
22
+ const ruleTester = new RuleTester({
23
+ languageOptions: {
24
+ parser,
25
+ parserOptions: { ecmaVersion: 2022, sourceType: 'module' },
26
+ },
27
+ });
28
+
29
+ describe('no-unsafe-copy-from — coverage gaps', () => {
30
+ ruleTester.run('allowlist and path-extraction branches', noUnsafeCopyFrom, {
31
+ valid: [
32
+ {
33
+ name: 'template literal (no expressions) with allowlisted path',
34
+ code: 'client.query(`COPY t FROM \'/data/ok.csv\'`);',
35
+ options: [{ allowedPaths: ['^/data/'] }],
36
+ },
37
+ {
38
+ name: 'string concatenation of literals with allowlisted path',
39
+ code: `client.query('COPY t ' + "FROM '/data/ok.csv'");`,
40
+ options: [{ allowedPaths: ['^/data/'] }],
41
+ },
42
+ {
43
+ name: 'string concatenation of literals with allowHardcodedPaths',
44
+ code: `client.query('COPY t ' + "FROM '/etc/data.csv'");`,
45
+ options: [{ allowHardcodedPaths: true }],
46
+ },
47
+ {
48
+ name: 'call-expression query argument is statically unverifiable (skipped)',
49
+ code: `client.query(buildQuery());`,
50
+ },
51
+ {
52
+ name: 'member-expression query argument falls through all cases',
53
+ code: `client.query(cfg.sql);`,
54
+ },
55
+ ],
56
+ invalid: [
57
+ {
58
+ name: 'COPY FROM PROGRAM has no extractable quoted path (still hardcoded)',
59
+ code: `client.query("COPY t FROM PROGRAM 'gzip -dc backup.gz'");`,
60
+ errors: [{ messageId: 'hardcodedPath' }],
61
+ },
62
+ {
63
+ name: 'template-literal hardcoded path not matching the allowlist',
64
+ code: 'client.query(`COPY t FROM \'/etc/passwd\'`);',
65
+ options: [{ allowedPaths: ['^/data/'] }],
66
+ errors: [{ messageId: 'hardcodedPath' }],
67
+ },
68
+ {
69
+ name: 'concatenated hardcoded path not matching the allowlist',
70
+ code: `client.query('COPY t ' + "FROM '/etc/passwd'");`,
71
+ options: [{ allowedPaths: ['^/data/'] }],
72
+ errors: [{ messageId: 'hardcodedPath' }],
73
+ },
74
+ ],
75
+ });
76
+ });
@@ -0,0 +1,274 @@
1
+ import { RuleTester } from '@typescript-eslint/rule-tester';
2
+ import * as parser from '@typescript-eslint/parser';
3
+ import { noUnsafeCopyFrom } from './index';
4
+
5
+ const ruleTester = new RuleTester({
6
+ languageOptions: {
7
+ parser,
8
+ },
9
+ });
10
+
11
+ ruleTester.run('no-unsafe-copy-from', noUnsafeCopyFrom, {
12
+ valid: [
13
+ // ===========================================
14
+ // STDIN patterns (always safe)
15
+ // ===========================================
16
+ {
17
+ name: 'COPY FROM STDIN - literal string',
18
+ code: "client.query('COPY users FROM STDIN')",
19
+ },
20
+ {
21
+ name: 'COPY FROM STDIN - template literal',
22
+ code: 'client.query(`COPY users FROM STDIN`)',
23
+ },
24
+ {
25
+ name: 'COPY FROM STDIN - with CSV format',
26
+ code: "client.query('COPY users FROM STDIN CSV')",
27
+ },
28
+ {
29
+ name: 'COPY FROM STDIN - with options',
30
+ code: "client.query('COPY users (id, name) FROM STDIN WITH (FORMAT CSV, HEADER)')",
31
+ },
32
+ {
33
+ name: 'COPY FROM STDIN - binary expression all literals',
34
+ code: "client.query('COPY ' + 'users ' + 'FROM ' + 'STDIN')",
35
+ },
36
+ {
37
+ name: 'COPY FROM STDIN - case insensitive',
38
+ code: "client.query('copy users from stdin')",
39
+ },
40
+
41
+ // ===========================================
42
+ // Non-COPY queries (should not flag)
43
+ // ===========================================
44
+ {
45
+ name: 'SELECT query - not COPY',
46
+ code: "client.query('SELECT * FROM users')",
47
+ },
48
+ {
49
+ name: 'INSERT query - not COPY',
50
+ code: "client.query('INSERT INTO users VALUES ($1)', [name])",
51
+ },
52
+ {
53
+ name: 'UPDATE query - not COPY',
54
+ code: "client.query('UPDATE users SET name = $1', [name])",
55
+ },
56
+ {
57
+ name: 'DELETE query - not COPY',
58
+ code: "client.query('DELETE FROM users WHERE id = $1', [id])",
59
+ },
60
+ {
61
+ name: 'Binary expression no COPY',
62
+ code: "client.query('SELECT ' + someVar)",
63
+ },
64
+
65
+ // ===========================================
66
+ // Non-query method calls (should not flag)
67
+ // ===========================================
68
+ {
69
+ name: 'Different method name',
70
+ code: "client.execute('COPY users FROM /etc/passwd')",
71
+ },
72
+ {
73
+ name: 'Different object method',
74
+ code: "client.other('COPY users FROM /etc/passwd')",
75
+ },
76
+ {
77
+ name: 'Function call not member expression',
78
+ code: "query('COPY users FROM /etc/passwd')",
79
+ },
80
+
81
+ // ===========================================
82
+ // Edge cases - empty/unusual args
83
+ // ===========================================
84
+ {
85
+ name: 'Empty query arguments',
86
+ code: 'client.query()',
87
+ },
88
+ {
89
+ name: 'Query with function call argument (cannot verify)',
90
+ code: 'client.query(getSqlQuery())',
91
+ },
92
+ {
93
+ name: 'Query with identifier argument (cannot verify)',
94
+ code: 'client.query(sqlQuery)',
95
+ },
96
+
97
+ // ===========================================
98
+ // allowHardcodedPaths option enabled
99
+ // ===========================================
100
+ {
101
+ name: 'Hardcoded path allowed by option',
102
+ code: "client.query(\"COPY users FROM '/var/data/users.csv'\")",
103
+ options: [{ allowHardcodedPaths: true }],
104
+ },
105
+ {
106
+ name: 'Hardcoded path in template literal allowed',
107
+ code: "client.query(`COPY users FROM '/var/data/users.csv'`)",
108
+ options: [{ allowHardcodedPaths: true }],
109
+ },
110
+
111
+ // ===========================================
112
+ // allowedPaths option (regex patterns)
113
+ // ===========================================
114
+ {
115
+ name: 'Path matches allowed pattern',
116
+ code: "client.query(\"COPY users FROM '/var/imports/users.csv'\")",
117
+ options: [{ allowedPaths: ['^/var/imports/'] }],
118
+ },
119
+ {
120
+ name: 'Path matches allowed pattern with extension',
121
+ code: "client.query(\"COPY users FROM '/backup/data.csv'\")",
122
+ options: [{ allowedPaths: ['\\.csv$'] }],
123
+ },
124
+ {
125
+ name: 'Path matches one of multiple allowed patterns',
126
+ code: "client.query(\"COPY users FROM '/tmp/import.csv'\")",
127
+ options: [{ allowedPaths: ['^/var/', '^/tmp/'] }],
128
+ },
129
+
130
+ // ===========================================
131
+ // COPY TO (not FROM - different vulnerability)
132
+ // Note: We only detect COPY FROM, not COPY TO
133
+ // ===========================================
134
+ {
135
+ name: 'COPY TO is not flagged (different rule)',
136
+ code: "client.query(\"COPY users TO '/tmp/export.csv'\")",
137
+ },
138
+ ],
139
+
140
+ invalid: [
141
+ // ===========================================
142
+ // Dynamic paths - CRITICAL (injection risk)
143
+ // ===========================================
144
+ {
145
+ name: 'Template literal with variable in path',
146
+ code: `client.query(\`COPY users FROM '\${filepath}'\`)`,
147
+ errors: [{ messageId: 'dynamicPath' }],
148
+ },
149
+ {
150
+ name: 'Template literal with expression in table name',
151
+ code: `client.query(\`COPY \${table} FROM '/etc/passwd'\`)`,
152
+ errors: [{ messageId: 'dynamicPath' }],
153
+ },
154
+ {
155
+ name: 'Template literal with req.body',
156
+ code: `client.query(\`COPY users FROM '\${req.body.path}'\`)`,
157
+ errors: [{ messageId: 'dynamicPath' }],
158
+ },
159
+ {
160
+ name: 'Binary expression with variable path',
161
+ code: "client.query('COPY users FROM ' + userPath)",
162
+ errors: [{ messageId: 'dynamicPath' }],
163
+ },
164
+ {
165
+ name: 'Binary expression with variable in middle',
166
+ code: "client.query('COPY ' + table + \" FROM '/data/file.csv'\")",
167
+ errors: [{ messageId: 'dynamicPath' }],
168
+ },
169
+ {
170
+ name: 'Complex binary expression with variable',
171
+ code: "client.query('COPY ' + 'users' + ' FROM ' + \"'\" + filepath + \"'\")",
172
+ errors: [{ messageId: 'dynamicPath' }],
173
+ },
174
+
175
+ // ===========================================
176
+ // Hardcoded paths - MEDIUM (server-side file access)
177
+ // ===========================================
178
+ {
179
+ name: 'Literal path to sensitive file',
180
+ code: "client.query(\"COPY users FROM '/etc/passwd'\")",
181
+ errors: [{ messageId: 'hardcodedPath' }],
182
+ },
183
+ {
184
+ name: 'Literal path to data file',
185
+ code: "client.query(\"COPY users FROM '/var/data/users.csv'\")",
186
+ errors: [{ messageId: 'hardcodedPath' }],
187
+ },
188
+ {
189
+ name: 'Template literal no expressions (hardcoded)',
190
+ code: "client.query(`COPY users FROM '/tmp/data.csv'`)",
191
+ errors: [{ messageId: 'hardcodedPath' }],
192
+ },
193
+ {
194
+ name: 'Binary expression all literals (hardcoded)',
195
+ code: "client.query('COPY users FROM ' + \"'/data/file.csv'\")",
196
+ errors: [{ messageId: 'hardcodedPath' }],
197
+ },
198
+ {
199
+ name: 'Single quotes in path',
200
+ code: "client.query(\"COPY users FROM '/path/to/file'\")",
201
+ errors: [{ messageId: 'hardcodedPath' }],
202
+ },
203
+ {
204
+ name: 'Double quotes in SQL',
205
+ code: 'client.query(\'COPY users FROM "/path/to/file"\')',
206
+ errors: [{ messageId: 'hardcodedPath' }],
207
+ },
208
+
209
+ // ===========================================
210
+ // Case variations
211
+ // ===========================================
212
+ {
213
+ name: 'Uppercase COPY FROM',
214
+ code: "client.query(\"COPY users FROM '/tmp/data.csv'\")",
215
+ errors: [{ messageId: 'hardcodedPath' }],
216
+ },
217
+ {
218
+ name: 'Lowercase copy from',
219
+ code: "client.query(\"copy users from '/tmp/data.csv'\")",
220
+ errors: [{ messageId: 'hardcodedPath' }],
221
+ },
222
+ {
223
+ name: 'Mixed case Copy From',
224
+ code: "client.query(\"Copy users From '/tmp/data.csv'\")",
225
+ errors: [{ messageId: 'hardcodedPath' }],
226
+ },
227
+
228
+ // ===========================================
229
+ // With additional SQL syntax
230
+ // ===========================================
231
+ {
232
+ name: 'COPY with column list',
233
+ code: "client.query(\"COPY users (id, name, email) FROM '/tmp/data.csv'\")",
234
+ errors: [{ messageId: 'hardcodedPath' }],
235
+ },
236
+ {
237
+ name: 'COPY with CSV option',
238
+ code: "client.query(\"COPY users FROM '/tmp/data.csv' CSV\")",
239
+ errors: [{ messageId: 'hardcodedPath' }],
240
+ },
241
+ {
242
+ name: 'COPY with WITH clause',
243
+ code: "client.query(\"COPY users FROM '/tmp/data.csv' WITH (FORMAT CSV, HEADER)\")",
244
+ errors: [{ messageId: 'hardcodedPath' }],
245
+ },
246
+
247
+ // ===========================================
248
+ // Dynamic path even with allowHardcodedPaths
249
+ // (Dynamic should ALWAYS be flagged as CRITICAL)
250
+ // ===========================================
251
+ {
252
+ name: 'Dynamic path still flagged even with allowHardcodedPaths',
253
+ code: "client.query(`COPY users FROM '${userPath}'`)",
254
+ options: [{ allowHardcodedPaths: true }],
255
+ errors: [{ messageId: 'dynamicPath' }],
256
+ },
257
+
258
+ // ===========================================
259
+ // Path not in allowedPaths
260
+ // ===========================================
261
+ {
262
+ name: 'Path does not match allowed pattern',
263
+ code: "client.query(\"COPY users FROM '/etc/passwd'\")",
264
+ options: [{ allowedPaths: ['^/var/imports/'] }],
265
+ errors: [{ messageId: 'hardcodedPath' }],
266
+ },
267
+ {
268
+ name: 'Path does not match any allowed pattern',
269
+ code: "client.query(\"COPY users FROM '/home/user/data.csv'\")",
270
+ options: [{ allowedPaths: ['^/var/', '^/tmp/'] }],
271
+ errors: [{ messageId: 'hardcodedPath' }],
272
+ },
273
+ ],
274
+ });