eslint-plugin-postgresql-security 1.5.1 → 1.5.3

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.
@@ -1,66 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noSelectAll = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const COUNT_STAR_REGEX = /COUNT\s*\(\s*\*\s*\)/g;
6
- const SELECT_STAR_REGEX = /\bSELECT\s+\*/;
7
- const COMMA_STAR_REGEX = /,\s*\*/;
8
- const SELECT_KEYWORD_REGEX = /\bSELECT\b/;
9
- const UNNEST_PATTERN_REGEX = /\bSELECT\s+\*\s+FROM\s+UNNEST\s*\(/;
10
- exports.noSelectAll = {
11
- meta: {
12
- type: 'problem',
13
- docs: {
14
- description: 'Prevent using * in SELECT statements (implicit columns).',
15
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/no-select-all.md',
16
- cwe: 'CWE-1049',
17
- cvss: 5,
18
- },
19
- messages: {
20
- noSelectAll: (0, eslint_devkit_1.formatLLMMessage)({
21
- icon: eslint_devkit_1.MessageIcons.PERFORMANCE,
22
- issueName: 'Select All',
23
- description: 'Avoid using "SELECT *" which fetches all columns.',
24
- severity: 'MEDIUM',
25
- cwe: 'CWE-1049',
26
- effort: 'low',
27
- fix: 'Explicitly list the columns you need (e.g., SELECT id, name FROM ...).',
28
- documentationLink: 'https://wiki.postgresql.org/wiki/Don%27t_Do_This#Don.27t_use_SELECT_.2A',
29
- }),
30
- },
31
- schema: [],
32
- },
33
- defaultOptions: [],
34
- create(context) {
35
- return {
36
- CallExpression(node) {
37
- if (node.callee.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression ||
38
- node.callee.property.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier ||
39
- node.callee.property.name !== 'query') {
40
- return;
41
- }
42
- const args = node.arguments;
43
- if (args.length === 0)
44
- return;
45
- const queryArg = args[0];
46
- if (queryArg.type !== eslint_devkit_1.AST_NODE_TYPES.Literal || typeof queryArg.value !== 'string') {
47
- return;
48
- }
49
- const queryText = queryArg.value;
50
- const upperQuery = queryText.toUpperCase();
51
- const cleanedQuery = upperQuery.replace(COUNT_STAR_REGEX, 'COUNT_ALL');
52
- if (SELECT_STAR_REGEX.test(cleanedQuery) || COMMA_STAR_REGEX.test(cleanedQuery)) {
53
- if (SELECT_KEYWORD_REGEX.test(cleanedQuery)) {
54
- if (UNNEST_PATTERN_REGEX.test(cleanedQuery)) {
55
- return;
56
- }
57
- context.report({
58
- node: queryArg,
59
- messageId: 'noSelectAll',
60
- });
61
- }
62
- }
63
- },
64
- };
65
- },
66
- };
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noSelectAll=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const COUNT_STAR_REGEX=/COUNT\s*\(\s*\*\s*\)/g;const SELECT_STAR_REGEX=/\bSELECT\s+\*/;const COMMA_STAR_REGEX=/,\s*\*/;const SELECT_KEYWORD_REGEX=/\bSELECT\b/;const UNNEST_PATTERN_REGEX=/\bSELECT\s+\*\s+FROM\s+UNNEST\s*\(/;exports.noSelectAll={meta:{type:"problem",docs:{description:"Prevent using * in SELECT statements (implicit columns).",url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/no-select-all.md",cwe:"CWE-1049",cvss:5},messages:{noSelectAll:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.PERFORMANCE,issueName:"Select All",description:'Avoid using "SELECT *" which fetches all columns.',severity:"MEDIUM",cwe:"CWE-1049",effort:"low",fix:"Explicitly list the columns you need (e.g., SELECT id, name FROM ...).",documentationLink:"https://wiki.postgresql.org/wiki/Don%27t_Do_This#Don.27t_use_SELECT_.2A"})},schema:[]},defaultOptions:[],create(context){return{CallExpression(node){if(node.callee.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression||node.callee.property.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||node.callee.property.name!=="query"){return}const args=node.arguments;if(args.length===0)return;const queryArg=args[0];if(queryArg.type!==eslint_devkit_1.AST_NODE_TYPES.Literal||typeof queryArg.value!=="string"){return}const queryText=queryArg.value;const upperQuery=queryText.toUpperCase();const cleanedQuery=upperQuery.replace(COUNT_STAR_REGEX,"COUNT_ALL");if(SELECT_STAR_REGEX.test(cleanedQuery)||COMMA_STAR_REGEX.test(cleanedQuery)){if(SELECT_KEYWORD_REGEX.test(cleanedQuery)){if(UNNEST_PATTERN_REGEX.test(cleanedQuery)){return}context.report({node:queryArg,messageId:"noSelectAll"})}}}}}};
@@ -1,59 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noTransactionOnPool = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const TRANSACTION_KEYWORDS = new Set(['BEGIN', 'COMMIT', 'ROLLBACK']);
6
- exports.noTransactionOnPool = {
7
- meta: {
8
- type: 'problem',
9
- docs: {
10
- description: 'Prevent starting transactions directly on the Pool, which is unsafe due to lack of client affinity.',
11
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/no-transaction-on-pool.md',
12
- cwe: 'CWE-662',
13
- cweJustification: 'CWE-662 (Improper Synchronization) — running BEGIN/COMMIT on a connection pool can split a logical transaction across different physical clients, breaking ACID atomicity.',
14
- confidence: 'high',
15
- },
16
- messages: {
17
- noTransactionOnPool: (0, eslint_devkit_1.formatLLMMessage)({
18
- icon: eslint_devkit_1.MessageIcons.WARNING,
19
- issueName: 'Transaction on Pool',
20
- description: 'Transactions should not be started on the Pool directly.',
21
- severity: 'HIGH',
22
- effort: 'low',
23
- fix: 'Use "await pool.connect()" to get a client, then start the transaction on the client.',
24
- documentationLink: 'https://node-postgres.com/features/transactions',
25
- }),
26
- },
27
- schema: [],
28
- },
29
- defaultOptions: [],
30
- create(context) {
31
- return {
32
- CallExpression(node) {
33
- if (node.callee.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression ||
34
- node.callee.property.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier ||
35
- node.callee.property.name !== 'query') {
36
- return;
37
- }
38
- const args = node.arguments;
39
- if (args.length === 0)
40
- return;
41
- const queryArg = args[0];
42
- if (queryArg.type !== eslint_devkit_1.AST_NODE_TYPES.Literal || typeof queryArg.value !== 'string') {
43
- return;
44
- }
45
- const queryText = queryArg.value.toUpperCase().trim();
46
- const firstWord = queryText.split(/[;\s]/)[0];
47
- if (TRANSACTION_KEYWORDS.has(firstWord)) {
48
- if (node.callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
49
- (node.callee.object.name === 'pool' || node.callee.object.name.toLowerCase().includes('pool'))) {
50
- context.report({
51
- node: queryArg,
52
- messageId: 'noTransactionOnPool',
53
- });
54
- }
55
- }
56
- },
57
- };
58
- },
59
- };
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noTransactionOnPool=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const TRANSACTION_KEYWORDS=new Set(["BEGIN","COMMIT","ROLLBACK"]);exports.noTransactionOnPool={meta:{type:"problem",docs:{description:"Prevent starting transactions directly on the Pool, which is unsafe due to lack of client affinity.",url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/no-transaction-on-pool.md",cwe:"CWE-662",cweJustification:"CWE-662 (Improper Synchronization) \u2014 running BEGIN/COMMIT on a connection pool can split a logical transaction across different physical clients, breaking ACID atomicity.",confidence:"high"},messages:{noTransactionOnPool:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"Transaction on Pool",description:"Transactions should not be started on the Pool directly.",severity:"HIGH",effort:"low",fix:'Use "await pool.connect()" to get a client, then start the transaction on the client.',documentationLink:"https://node-postgres.com/features/transactions"})},schema:[]},defaultOptions:[],create(context){return{CallExpression(node){if(node.callee.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression||node.callee.property.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||node.callee.property.name!=="query"){return}const args=node.arguments;if(args.length===0)return;const queryArg=args[0];if(queryArg.type!==eslint_devkit_1.AST_NODE_TYPES.Literal||typeof queryArg.value!=="string"){return}const queryText=queryArg.value.toUpperCase().trim();const firstWord=queryText.split(/[;\s]/)[0];if(TRANSACTION_KEYWORDS.has(firstWord)){if(node.callee.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&(node.callee.object.name==="pool"||node.callee.object.name.toLowerCase().includes("pool"))){context.report({node:queryArg,messageId:"noTransactionOnPool"})}}}}}};
@@ -1,179 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noUnsafeCopyFrom = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const COPY_FROM_REGEX = /\bCOPY\b.*\bFROM\b/i;
6
- const STDIN_REGEX = /\bFROM\s+STDIN\b/i;
7
- const FILE_PATH_REGEX = /FROM\s+['"]([^'"]+)['"]/i;
8
- const hasCopyFrom = (str) => COPY_FROM_REGEX.test(str) && !STDIN_REGEX.test(str);
9
- const extractFilePath = (str) => {
10
- const match = FILE_PATH_REGEX.exec(str);
11
- return match ? match[1] : null;
12
- };
13
- exports.noUnsafeCopyFrom = {
14
- meta: {
15
- type: 'problem',
16
- docs: {
17
- description: 'Prevent unsafe COPY FROM usage with dynamic file paths, which can lead to arbitrary file read/RCE.',
18
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/no-unsafe-copy-from.md',
19
- cwe: 'CWE-73',
20
- cvss: 9.5,
21
- },
22
- messages: {
23
- dynamicPath: (0, eslint_devkit_1.formatLLMMessage)({
24
- icon: eslint_devkit_1.MessageIcons.SECURITY,
25
- issueName: 'COPY FROM Injection',
26
- description: 'Dynamic file path in COPY FROM detected - potential arbitrary file read.',
27
- severity: 'CRITICAL',
28
- cwe: 'CWE-73',
29
- owasp: 'A03:2021',
30
- compliance: ['SOC2', 'PCI-DSS'],
31
- effort: 'low',
32
- fix: 'Never use user input in COPY FROM paths. Use COPY FROM STDIN for user data.',
33
- documentationLink: 'https://www.postgresql.org/docs/current/sql-copy.html',
34
- }),
35
- hardcodedPath: (0, eslint_devkit_1.formatLLMMessage)({
36
- icon: eslint_devkit_1.MessageIcons.WARNING,
37
- issueName: 'Server-side COPY FROM',
38
- description: 'Hardcoded file path in COPY FROM - server-side file access.',
39
- severity: 'MEDIUM',
40
- cwe: 'CWE-73',
41
- effort: 'low',
42
- fix: 'Prefer COPY FROM STDIN for application code. Use allowHardcodedPaths option if this is an admin script.',
43
- documentationLink: 'https://www.postgresql.org/docs/current/sql-copy.html',
44
- }),
45
- unverifiablePath: (0, eslint_devkit_1.formatLLMMessage)({
46
- icon: eslint_devkit_1.MessageIcons.WARNING,
47
- issueName: 'Unverifiable COPY FROM',
48
- description: 'Cannot statically verify COPY FROM source - potential injection risk.',
49
- severity: 'MEDIUM',
50
- cwe: 'CWE-73',
51
- effort: 'medium',
52
- fix: 'Ensure the query source does not contain user input, or refactor to use COPY FROM STDIN.',
53
- documentationLink: 'https://www.postgresql.org/docs/current/sql-copy.html',
54
- }),
55
- },
56
- schema: [
57
- {
58
- type: 'object',
59
- properties: {
60
- allowHardcodedPaths: {
61
- type: 'boolean',
62
- description: 'Allow hardcoded file paths (for admin/migration scripts)',
63
- },
64
- allowedPaths: {
65
- type: 'array',
66
- items: { type: 'string' },
67
- description: 'List of allowed file path patterns (regex strings)',
68
- },
69
- },
70
- additionalProperties: false,
71
- },
72
- ],
73
- },
74
- defaultOptions: [{}],
75
- create(context) {
76
- const options = context.options[0] ?? {};
77
- const allowHardcodedPaths = options.allowHardcodedPaths ?? false;
78
- const allowedPaths = (options.allowedPaths ?? []).map((p) => new RegExp(p));
79
- const isPathAllowed = (filePath) => {
80
- return allowedPaths.some((pattern) => pattern.test(filePath));
81
- };
82
- return {
83
- CallExpression(node) {
84
- if (node.callee.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression ||
85
- node.callee.property.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier ||
86
- node.callee.property.name !== 'query') {
87
- return;
88
- }
89
- const args = node.arguments;
90
- if (args.length === 0)
91
- return;
92
- const queryArg = args[0];
93
- if (queryArg.type === eslint_devkit_1.AST_NODE_TYPES.Literal && typeof queryArg.value === 'string') {
94
- if (hasCopyFrom(queryArg.value)) {
95
- const filePath = extractFilePath(queryArg.value);
96
- if (filePath && isPathAllowed(filePath)) {
97
- return;
98
- }
99
- if (allowHardcodedPaths) {
100
- return;
101
- }
102
- context.report({
103
- node: queryArg,
104
- messageId: 'hardcodedPath',
105
- });
106
- }
107
- return;
108
- }
109
- if (queryArg.type === eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral) {
110
- const staticText = queryArg.quasis.map(q => q.value.raw).join(' ');
111
- if (hasCopyFrom(staticText)) {
112
- if (queryArg.expressions.length > 0) {
113
- context.report({
114
- node: queryArg,
115
- messageId: 'dynamicPath',
116
- });
117
- }
118
- else {
119
- const filePath = extractFilePath(staticText);
120
- if (filePath && isPathAllowed(filePath)) {
121
- return;
122
- }
123
- if (!allowHardcodedPaths) {
124
- context.report({
125
- node: queryArg,
126
- messageId: 'hardcodedPath',
127
- });
128
- }
129
- }
130
- }
131
- return;
132
- }
133
- if (queryArg.type === eslint_devkit_1.AST_NODE_TYPES.BinaryExpression) {
134
- const parts = [];
135
- let hasDynamicPart = false;
136
- const stack = [queryArg];
137
- for (let curr = stack.pop(); curr !== undefined; curr = stack.pop()) {
138
- if (curr.type === eslint_devkit_1.AST_NODE_TYPES.BinaryExpression && curr.operator === '+') {
139
- stack.push(curr.right);
140
- stack.push(curr.left);
141
- }
142
- else if (curr.type === eslint_devkit_1.AST_NODE_TYPES.Literal && typeof curr.value === 'string') {
143
- parts.push(curr.value);
144
- }
145
- else {
146
- hasDynamicPart = true;
147
- }
148
- }
149
- const staticText = parts.join(' ');
150
- if (hasCopyFrom(staticText)) {
151
- if (hasDynamicPart) {
152
- context.report({
153
- node: queryArg,
154
- messageId: 'dynamicPath',
155
- });
156
- }
157
- else {
158
- const filePath = extractFilePath(staticText);
159
- if (filePath && isPathAllowed(filePath)) {
160
- return;
161
- }
162
- if (!allowHardcodedPaths) {
163
- context.report({
164
- node: queryArg,
165
- messageId: 'hardcodedPath',
166
- });
167
- }
168
- }
169
- }
170
- return;
171
- }
172
- if (queryArg.type === eslint_devkit_1.AST_NODE_TYPES.Identifier ||
173
- queryArg.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression) {
174
- return;
175
- }
176
- },
177
- };
178
- },
179
- };
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noUnsafeCopyFrom=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const COPY_FROM_REGEX=/\bCOPY\b.*\bFROM\b/i;const STDIN_REGEX=/\bFROM\s+STDIN\b/i;const FILE_PATH_REGEX=/FROM\s+['"]([^'"]+)['"]/i;const hasCopyFrom=str=>COPY_FROM_REGEX.test(str)&&!STDIN_REGEX.test(str);const extractFilePath=str=>{const match=FILE_PATH_REGEX.exec(str);return match?match[1]:null};exports.noUnsafeCopyFrom={meta:{type:"problem",docs:{description:"Prevent unsafe COPY FROM usage with dynamic file paths, which can lead to arbitrary file read/RCE.",url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/no-unsafe-copy-from.md",cwe:"CWE-73",cvss:9.5},messages:{dynamicPath:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"COPY FROM Injection",description:"Dynamic file path in COPY FROM detected - potential arbitrary file read.",severity:"CRITICAL",cwe:"CWE-73",owasp:"A03:2021",compliance:["SOC2","PCI-DSS"],effort:"low",fix:"Never use user input in COPY FROM paths. Use COPY FROM STDIN for user data.",documentationLink:"https://www.postgresql.org/docs/current/sql-copy.html"}),hardcodedPath:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"Server-side COPY FROM",description:"Hardcoded file path in COPY FROM - server-side file access.",severity:"MEDIUM",cwe:"CWE-73",effort:"low",fix:"Prefer COPY FROM STDIN for application code. Use allowHardcodedPaths option if this is an admin script.",documentationLink:"https://www.postgresql.org/docs/current/sql-copy.html"}),unverifiablePath:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"Unverifiable COPY FROM",description:"Cannot statically verify COPY FROM source - potential injection risk.",severity:"MEDIUM",cwe:"CWE-73",effort:"medium",fix:"Ensure the query source does not contain user input, or refactor to use COPY FROM STDIN.",documentationLink:"https://www.postgresql.org/docs/current/sql-copy.html"})},schema:[{type:"object",properties:{allowHardcodedPaths:{type:"boolean",description:"Allow hardcoded file paths (for admin/migration scripts)"},allowedPaths:{type:"array",items:{type:"string"},description:"List of allowed file path patterns (regex strings)"}},additionalProperties:false}]},defaultOptions:[{}],create(context){const options=context.options[0]??{};const allowHardcodedPaths=options.allowHardcodedPaths??false;const allowedPaths=(options.allowedPaths??[]).map(p=>new RegExp(p));const isPathAllowed=filePath=>{return allowedPaths.some(pattern=>pattern.test(filePath))};return{CallExpression(node){if(node.callee.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression||node.callee.property.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||node.callee.property.name!=="query"){return}const args=node.arguments;if(args.length===0)return;const queryArg=args[0];if(queryArg.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof queryArg.value==="string"){if(hasCopyFrom(queryArg.value)){const filePath=extractFilePath(queryArg.value);if(filePath&&isPathAllowed(filePath)){return}if(allowHardcodedPaths){return}context.report({node:queryArg,messageId:"hardcodedPath"})}return}if(queryArg.type===eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral){const staticText=queryArg.quasis.map(q=>q.value.raw).join(" ");if(hasCopyFrom(staticText)){if(queryArg.expressions.length>0){context.report({node:queryArg,messageId:"dynamicPath"})}else{const filePath=extractFilePath(staticText);if(filePath&&isPathAllowed(filePath)){return}if(!allowHardcodedPaths){context.report({node:queryArg,messageId:"hardcodedPath"})}}}return}if(queryArg.type===eslint_devkit_1.AST_NODE_TYPES.BinaryExpression){const parts=[];let hasDynamicPart=false;const stack=[queryArg];for(let curr=stack.pop();curr!==void 0;curr=stack.pop()){if(curr.type===eslint_devkit_1.AST_NODE_TYPES.BinaryExpression&&curr.operator==="+"){stack.push(curr.right);stack.push(curr.left)}else if(curr.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof curr.value==="string"){parts.push(curr.value)}else{hasDynamicPart=true}}const staticText=parts.join(" ");if(hasCopyFrom(staticText)){if(hasDynamicPart){context.report({node:queryArg,messageId:"dynamicPath"})}else{const filePath=extractFilePath(staticText);if(filePath&&isPathAllowed(filePath)){return}if(!allowHardcodedPaths){context.report({node:queryArg,messageId:"hardcodedPath"})}}}return}if(queryArg.type===eslint_devkit_1.AST_NODE_TYPES.Identifier||queryArg.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression){return}}}}};
@@ -1,106 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noUnsafeQuery = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- function isUnsafeStringConstruction(node) {
6
- if (node.type === eslint_devkit_1.AST_NODE_TYPES.BinaryExpression && node.operator === '+') {
7
- return 'concat';
8
- }
9
- if (node.type === eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral && node.expressions.length > 0) {
10
- return 'template';
11
- }
12
- return false;
13
- }
14
- exports.noUnsafeQuery = {
15
- meta: {
16
- type: 'problem',
17
- docs: {
18
- description: 'Prevent SQL injection by disallowing string concatenation or unsafe template literals in queries.',
19
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/no-unsafe-query.md',
20
- cwe: 'CWE-89',
21
- cvss: 9.8,
22
- confidence: 'high',
23
- },
24
- messages: {
25
- noUnsafeQuery: (0, eslint_devkit_1.formatLLMMessage)({
26
- icon: eslint_devkit_1.MessageIcons.SECURITY,
27
- issueName: 'SQL Injection Risk',
28
- description: 'Unsafe SQL query detected. Variable interpolation found.',
29
- severity: 'CRITICAL',
30
- cwe: 'CWE-89',
31
- owasp: 'A03:2021',
32
- compliance: ['SOC2', 'PCI-DSS', 'NIST-CSF'],
33
- effort: 'high',
34
- fix: 'Use parameterized queries ($1, $2) instead of string concatenation.',
35
- documentationLink: 'https://node-postgres.com/features/queries#parameterized-queries',
36
- }),
37
- unsafeTemplateLiteral: (0, eslint_devkit_1.formatLLMMessage)({
38
- icon: eslint_devkit_1.MessageIcons.SECURITY,
39
- issueName: 'SQL Injection Risk',
40
- description: 'Unsafe SQL query construction detected (template literal).',
41
- severity: 'CRITICAL',
42
- fix: 'Use parameterized queries ($1, $2) instead of interpolating values.',
43
- documentationLink: 'https://owasp.org/www-community/attacks/SQL_Injection',
44
- }),
45
- },
46
- schema: [],
47
- },
48
- defaultOptions: [],
49
- create(context) {
50
- const taintedVariables = new Map();
51
- return {
52
- VariableDeclarator(node) {
53
- if (node.id.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
54
- node.init) {
55
- const unsafe = isUnsafeStringConstruction(node.init);
56
- if (unsafe) {
57
- taintedVariables.set(node.id.name, unsafe);
58
- }
59
- }
60
- },
61
- AssignmentExpression(node) {
62
- if (node.operator === '+=' &&
63
- node.left.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
64
- const unsafe = isUnsafeStringConstruction(node.right);
65
- if (unsafe) {
66
- taintedVariables.set(node.left.name, unsafe);
67
- }
68
- }
69
- },
70
- CallExpression(node) {
71
- if (node.callee.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression ||
72
- node.callee.property.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier ||
73
- node.callee.property.name !== 'query') {
74
- return;
75
- }
76
- const args = node.arguments;
77
- if (args.length === 0)
78
- return;
79
- const queryArg = args[0];
80
- if (queryArg.type === eslint_devkit_1.AST_NODE_TYPES.BinaryExpression && queryArg.operator === '+') {
81
- context.report({
82
- node: queryArg,
83
- messageId: 'noUnsafeQuery',
84
- });
85
- return;
86
- }
87
- if (queryArg.type === eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral && queryArg.expressions.length > 0) {
88
- context.report({
89
- node: queryArg,
90
- messageId: 'unsafeTemplateLiteral',
91
- });
92
- return;
93
- }
94
- if (queryArg.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
95
- const taint = taintedVariables.get(queryArg.name);
96
- if (taint) {
97
- context.report({
98
- node: queryArg,
99
- messageId: taint === 'template' ? 'unsafeTemplateLiteral' : 'noUnsafeQuery',
100
- });
101
- }
102
- }
103
- },
104
- };
105
- },
106
- };
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noUnsafeQuery=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");function isUnsafeStringConstruction(node){if(node.type===eslint_devkit_1.AST_NODE_TYPES.BinaryExpression&&node.operator==="+"){return"concat"}if(node.type===eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral&&node.expressions.length>0){return"template"}return false}exports.noUnsafeQuery={meta:{type:"problem",docs:{description:"Prevent SQL injection by disallowing string concatenation or unsafe template literals in queries.",url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/no-unsafe-query.md",cwe:"CWE-89",cvss:9.8,confidence:"high"},messages:{noUnsafeQuery:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"SQL Injection Risk",description:"Unsafe SQL query detected. Variable interpolation found.",severity:"CRITICAL",cwe:"CWE-89",owasp:"A03:2021",compliance:["SOC2","PCI-DSS","NIST-CSF"],effort:"high",fix:"Use parameterized queries ($1, $2) instead of string concatenation.",documentationLink:"https://node-postgres.com/features/queries#parameterized-queries"}),unsafeTemplateLiteral:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"SQL Injection Risk",description:"Unsafe SQL query construction detected (template literal).",severity:"CRITICAL",fix:"Use parameterized queries ($1, $2) instead of interpolating values.",documentationLink:"https://owasp.org/www-community/attacks/SQL_Injection"})},schema:[]},defaultOptions:[],create(context){const taintedVariables=new Map;return{VariableDeclarator(node){if(node.id.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.init){const unsafe=isUnsafeStringConstruction(node.init);if(unsafe){taintedVariables.set(node.id.name,unsafe)}}},AssignmentExpression(node){if(node.operator==="+="&&node.left.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){const unsafe=isUnsafeStringConstruction(node.right);if(unsafe){taintedVariables.set(node.left.name,unsafe)}}},CallExpression(node){if(node.callee.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression||node.callee.property.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||node.callee.property.name!=="query"){return}const args=node.arguments;if(args.length===0)return;const queryArg=args[0];if(queryArg.type===eslint_devkit_1.AST_NODE_TYPES.BinaryExpression&&queryArg.operator==="+"){context.report({node:queryArg,messageId:"noUnsafeQuery"});return}if(queryArg.type===eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral&&queryArg.expressions.length>0){context.report({node:queryArg,messageId:"unsafeTemplateLiteral"});return}if(queryArg.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){const taint=taintedVariables.get(queryArg.name);if(taint){context.report({node:queryArg,messageId:taint==="template"?"unsafeTemplateLiteral":"noUnsafeQuery"})}}}}}};
@@ -1,101 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noUnsafeSearchPath = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const hasSearchPath = (str) => str.toLowerCase().includes('set search_path');
6
- exports.noUnsafeSearchPath = {
7
- meta: {
8
- type: 'problem',
9
- docs: {
10
- description: 'Prevent unsafe SET search_path usage with dynamic values, which can lead to schema hijacking.',
11
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/no-unsafe-search-path.md',
12
- cwe: 'CWE-426',
13
- cvss: 7.5,
14
- },
15
- messages: {
16
- noUnsafeSearchPath: (0, eslint_devkit_1.formatLLMMessage)({
17
- icon: eslint_devkit_1.MessageIcons.SECURITY,
18
- issueName: 'Schema Hijacking Risk',
19
- description: 'Unsafe "SET search_path" detected.',
20
- severity: 'CRITICAL',
21
- cwe: 'CWE-426',
22
- owasp: 'A05:2021',
23
- compliance: ['SOC2', 'PCI-DSS'],
24
- effort: 'low',
25
- fix: 'Do not use dynamic values for search_path. Use static strings or strict validation.',
26
- documentationLink: 'https://www.postgresql.org/docs/current/ddl-schemas.html#DDL-SCHEMAS-PATH',
27
- }),
28
- },
29
- schema: [],
30
- },
31
- defaultOptions: [],
32
- create(context) {
33
- return {
34
- CallExpression(node) {
35
- if (node.callee.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression ||
36
- node.callee.property.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier ||
37
- node.callee.property.name !== 'query') {
38
- return;
39
- }
40
- const args = node.arguments;
41
- if (args.length === 0)
42
- return;
43
- const queryArg = args[0];
44
- if (queryArg.type === eslint_devkit_1.AST_NODE_TYPES.BinaryExpression && queryArg.operator === '+') {
45
- }
46
- if (queryArg.type === eslint_devkit_1.AST_NODE_TYPES.Literal) {
47
- if (typeof queryArg.value === 'string' && hasSearchPath(queryArg.value)) {
48
- return;
49
- }
50
- }
51
- if (queryArg.type === eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral) {
52
- const rawText = queryArg.quasis.map(q => q.value.raw).join(' ');
53
- if (hasSearchPath(rawText)) {
54
- if (queryArg.expressions.length > 0) {
55
- context.report({
56
- node: queryArg,
57
- messageId: 'noUnsafeSearchPath',
58
- });
59
- }
60
- }
61
- return;
62
- }
63
- if (queryArg.type === eslint_devkit_1.AST_NODE_TYPES.BinaryExpression) {
64
- const parts = [];
65
- const stack = [queryArg];
66
- for (let curr = stack.pop(); curr !== undefined; curr = stack.pop()) {
67
- if (curr.type === eslint_devkit_1.AST_NODE_TYPES.BinaryExpression && curr.operator === '+') {
68
- stack.push(curr.right);
69
- stack.push(curr.left);
70
- }
71
- else if (curr.type === eslint_devkit_1.AST_NODE_TYPES.Literal && typeof curr.value === 'string') {
72
- parts.push(curr.value);
73
- }
74
- }
75
- const combined = parts.join(' ');
76
- if (hasSearchPath(combined)) {
77
- context.report({
78
- node: queryArg,
79
- messageId: 'noUnsafeSearchPath',
80
- });
81
- }
82
- return;
83
- }
84
- if (queryArg.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression) {
85
- if (queryArg.arguments.length > 0 &&
86
- queryArg.arguments[0].type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
87
- typeof queryArg.arguments[0].value === 'string' &&
88
- hasSearchPath(queryArg.arguments[0].value)) {
89
- const allLiterals = queryArg.arguments.every(arg => arg.type === eslint_devkit_1.AST_NODE_TYPES.Literal);
90
- if (allLiterals)
91
- return;
92
- context.report({
93
- node: queryArg,
94
- messageId: 'noUnsafeSearchPath',
95
- });
96
- }
97
- }
98
- },
99
- };
100
- },
101
- };
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noUnsafeSearchPath=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const hasSearchPath=str=>str.toLowerCase().includes("set search_path");exports.noUnsafeSearchPath={meta:{type:"problem",docs:{description:"Prevent unsafe SET search_path usage with dynamic values, which can lead to schema hijacking.",url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/no-unsafe-search-path.md",cwe:"CWE-426",cvss:7.5},messages:{noUnsafeSearchPath:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Schema Hijacking Risk",description:'Unsafe "SET search_path" detected.',severity:"CRITICAL",cwe:"CWE-426",owasp:"A05:2021",compliance:["SOC2","PCI-DSS"],effort:"low",fix:"Do not use dynamic values for search_path. Use static strings or strict validation.",documentationLink:"https://www.postgresql.org/docs/current/ddl-schemas.html#DDL-SCHEMAS-PATH"})},schema:[]},defaultOptions:[],create(context){return{CallExpression(node){if(node.callee.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression||node.callee.property.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||node.callee.property.name!=="query"){return}const args=node.arguments;if(args.length===0)return;const queryArg=args[0];if(queryArg.type===eslint_devkit_1.AST_NODE_TYPES.BinaryExpression&&queryArg.operator==="+"){}if(queryArg.type===eslint_devkit_1.AST_NODE_TYPES.Literal){if(typeof queryArg.value==="string"&&hasSearchPath(queryArg.value)){return}}if(queryArg.type===eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral){const rawText=queryArg.quasis.map(q=>q.value.raw).join(" ");if(hasSearchPath(rawText)){if(queryArg.expressions.length>0){context.report({node:queryArg,messageId:"noUnsafeSearchPath"})}}return}if(queryArg.type===eslint_devkit_1.AST_NODE_TYPES.BinaryExpression){const parts=[];const stack=[queryArg];for(let curr=stack.pop();curr!==void 0;curr=stack.pop()){if(curr.type===eslint_devkit_1.AST_NODE_TYPES.BinaryExpression&&curr.operator==="+"){stack.push(curr.right);stack.push(curr.left)}else if(curr.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof curr.value==="string"){parts.push(curr.value)}}const combined=parts.join(" ");if(hasSearchPath(combined)){context.report({node:queryArg,messageId:"noUnsafeSearchPath"})}return}if(queryArg.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression){if(queryArg.arguments.length>0&&queryArg.arguments[0].type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof queryArg.arguments[0].value==="string"&&hasSearchPath(queryArg.arguments[0].value)){const allLiterals=queryArg.arguments.every(arg=>arg.type===eslint_devkit_1.AST_NODE_TYPES.Literal);if(allLiterals)return;context.report({node:queryArg,messageId:"noUnsafeSearchPath"})}}}}}};
@@ -1,87 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.preferPoolQuery = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- exports.preferPoolQuery = {
6
- meta: {
7
- type: 'suggestion',
8
- docs: {
9
- description: 'Prefer pool.query() over client.query() for single-shot queries.',
10
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/prefer-pool-query.md',
11
- },
12
- messages: {
13
- preferPoolQuery: (0, eslint_devkit_1.formatLLMMessage)({
14
- icon: eslint_devkit_1.MessageIcons.PERFORMANCE,
15
- issueName: 'Prefer Pool Query',
16
- description: 'Single-shot queries should use pool.query() directly.',
17
- severity: 'MEDIUM',
18
- cwe: 'CWE-400',
19
- effort: 'low',
20
- fix: 'Use pool.query(...) instead of manual client checkout/release for simple queries.',
21
- documentationLink: 'https://node-postgres.com/features/pooling',
22
- }),
23
- },
24
- schema: [],
25
- },
26
- defaultOptions: [],
27
- create(context) {
28
- return {
29
- VariableDeclarator(node) {
30
- if (!node.init ||
31
- node.init.type !== eslint_devkit_1.AST_NODE_TYPES.AwaitExpression ||
32
- node.init.argument.type !== eslint_devkit_1.AST_NODE_TYPES.CallExpression ||
33
- node.init.argument.callee.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression ||
34
- node.init.argument.callee.property.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier ||
35
- node.init.argument.callee.property.name !== 'connect') {
36
- return;
37
- }
38
- const variable = context.sourceCode.getDeclaredVariables(node)[0];
39
- if (!variable)
40
- return;
41
- const references = variable.references;
42
- let queryCallCount = 0;
43
- let releaseCallCount = 0;
44
- let otherUsageCount = 0;
45
- for (const ref of references) {
46
- if (ref.isWrite())
47
- continue;
48
- const id = ref.identifier;
49
- if (id.parent?.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
50
- id.parent.object === id &&
51
- id.parent.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
52
- const method = id.parent.property.name;
53
- if (method === 'query') {
54
- queryCallCount++;
55
- if (id.parent.parent?.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression) {
56
- const call = id.parent.parent;
57
- if (call.arguments.length > 0 &&
58
- call.arguments[0].type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
59
- typeof call.arguments[0].value === 'string') {
60
- const q = call.arguments[0].value.toUpperCase().trim();
61
- if (q.startsWith('BEGIN') || q.startsWith('COMMIT') || q.startsWith('ROLLBACK')) {
62
- return;
63
- }
64
- }
65
- }
66
- }
67
- else if (method === 'release') {
68
- releaseCallCount++;
69
- }
70
- else {
71
- otherUsageCount++;
72
- }
73
- }
74
- else {
75
- otherUsageCount++;
76
- }
77
- }
78
- if (queryCallCount === 1 && releaseCallCount === 1 && otherUsageCount === 0) {
79
- context.report({
80
- node,
81
- messageId: 'preferPoolQuery',
82
- });
83
- }
84
- },
85
- };
86
- },
87
- };
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.preferPoolQuery=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.preferPoolQuery={meta:{type:"suggestion",docs:{description:"Prefer pool.query() over client.query() for single-shot queries.",url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/prefer-pool-query.md"},messages:{preferPoolQuery:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.PERFORMANCE,issueName:"Prefer Pool Query",description:"Single-shot queries should use pool.query() directly.",severity:"MEDIUM",cwe:"CWE-400",effort:"low",fix:"Use pool.query(...) instead of manual client checkout/release for simple queries.",documentationLink:"https://node-postgres.com/features/pooling"})},schema:[]},defaultOptions:[],create(context){return{VariableDeclarator(node){if(!node.init||node.init.type!==eslint_devkit_1.AST_NODE_TYPES.AwaitExpression||node.init.argument.type!==eslint_devkit_1.AST_NODE_TYPES.CallExpression||node.init.argument.callee.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression||node.init.argument.callee.property.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||node.init.argument.callee.property.name!=="connect"){return}const variable=context.sourceCode.getDeclaredVariables(node)[0];if(!variable)return;const references=variable.references;let queryCallCount=0;let releaseCallCount=0;let otherUsageCount=0;for(const ref of references){if(ref.isWrite())continue;const id=ref.identifier;if(id.parent?.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&id.parent.object===id&&id.parent.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){const method=id.parent.property.name;if(method==="query"){queryCallCount++;if(id.parent.parent?.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression){const call=id.parent.parent;if(call.arguments.length>0&&call.arguments[0].type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof call.arguments[0].value==="string"){const q=call.arguments[0].value.toUpperCase().trim();if(q.startsWith("BEGIN")||q.startsWith("COMMIT")||q.startsWith("ROLLBACK")){return}}}}else if(method==="release"){releaseCallCount++}else{otherUsageCount++}}else{otherUsageCount++}}if(queryCallCount===1&&releaseCallCount===1&&otherUsageCount===0){context.report({node,messageId:"preferPoolQuery"})}}}}};