eslint-plugin-postgresql-security 1.5.0 → 1.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/README.md +5 -5
  2. package/package.json +9 -23
  3. package/src/constants.js +1 -0
  4. package/src/index.d.ts +17 -0
  5. package/src/index.js +1 -0
  6. package/src/oxlint.d.ts +17 -0
  7. package/src/oxlint.js +1 -0
  8. package/src/rules/check-query-params/index.js +1 -0
  9. package/src/rules/no-batch-insert-loop/index.js +1 -0
  10. package/src/rules/no-floating-query/index.js +1 -0
  11. package/src/rules/no-hardcoded-credentials/index.js +1 -0
  12. package/src/rules/no-insecure-ssl/index.js +1 -0
  13. package/src/rules/no-missing-client-release/index.js +1 -0
  14. package/src/rules/no-select-all/index.js +1 -0
  15. package/src/rules/no-transaction-on-pool/index.js +1 -0
  16. package/src/rules/no-unsafe-copy-from/index.js +1 -0
  17. package/src/rules/no-unsafe-query/index.js +1 -0
  18. package/src/rules/no-unsafe-search-path/index.js +1 -0
  19. package/src/rules/prefer-pool-query/index.js +1 -0
  20. package/src/rules/prevent-double-release/index.js +1 -0
  21. package/src/types/index.js +1 -0
  22. package/CHANGELOG.md +0 -150
  23. package/dist/AGENTS.md +0 -118
  24. package/dist/CHANGELOG.md +0 -150
  25. package/dist/LICENSE +0 -23
  26. package/dist/README.md +0 -169
  27. package/dist/package.json +0 -99
  28. package/dist/src/constants.d.ts +0 -6
  29. package/dist/src/constants.js +0 -13
  30. package/dist/src/index.d.ts +0 -26
  31. package/dist/src/index.js +0 -116
  32. package/dist/src/oxlint.d.ts +0 -20
  33. package/dist/src/oxlint.js +0 -21
  34. package/dist/src/rules/check-query-params/index.d.ts +0 -8
  35. package/dist/src/rules/check-query-params/index.js +0 -90
  36. package/dist/src/rules/no-batch-insert-loop/index.d.ts +0 -8
  37. package/dist/src/rules/no-batch-insert-loop/index.js +0 -90
  38. package/dist/src/rules/no-floating-query/index.d.ts +0 -8
  39. package/dist/src/rules/no-floating-query/index.js +0 -74
  40. package/dist/src/rules/no-hardcoded-credentials/index.d.ts +0 -8
  41. package/dist/src/rules/no-hardcoded-credentials/index.js +0 -86
  42. package/dist/src/rules/no-insecure-ssl/index.d.ts +0 -8
  43. package/dist/src/rules/no-insecure-ssl/index.js +0 -66
  44. package/dist/src/rules/no-missing-client-release/index.d.ts +0 -8
  45. package/dist/src/rules/no-missing-client-release/index.js +0 -85
  46. package/dist/src/rules/no-select-all/index.d.ts +0 -8
  47. package/dist/src/rules/no-select-all/index.js +0 -79
  48. package/dist/src/rules/no-transaction-on-pool/index.d.ts +0 -8
  49. package/dist/src/rules/no-transaction-on-pool/index.js +0 -71
  50. package/dist/src/rules/no-unsafe-copy-from/index.d.ts +0 -10
  51. package/dist/src/rules/no-unsafe-copy-from/index.js +0 -205
  52. package/dist/src/rules/no-unsafe-query/index.d.ts +0 -8
  53. package/dist/src/rules/no-unsafe-query/index.js +0 -132
  54. package/dist/src/rules/no-unsafe-search-path/index.d.ts +0 -8
  55. package/dist/src/rules/no-unsafe-search-path/index.js +0 -144
  56. package/dist/src/rules/prefer-pool-query/index.d.ts +0 -8
  57. package/dist/src/rules/prefer-pool-query/index.js +0 -104
  58. package/dist/src/rules/prevent-double-release/index.d.ts +0 -8
  59. package/dist/src/rules/prevent-double-release/index.js +0 -456
  60. package/dist/src/types/index.js +0 -7
  61. package/src/__compatibility__/pg-interface.spec.ts +0 -495
  62. package/src/constants.ts +0 -11
  63. package/src/index.spec.ts +0 -14
  64. package/src/index.test.ts +0 -59
  65. package/src/index.ts +0 -130
  66. package/src/oxlint.spec.ts +0 -70
  67. package/src/oxlint.ts +0 -23
  68. package/src/rules/check-query-params/check-query-params.test.ts +0 -68
  69. package/src/rules/check-query-params/index.spec.ts +0 -117
  70. package/src/rules/check-query-params/index.ts +0 -106
  71. package/src/rules/no-batch-insert-loop/index.spec.ts +0 -105
  72. package/src/rules/no-batch-insert-loop/index.ts +0 -105
  73. package/src/rules/no-batch-insert-loop/no-batch-insert-loop.test.ts +0 -68
  74. package/src/rules/no-floating-query/index.spec.ts +0 -112
  75. package/src/rules/no-floating-query/index.ts +0 -81
  76. package/src/rules/no-floating-query/no-floating-query.test.ts +0 -68
  77. package/src/rules/no-hardcoded-credentials/index.spec.ts +0 -38
  78. package/src/rules/no-hardcoded-credentials/index.ts +0 -93
  79. package/src/rules/no-hardcoded-credentials/no-hardcoded-credentials.test.ts +0 -68
  80. package/src/rules/no-insecure-ssl/index.spec.ts +0 -40
  81. package/src/rules/no-insecure-ssl/index.ts +0 -81
  82. package/src/rules/no-insecure-ssl/no-insecure-ssl.test.ts +0 -68
  83. package/src/rules/no-missing-client-release/coverage-gaps.spec.ts +0 -42
  84. package/src/rules/no-missing-client-release/index.spec.ts +0 -52
  85. package/src/rules/no-missing-client-release/index.ts +0 -100
  86. package/src/rules/no-missing-client-release/no-missing-client-release.test.ts +0 -68
  87. package/src/rules/no-select-all/index.spec.ts +0 -44
  88. package/src/rules/no-select-all/index.ts +0 -92
  89. package/src/rules/no-select-all/no-select-all.test.ts +0 -68
  90. package/src/rules/no-transaction-on-pool/index.spec.ts +0 -36
  91. package/src/rules/no-transaction-on-pool/index.ts +0 -85
  92. package/src/rules/no-transaction-on-pool/no-transaction-on-pool.test.ts +0 -68
  93. package/src/rules/no-unsafe-copy-from/coverage-gaps.spec.ts +0 -76
  94. package/src/rules/no-unsafe-copy-from/index.spec.ts +0 -274
  95. package/src/rules/no-unsafe-copy-from/index.ts +0 -226
  96. package/src/rules/no-unsafe-copy-from/no-unsafe-copy-from.test.ts +0 -78
  97. package/src/rules/no-unsafe-query/coverage-gaps.spec.ts +0 -61
  98. package/src/rules/no-unsafe-query/index.spec.ts +0 -103
  99. package/src/rules/no-unsafe-query/index.ts +0 -149
  100. package/src/rules/no-unsafe-query/no-unsafe-query.test.ts +0 -73
  101. package/src/rules/no-unsafe-search-path/index.spec.ts +0 -46
  102. package/src/rules/no-unsafe-search-path/index.ts +0 -164
  103. package/src/rules/no-unsafe-search-path/no-unsafe-search-path.test.ts +0 -68
  104. package/src/rules/prefer-pool-query/coverage-gaps.spec.ts +0 -76
  105. package/src/rules/prefer-pool-query/index.spec.ts +0 -97
  106. package/src/rules/prefer-pool-query/index.ts +0 -118
  107. package/src/rules/prefer-pool-query/prefer-pool-query.test.ts +0 -68
  108. package/src/rules/prevent-double-release/coverage-gaps.spec.ts +0 -538
  109. package/src/rules/prevent-double-release/index.spec.ts +0 -824
  110. package/src/rules/prevent-double-release/index.ts +0 -534
  111. package/src/rules/prevent-double-release/prevent-double-release.test.ts +0 -70
  112. package/src/types/index.ts +0 -58
  113. /package/{dist/src → src}/types/index.d.ts +0 -0
@@ -1,144 +0,0 @@
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.noUnsafeSearchPath = void 0;
9
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
- // Pre-compiled pattern check for search_path
11
- const hasSearchPath = (str) => str.toLowerCase().includes('set search_path');
12
- exports.noUnsafeSearchPath = {
13
- meta: {
14
- type: 'problem',
15
- docs: {
16
- description: 'Prevent unsafe SET search_path usage with dynamic values, which can lead to schema hijacking.',
17
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/no-unsafe-search-path.md',
18
- cwe: 'CWE-426',
19
- cvss: 7.5,
20
- },
21
- messages: {
22
- noUnsafeSearchPath: (0, eslint_devkit_1.formatLLMMessage)({
23
- icon: eslint_devkit_1.MessageIcons.SECURITY,
24
- issueName: 'Schema Hijacking Risk',
25
- description: 'Unsafe "SET search_path" detected.',
26
- severity: 'CRITICAL',
27
- cwe: 'CWE-426',
28
- owasp: 'A05:2021',
29
- compliance: ['SOC2', 'PCI-DSS'],
30
- effort: 'low',
31
- fix: 'Do not use dynamic values for search_path. Use static strings or strict validation.',
32
- documentationLink: 'https://www.postgresql.org/docs/current/ddl-schemas.html#DDL-SCHEMAS-PATH',
33
- }),
34
- },
35
- schema: [],
36
- },
37
- defaultOptions: [],
38
- create(context) {
39
- return {
40
- CallExpression(node) {
41
- if (node.callee.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression ||
42
- node.callee.property.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier ||
43
- node.callee.property.name !== 'query') {
44
- return;
45
- }
46
- const args = node.arguments;
47
- if (args.length === 0)
48
- return;
49
- const queryArg = args[0];
50
- // 1. Literal Check: "SET search_path = " + variable
51
- if (queryArg.type === eslint_devkit_1.AST_NODE_TYPES.BinaryExpression && queryArg.operator === '+') {
52
- // We need to check if the left or right side contains "SET search_path"
53
- // This requires a bit of deep traversal if it's a chain, but let's check simple cases first.
54
- // Or, we can just check if *any* part of the expression is a string literal containing "SET search_path"
55
- // A simpler approach for BinaryExpression:
56
- // If it isn't a Literal, it's dynamic. If we can prove it contains "SET search_path", flag it.
57
- // But statically analyzing the concatenated string is hard.
58
- // However, we ALREADY forbid string concatenation in queries via `no-unsafe-query`.
59
- // So this rule specifically should target WHERE `no-unsafe-query` might miss (e.g. valid syntax but unsafe LOGIC),
60
- // OR reinforce it.
61
- // Actually `no-unsafe-query` blocks `query('SET search_path = ' + val)`.
62
- // But what about `query('SET search_path = $1', [val])`?
63
- // PostgreSQL DOES NOT allow parameters for `SET search_path`. It must be a literal identifier.
64
- // usages like `SET search_path TO $1` throw syntax error in PG.
65
- // So users MUST use string interpolation or literal.
66
- // `no-unsafe-query` will block the string interpolation/concatenation.
67
- // So the only "safe" way usually is `query('SET search_path = public')`.
68
- // Wait, if `no-unsafe-query` blocks all dynamic queries, then `no-unsafe-search-path` is redundant?
69
- // Not quite. `no-unsafe-query` allows template literals without expressions.
70
- // It blocks concatenation.
71
- // But sometimes people disable `no-unsafe-query` or use helpers.
72
- // Also, `pg-format` usage: `format('SET search_path = %I', val)`.
73
- // This IS safe from SQLi in general, but for `search_path`, allows changing to ARBITRARY schema.
74
- // If attacker controls `val`, they can point to `hack_public` schema.
75
- // So we want to ensure `search_path` is HARDCODED or strictly validated.
76
- // Let's detect `SET search_path` in any string literal part of the arg.
77
- // If we find it, and the argument is NOT a pure String Literal (i.e. it involves vars/functions), WARN.
78
- }
79
- if (queryArg.type === eslint_devkit_1.AST_NODE_TYPES.Literal) {
80
- if (typeof queryArg.value === 'string' && hasSearchPath(queryArg.value)) {
81
- // Safe: Literal string "SET search_path = public"
82
- return;
83
- }
84
- }
85
- // If it's a TemplateLiteral
86
- if (queryArg.type === eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral) {
87
- // Check quasis
88
- const rawText = queryArg.quasis.map(q => q.value.raw).join(' ');
89
- if (hasSearchPath(rawText)) {
90
- if (queryArg.expressions.length > 0) {
91
- context.report({
92
- node: queryArg,
93
- messageId: 'noUnsafeSearchPath',
94
- });
95
- }
96
- }
97
- return;
98
- }
99
- // If it's a BinaryExpression (concat)
100
- if (queryArg.type === eslint_devkit_1.AST_NODE_TYPES.BinaryExpression) {
101
- // We can't easily reconstruction the full string.
102
- // But if we detect "search_path" in any literal part, and it's being concatenated, flag it.
103
- // This is a simplified visitor for the binary expression tree
104
- const parts = [];
105
- const stack = [queryArg];
106
- for (let curr = stack.pop(); curr !== undefined; curr = stack.pop()) {
107
- if (curr.type === eslint_devkit_1.AST_NODE_TYPES.BinaryExpression && curr.operator === '+') {
108
- stack.push(curr.right);
109
- stack.push(curr.left);
110
- }
111
- else if (curr.type === eslint_devkit_1.AST_NODE_TYPES.Literal && typeof curr.value === 'string') {
112
- parts.push(curr.value);
113
- }
114
- }
115
- const combined = parts.join(' ');
116
- if (hasSearchPath(combined)) {
117
- context.report({
118
- node: queryArg,
119
- messageId: 'noUnsafeSearchPath',
120
- });
121
- }
122
- return;
123
- }
124
- // CallExpression (e.g. pg-format)
125
- // format('SET search_path = %I', schema) -> This is arguably unsafe if schema is user-controlled.
126
- if (queryArg.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression) {
127
- if (queryArg.arguments.length > 0 &&
128
- queryArg.arguments[0].type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
129
- typeof queryArg.arguments[0].value === 'string' &&
130
- hasSearchPath(queryArg.arguments[0].value)) {
131
- // Fix: If all arguments are Literals, assume it is safe.
132
- const allLiterals = queryArg.arguments.every(arg => arg.type === eslint_devkit_1.AST_NODE_TYPES.Literal);
133
- if (allLiterals)
134
- return;
135
- context.report({
136
- node: queryArg,
137
- messageId: 'noUnsafeSearchPath',
138
- });
139
- }
140
- }
141
- },
142
- };
143
- },
144
- };
@@ -1,8 +0,0 @@
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
- import { TSESLint } from '@interlace/eslint-devkit';
7
- import { PreferPoolQueryOptions } from '../../types';
8
- export declare const preferPoolQuery: TSESLint.RuleModule<'preferPoolQuery', PreferPoolQueryOptions>;
@@ -1,104 +0,0 @@
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.preferPoolQuery = void 0;
9
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
- exports.preferPoolQuery = {
11
- meta: {
12
- type: 'suggestion',
13
- docs: {
14
- description: 'Prefer pool.query() over client.query() for single-shot queries.',
15
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/prefer-pool-query.md',
16
- },
17
- messages: {
18
- preferPoolQuery: (0, eslint_devkit_1.formatLLMMessage)({
19
- icon: eslint_devkit_1.MessageIcons.PERFORMANCE,
20
- issueName: 'Prefer Pool Query',
21
- description: 'Single-shot queries should use pool.query() directly.',
22
- severity: 'MEDIUM',
23
- cwe: 'CWE-400',
24
- effort: 'low',
25
- fix: 'Use pool.query(...) instead of manual client checkout/release for simple queries.',
26
- documentationLink: 'https://node-postgres.com/features/pooling',
27
- }),
28
- },
29
- schema: [],
30
- },
31
- defaultOptions: [],
32
- create(context) {
33
- return {
34
- VariableDeclarator(node) {
35
- // Look for: const client = await pool.connect()
36
- // And ensure it is used for exactly one query, then released.
37
- // This is complex for a perfect check, but we can look for basic patterns.
38
- if (!node.init ||
39
- node.init.type !== eslint_devkit_1.AST_NODE_TYPES.AwaitExpression ||
40
- node.init.argument.type !== eslint_devkit_1.AST_NODE_TYPES.CallExpression ||
41
- node.init.argument.callee.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression ||
42
- node.init.argument.callee.property.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier ||
43
- node.init.argument.callee.property.name !== 'connect') {
44
- return;
45
- }
46
- const variable = context.sourceCode.getDeclaredVariables(node)[0];
47
- if (!variable)
48
- return;
49
- const references = variable.references;
50
- // Count meaningful usages
51
- // 1. Definition (init)
52
- // 2. usage in query
53
- // 3. usage in release
54
- // roughly 3 refs total? (maybe 2 if release is forgot, but that is handled by other rule)
55
- // If we have just: connect, query, release.
56
- // And NO transactions (BEGIN/COMMIT).
57
- let queryCallCount = 0;
58
- let releaseCallCount = 0;
59
- let otherUsageCount = 0;
60
- for (const ref of references) {
61
- if (ref.isWrite())
62
- continue; // definition
63
- const id = ref.identifier;
64
- // Check for member access
65
- if (id.parent?.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
66
- id.parent.object === id &&
67
- id.parent.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
68
- const method = id.parent.property.name;
69
- if (method === 'query') {
70
- queryCallCount++;
71
- // Check if it is a transaction command
72
- if (id.parent.parent?.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression) {
73
- const call = id.parent.parent;
74
- if (call.arguments.length > 0 &&
75
- call.arguments[0].type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
76
- typeof call.arguments[0].value === 'string') {
77
- const q = call.arguments[0].value.toUpperCase().trim();
78
- if (q.startsWith('BEGIN') || q.startsWith('COMMIT') || q.startsWith('ROLLBACK')) {
79
- return; // It's a transaction, keep manual control
80
- }
81
- }
82
- }
83
- }
84
- else if (method === 'release') {
85
- releaseCallCount++;
86
- }
87
- else {
88
- otherUsageCount++;
89
- }
90
- }
91
- else {
92
- otherUsageCount++; // usage as value (passing to func?)
93
- }
94
- }
95
- if (queryCallCount === 1 && releaseCallCount === 1 && otherUsageCount === 0) {
96
- context.report({
97
- node,
98
- messageId: 'preferPoolQuery',
99
- });
100
- }
101
- },
102
- };
103
- },
104
- };
@@ -1,8 +0,0 @@
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
- import { TSESLint } from '@interlace/eslint-devkit';
7
- import { PreventDoubleReleaseOptions } from '../../types';
8
- export declare const preventDoubleRelease: TSESLint.RuleModule<'doubleRelease' | 'doubleReleaseCallback', PreventDoubleReleaseOptions>;