@interlace/eslint-devkit 1.9.0 → 1.10.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 (43) hide show
  1. package/package.json +1 -1
  2. package/src/aria-definitions.js +1 -990
  3. package/src/ast/ast-utils.js +1 -133
  4. package/src/ast/index.js +1 -17
  5. package/src/ast-node-types.js +1 -174
  6. package/src/index.js +1 -43
  7. package/src/messaging/config.js +1 -98
  8. package/src/messaging/constants.js +1 -678
  9. package/src/messaging/formatters-ai.js +2 -176
  10. package/src/messaging/formatters-v2.js +10 -212
  11. package/src/messaging/formatters.js +3 -186
  12. package/src/messaging/index.js +1 -21
  13. package/src/messaging/types-v2.js +1 -2
  14. package/src/messaging/types.js +1 -2
  15. package/src/node/fs.js +1 -104
  16. package/src/node/index.js +1 -19
  17. package/src/node/os.js +1 -52
  18. package/src/node/path.js +1 -143
  19. package/src/resolver/dependency-analysis.js +1 -740
  20. package/src/resolver/index.js +1 -20
  21. package/src/resolver/resolver-adapter.js +1 -92
  22. package/src/resolver/resolver-detection.js +1 -189
  23. package/src/resolver/resolver.js +1 -206
  24. package/src/resolver.js +1 -17
  25. package/src/rule-creation/browser-escape-hatch-rule.js +1 -100
  26. package/src/rule-creation/hardcoded-credentials-rule.js +1 -143
  27. package/src/rule-creation/index.d.ts +1 -0
  28. package/src/rule-creation/index.js +1 -26
  29. package/src/rule-creation/mass-assignment-rule.js +1 -121
  30. package/src/rule-creation/mock-context.js +1 -39
  31. package/src/rule-creation/raw-identifier-rule.js +1 -140
  32. package/src/rule-creation/require-tls-rule.js +1 -190
  33. package/src/rule-creation/rule-creator.js +1 -70
  34. package/src/rule-creation/sdk-api-key-rule.js +1 -121
  35. package/src/rule-creation/sql-injection-rule.js +1 -207
  36. package/src/rule-creation/system-prompt-injection-rule.d.ts +78 -0
  37. package/src/rule-creation/system-prompt-injection-rule.js +1 -0
  38. package/src/rule-creation/unscoped-mutation-rule.js +1 -234
  39. package/src/security/index.js +1 -17
  40. package/src/security/security-utils.js +1 -461
  41. package/src/types/index.js +1 -18
  42. package/src/types/meta-augmentation.js +1 -2
  43. package/src/types/type-utils.js +1 -222
@@ -1,143 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.urlEmbedsCredentials = urlEmbedsCredentials;
4
- exports.staticStringValue = staticStringValue;
5
- exports.isLiteralSecret = isLiteralSecret;
6
- exports.createHardcodedCredentialsRule = createHardcodedCredentialsRule;
7
- const ast_node_types_1 = require("../ast-node-types");
8
- const messaging_1 = require("../messaging");
9
- const unscoped_mutation_rule_1 = require("./unscoped-mutation-rule");
10
- const require_tls_rule_1 = require("./require-tls-rule");
11
- const CREDENTIAL_KEYS = ['password', 'pass', 'pwd', 'secret', 'passwd', 'auth'];
12
- const DEFAULT_CONNECTION_KEYS = [
13
- 'host',
14
- 'hostname',
15
- 'port',
16
- 'database',
17
- 'connectionString',
18
- 'socketPath',
19
- 'uri',
20
- 'url',
21
- 'connection',
22
- 'pool',
23
- 'schema',
24
- ];
25
- function urlEmbedsCredentials(value, schemes) {
26
- const match = /^([a-z][a-z0-9+.-]*):\/\/([^/@\s:]*:[^/@\s]+)@/i.exec(value);
27
- if (match === null)
28
- return false;
29
- return schemes.some((scheme) => scheme.toLowerCase() === match[1].toLowerCase());
30
- }
31
- function staticStringValue(node) {
32
- if (node.type === ast_node_types_1.AST_NODE_TYPES.Literal) {
33
- return typeof node.value === 'string' ? node.value : undefined;
34
- }
35
- if (node.type === ast_node_types_1.AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
36
- return node.quasis[0].value.cooked;
37
- }
38
- return undefined;
39
- }
40
- function isLiteralSecret(node) {
41
- const value = staticStringValue(node);
42
- return value !== undefined && value.length > 0;
43
- }
44
- function createHardcodedCredentialsRule(config) {
45
- const connectionKeys = [...DEFAULT_CONNECTION_KEYS, ...(config.connectionKeys ?? [])];
46
- return {
47
- meta: {
48
- type: config.meta.type,
49
- docs: { ...config.meta.docs },
50
- messages: {
51
- hardcodedPassword: (0, messaging_1.formatLLMMessage)({
52
- icon: messaging_1.MessageIcons.SECURITY,
53
- issueName: 'Hardcoded Credentials',
54
- description: 'A database password is written as a literal. It is in git history, every fork, and the built image — rotating it means rewriting history, so it never gets rotated.',
55
- severity: 'CRITICAL',
56
- cwe: config.meta.docs.cwe,
57
- owasp: 'A07:2021',
58
- compliance: ['SOC2', 'PCI-DSS', 'ISO27001', 'NIST-CSF'],
59
- effort: 'low',
60
- fix: config.fix,
61
- documentationLink: config.documentationLink,
62
- }),
63
- credentialsInUrl: (0, messaging_1.formatLLMMessage)({
64
- icon: messaging_1.MessageIcons.SECURITY,
65
- issueName: 'Hardcoded Credentials',
66
- description: 'A connection URL embeds a password in its userinfo section, so the secret is committed with the string.',
67
- severity: 'CRITICAL',
68
- cwe: config.meta.docs.cwe,
69
- owasp: 'A07:2021',
70
- compliance: ['SOC2', 'PCI-DSS', 'ISO27001', 'NIST-CSF'],
71
- effort: 'low',
72
- fix: config.urlFix,
73
- documentationLink: config.documentationLink,
74
- }),
75
- },
76
- schema: [],
77
- },
78
- defaultOptions: [],
79
- create(context) {
80
- let bindings = new Set();
81
- let reported = new WeakSet();
82
- let scanned = new WeakSet();
83
- const report = (node, messageId) => {
84
- if (reported.has(node))
85
- return;
86
- reported.add(node);
87
- context.report({ node, messageId });
88
- };
89
- const scanConfig = (obj) => {
90
- if (scanned.has(obj))
91
- return;
92
- scanned.add(obj);
93
- for (const prop of obj.properties) {
94
- if (prop.type !== ast_node_types_1.AST_NODE_TYPES.Property)
95
- continue;
96
- const name = (0, unscoped_mutation_rule_1.propertyKeyName)(prop);
97
- if (name === undefined)
98
- continue;
99
- if (CREDENTIAL_KEYS.includes(name.toLowerCase())) {
100
- if (isLiteralSecret(prop.value))
101
- report(prop.value, 'hardcodedPassword');
102
- continue;
103
- }
104
- const url = staticStringValue(prop.value);
105
- if (url !== undefined && urlEmbedsCredentials(url, config.urlSchemes)) {
106
- report(prop.value, 'credentialsInUrl');
107
- continue;
108
- }
109
- if (prop.value.type === ast_node_types_1.AST_NODE_TYPES.ObjectExpression &&
110
- connectionKeys.includes(name)) {
111
- scanConfig(prop.value);
112
- }
113
- }
114
- };
115
- return {
116
- Program(program) {
117
- bindings = (0, unscoped_mutation_rule_1.driverBindings)(program, config.modules);
118
- reported = new WeakSet();
119
- scanned = new WeakSet();
120
- },
121
- ObjectExpression(node) {
122
- if (bindings.size === 0)
123
- return;
124
- if (!(0, require_tls_rule_1.looksLikeConnectionConfig)(node, connectionKeys))
125
- return;
126
- scanConfig(node);
127
- },
128
- 'Literal, TemplateLiteral'(node) {
129
- if (bindings.size === 0)
130
- return;
131
- const value = staticStringValue(node);
132
- if (value === undefined)
133
- return;
134
- if (!urlEmbedsCredentials(value, config.urlSchemes))
135
- return;
136
- if (!(0, require_tls_rule_1.inConnectionPosition)(node, connectionKeys, bindings))
137
- return;
138
- report(node, 'credentialsInUrl');
139
- },
140
- };
141
- },
142
- };
143
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.urlEmbedsCredentials=urlEmbedsCredentials;exports.staticStringValue=staticStringValue;exports.isLiteralSecret=isLiteralSecret;exports.createHardcodedCredentialsRule=createHardcodedCredentialsRule;const ast_node_types_1=require("../ast-node-types");const messaging_1=require("../messaging");const unscoped_mutation_rule_1=require("./unscoped-mutation-rule");const require_tls_rule_1=require("./require-tls-rule");const CREDENTIAL_KEYS=["password","pass","pwd","secret","passwd","auth"];const DEFAULT_CONNECTION_KEYS=["host","hostname","port","database","connectionString","socketPath","uri","url","connection","pool","schema"];function urlEmbedsCredentials(value,schemes){const match=/^([a-z][a-z0-9+.-]*):\/\/([^/@\s:]*:[^/@\s]+)@/i.exec(value);if(match===null)return false;return schemes.some(scheme=>scheme.toLowerCase()===match[1].toLowerCase())}function staticStringValue(node){if(node.type===ast_node_types_1.AST_NODE_TYPES.Literal){return typeof node.value==="string"?node.value:void 0}if(node.type===ast_node_types_1.AST_NODE_TYPES.TemplateLiteral&&node.expressions.length===0){return node.quasis[0].value.cooked}return void 0}function isLiteralSecret(node){const value=staticStringValue(node);return value!==void 0&&value.length>0}function createHardcodedCredentialsRule(config){const connectionKeys=[...DEFAULT_CONNECTION_KEYS,...config.connectionKeys??[]];return{meta:{type:config.meta.type,docs:{...config.meta.docs},messages:{hardcodedPassword:(0,messaging_1.formatLLMMessage)({icon:messaging_1.MessageIcons.SECURITY,issueName:"Hardcoded Credentials",description:"A database password is written as a literal. It is in git history, every fork, and the built image \u2014 rotating it means rewriting history, so it never gets rotated.",severity:"CRITICAL",cwe:config.meta.docs.cwe,owasp:"A07:2021",compliance:["SOC2","PCI-DSS","ISO27001","NIST-CSF"],effort:"low",fix:config.fix,documentationLink:config.documentationLink}),credentialsInUrl:(0,messaging_1.formatLLMMessage)({icon:messaging_1.MessageIcons.SECURITY,issueName:"Hardcoded Credentials",description:"A connection URL embeds a password in its userinfo section, so the secret is committed with the string.",severity:"CRITICAL",cwe:config.meta.docs.cwe,owasp:"A07:2021",compliance:["SOC2","PCI-DSS","ISO27001","NIST-CSF"],effort:"low",fix:config.urlFix,documentationLink:config.documentationLink})},schema:[]},defaultOptions:[],create(context){let bindings=new Set;let reported=new WeakSet;let scanned=new WeakSet;const report=(node,messageId)=>{if(reported.has(node))return;reported.add(node);context.report({node,messageId})};const scanConfig=obj=>{if(scanned.has(obj))return;scanned.add(obj);for(const prop of obj.properties){if(prop.type!==ast_node_types_1.AST_NODE_TYPES.Property)continue;const name=(0,unscoped_mutation_rule_1.propertyKeyName)(prop);if(name===void 0)continue;if(CREDENTIAL_KEYS.includes(name.toLowerCase())){if(isLiteralSecret(prop.value))report(prop.value,"hardcodedPassword");continue}const url=staticStringValue(prop.value);if(url!==void 0&&urlEmbedsCredentials(url,config.urlSchemes)){report(prop.value,"credentialsInUrl");continue}if(prop.value.type===ast_node_types_1.AST_NODE_TYPES.ObjectExpression&&connectionKeys.includes(name)){scanConfig(prop.value)}}};return{Program(program){bindings=(0,unscoped_mutation_rule_1.driverBindings)(program,config.modules);reported=new WeakSet;scanned=new WeakSet},ObjectExpression(node){if(bindings.size===0)return;if(!(0,require_tls_rule_1.looksLikeConnectionConfig)(node,connectionKeys))return;scanConfig(node)},"Literal, TemplateLiteral"(node){if(bindings.size===0)return;const value=staticStringValue(node);if(value===void 0)return;if(!urlEmbedsCredentials(value,config.urlSchemes))return;if(!(0,require_tls_rule_1.inConnectionPosition)(node,connectionKeys,bindings))return;report(node,"credentialsInUrl")}}}}}
@@ -12,4 +12,5 @@ export * from './mass-assignment-rule';
12
12
  export * from './hardcoded-credentials-rule';
13
13
  export * from './sdk-api-key-rule';
14
14
  export * from './browser-escape-hatch-rule';
15
+ export * from './system-prompt-injection-rule';
15
16
  export * from './raw-identifier-rule';
@@ -1,26 +1 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./rule-creator"), exports);
18
- __exportStar(require("./mock-context"), exports);
19
- __exportStar(require("./sql-injection-rule"), exports);
20
- __exportStar(require("./unscoped-mutation-rule"), exports);
21
- __exportStar(require("./require-tls-rule"), exports);
22
- __exportStar(require("./mass-assignment-rule"), exports);
23
- __exportStar(require("./hardcoded-credentials-rule"), exports);
24
- __exportStar(require("./sdk-api-key-rule"), exports);
25
- __exportStar(require("./browser-escape-hatch-rule"), exports);
26
- __exportStar(require("./raw-identifier-rule"), exports);
1
+ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?(function(o,m,k,k2){if(k2===void 0)k2=k;var desc=Object.getOwnPropertyDescriptor(m,k);if(!desc||("get"in desc?!m.__esModule:desc.writable||desc.configurable)){desc={enumerable:true,get:function(){return m[k]}}}Object.defineProperty(o,k2,desc)}):(function(o,m,k,k2){if(k2===void 0)k2=k;o[k2]=m[k]}));var __exportStar=this&&this.__exportStar||function(m,exports2){for(var p in m)if(p!=="default"&&!Object.prototype.hasOwnProperty.call(exports2,p))__createBinding(exports2,m,p)};Object.defineProperty(exports,"__esModule",{value:true});__exportStar(require("./rule-creator"),exports);__exportStar(require("./mock-context"),exports);__exportStar(require("./sql-injection-rule"),exports);__exportStar(require("./unscoped-mutation-rule"),exports);__exportStar(require("./require-tls-rule"),exports);__exportStar(require("./mass-assignment-rule"),exports);__exportStar(require("./hardcoded-credentials-rule"),exports);__exportStar(require("./sdk-api-key-rule"),exports);__exportStar(require("./browser-escape-hatch-rule"),exports);__exportStar(require("./system-prompt-injection-rule"),exports);__exportStar(require("./raw-identifier-rule"),exports);
@@ -1,121 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isUntrustedSource = isUntrustedSource;
4
- exports.classifyPayload = classifyPayload;
5
- exports.createMassAssignmentRule = createMassAssignmentRule;
6
- const ast_node_types_1 = require("../ast-node-types");
7
- const messaging_1 = require("../messaging");
8
- const unscoped_mutation_rule_1 = require("./unscoped-mutation-rule");
9
- const REQUEST_OBJECTS = ['req', 'request', 'ctx', 'context', 'event'];
10
- const UNTRUSTED_PROPS = ['body', 'query', 'params', 'payload'];
11
- function isUntrustedSource(node) {
12
- if (node.type !== ast_node_types_1.AST_NODE_TYPES.MemberExpression || node.computed)
13
- return false;
14
- if (node.property.type !== ast_node_types_1.AST_NODE_TYPES.Identifier)
15
- return false;
16
- if (!UNTRUSTED_PROPS.includes(node.property.name)) {
17
- return false;
18
- }
19
- return baseIsRequest(node.object);
20
- }
21
- function baseIsRequest(node) {
22
- let cursor = node;
23
- while (cursor.type === ast_node_types_1.AST_NODE_TYPES.MemberExpression)
24
- cursor = cursor.object;
25
- return (cursor.type === ast_node_types_1.AST_NODE_TYPES.Identifier &&
26
- REQUEST_OBJECTS.includes(cursor.name));
27
- }
28
- function classifyPayload(node) {
29
- if (isUntrustedSource(node))
30
- return 'untrustedPayload';
31
- if (node.type === ast_node_types_1.AST_NODE_TYPES.ObjectExpression) {
32
- for (const prop of node.properties) {
33
- if (prop.type !== ast_node_types_1.AST_NODE_TYPES.SpreadElement)
34
- continue;
35
- if (isUntrustedSource(prop.argument))
36
- return 'untrustedSpread';
37
- }
38
- }
39
- return false;
40
- }
41
- function createMassAssignmentRule(config) {
42
- const methods = new Set(config.methods);
43
- const payloadKeys = new Set(config.payloadKeys ?? []);
44
- return {
45
- meta: {
46
- type: config.meta.type,
47
- docs: { ...config.meta.docs },
48
- messages: {
49
- untrustedPayload: (0, messaging_1.formatLLMMessage)({
50
- icon: messaging_1.MessageIcons.SECURITY,
51
- issueName: 'Mass Assignment',
52
- description: 'The request object is written straight to the database, so every column the model exposes is settable by the caller — including ones this code never mentions.',
53
- severity: 'HIGH',
54
- cwe: config.meta.docs.cwe,
55
- owasp: 'A04:2021',
56
- compliance: ['SOC2', 'PCI-DSS', 'NIST-CSF'],
57
- effort: 'medium',
58
- fix: config.fix,
59
- documentationLink: config.documentationLink,
60
- }),
61
- untrustedSpread: (0, messaging_1.formatLLMMessage)({
62
- icon: messaging_1.MessageIcons.SECURITY,
63
- issueName: 'Mass Assignment',
64
- description: 'Spreading the request into the payload carries every key it happens to hold, not just the ones written beside it.',
65
- severity: 'HIGH',
66
- cwe: config.meta.docs.cwe,
67
- owasp: 'A04:2021',
68
- compliance: ['SOC2', 'PCI-DSS', 'NIST-CSF'],
69
- effort: 'medium',
70
- fix: config.fix,
71
- documentationLink: config.documentationLink,
72
- }),
73
- },
74
- schema: [],
75
- },
76
- defaultOptions: [],
77
- create(context) {
78
- let bindings = new Set();
79
- return {
80
- Program(program) {
81
- bindings = (0, unscoped_mutation_rule_1.driverBindings)(program, config.modules);
82
- },
83
- CallExpression(node) {
84
- if (bindings.size === 0)
85
- return;
86
- if (node.callee.type !== ast_node_types_1.AST_NODE_TYPES.MemberExpression ||
87
- node.callee.property.type !== ast_node_types_1.AST_NODE_TYPES.Identifier ||
88
- !methods.has(node.callee.property.name)) {
89
- return;
90
- }
91
- const base = (0, unscoped_mutation_rule_1.receiverBaseName)(node.callee);
92
- if (base === undefined)
93
- return;
94
- if (!bindings.has(base) && !config.receiverPattern.test(base))
95
- return;
96
- for (const arg of node.arguments) {
97
- if (arg.type === ast_node_types_1.AST_NODE_TYPES.SpreadElement)
98
- continue;
99
- const direct = classifyPayload(arg);
100
- if (direct) {
101
- context.report({ node: arg, messageId: direct });
102
- continue;
103
- }
104
- if (arg.type !== ast_node_types_1.AST_NODE_TYPES.ObjectExpression)
105
- continue;
106
- for (const prop of arg.properties) {
107
- if (prop.type !== ast_node_types_1.AST_NODE_TYPES.Property)
108
- continue;
109
- const name = (0, unscoped_mutation_rule_1.propertyKeyName)(prop);
110
- if (name === undefined || !payloadKeys.has(name))
111
- continue;
112
- const nested = classifyPayload(prop.value);
113
- if (nested)
114
- context.report({ node: prop.value, messageId: nested });
115
- }
116
- }
117
- },
118
- };
119
- },
120
- };
121
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.isUntrustedSource=isUntrustedSource;exports.classifyPayload=classifyPayload;exports.createMassAssignmentRule=createMassAssignmentRule;const ast_node_types_1=require("../ast-node-types");const messaging_1=require("../messaging");const unscoped_mutation_rule_1=require("./unscoped-mutation-rule");const REQUEST_OBJECTS=["req","request","ctx","context","event"];const UNTRUSTED_PROPS=["body","query","params","payload"];function isUntrustedSource(node){if(node.type!==ast_node_types_1.AST_NODE_TYPES.MemberExpression||node.computed)return false;if(node.property.type!==ast_node_types_1.AST_NODE_TYPES.Identifier)return false;if(!UNTRUSTED_PROPS.includes(node.property.name)){return false}return baseIsRequest(node.object)}function baseIsRequest(node){let cursor=node;while(cursor.type===ast_node_types_1.AST_NODE_TYPES.MemberExpression)cursor=cursor.object;return cursor.type===ast_node_types_1.AST_NODE_TYPES.Identifier&&REQUEST_OBJECTS.includes(cursor.name)}function classifyPayload(node){if(isUntrustedSource(node))return"untrustedPayload";if(node.type===ast_node_types_1.AST_NODE_TYPES.ObjectExpression){for(const prop of node.properties){if(prop.type!==ast_node_types_1.AST_NODE_TYPES.SpreadElement)continue;if(isUntrustedSource(prop.argument))return"untrustedSpread"}}return false}function createMassAssignmentRule(config){const methods=new Set(config.methods);const payloadKeys=new Set(config.payloadKeys??[]);return{meta:{type:config.meta.type,docs:{...config.meta.docs},messages:{untrustedPayload:(0,messaging_1.formatLLMMessage)({icon:messaging_1.MessageIcons.SECURITY,issueName:"Mass Assignment",description:"The request object is written straight to the database, so every column the model exposes is settable by the caller \u2014 including ones this code never mentions.",severity:"HIGH",cwe:config.meta.docs.cwe,owasp:"A04:2021",compliance:["SOC2","PCI-DSS","NIST-CSF"],effort:"medium",fix:config.fix,documentationLink:config.documentationLink}),untrustedSpread:(0,messaging_1.formatLLMMessage)({icon:messaging_1.MessageIcons.SECURITY,issueName:"Mass Assignment",description:"Spreading the request into the payload carries every key it happens to hold, not just the ones written beside it.",severity:"HIGH",cwe:config.meta.docs.cwe,owasp:"A04:2021",compliance:["SOC2","PCI-DSS","NIST-CSF"],effort:"medium",fix:config.fix,documentationLink:config.documentationLink})},schema:[]},defaultOptions:[],create(context){let bindings=new Set;return{Program(program){bindings=(0,unscoped_mutation_rule_1.driverBindings)(program,config.modules)},CallExpression(node){if(bindings.size===0)return;if(node.callee.type!==ast_node_types_1.AST_NODE_TYPES.MemberExpression||node.callee.property.type!==ast_node_types_1.AST_NODE_TYPES.Identifier||!methods.has(node.callee.property.name)){return}const base=(0,unscoped_mutation_rule_1.receiverBaseName)(node.callee);if(base===void 0)return;if(!bindings.has(base)&&!config.receiverPattern.test(base))return;for(const arg of node.arguments){if(arg.type===ast_node_types_1.AST_NODE_TYPES.SpreadElement)continue;const direct=classifyPayload(arg);if(direct){context.report({node:arg,messageId:direct});continue}if(arg.type!==ast_node_types_1.AST_NODE_TYPES.ObjectExpression)continue;for(const prop of arg.properties){if(prop.type!==ast_node_types_1.AST_NODE_TYPES.Property)continue;const name=(0,unscoped_mutation_rule_1.propertyKeyName)(prop);if(name===void 0||!payloadKeys.has(name))continue;const nested=classifyPayload(prop.value);if(nested)context.report({node:prop.value,messageId:nested})}}}}}}}
@@ -1,39 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createWithMockContext = createWithMockContext;
4
- function createWithMockContext(rule, opts = {}) {
5
- const reports = [];
6
- const filename = opts.filename ?? 'mock.ts';
7
- const emptyScope = { variables: [], references: [], childScopes: [] };
8
- const sourceCode = {
9
- ast: opts.ast ?? { type: 'Program', body: [], tokens: [], comments: [] },
10
- text: opts.sourceText ?? '',
11
- getText: () => opts.sourceText ?? '',
12
- getScope: () => emptyScope,
13
- getAncestors: () => [],
14
- getCommentsBefore: () => [],
15
- getDeclaredVariables: () => [],
16
- };
17
- const context = {
18
- id: 'mock-rule',
19
- filename,
20
- physicalFilename: filename,
21
- cwd: '/',
22
- options: opts.options ?? rule.defaultOptions ?? [],
23
- settings: opts.settings ?? {},
24
- parserOptions: {},
25
- languageOptions: {},
26
- sourceCode,
27
- getFilename: () => filename,
28
- getPhysicalFilename: () => filename,
29
- getCwd: () => '/',
30
- getSourceCode: () => sourceCode,
31
- getScope: () => emptyScope,
32
- getAncestors: () => [],
33
- report: (descriptor) => {
34
- reports.push(descriptor);
35
- },
36
- };
37
- const listeners = rule.create(context);
38
- return { listeners, reports, context };
39
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.createWithMockContext=createWithMockContext;function createWithMockContext(rule,opts={}){const reports=[];const filename=opts.filename??"mock.ts";const emptyScope={variables:[],references:[],childScopes:[]};const sourceCode={ast:opts.ast??{type:"Program",body:[],tokens:[],comments:[]},text:opts.sourceText??"",getText:()=>opts.sourceText??"",getScope:()=>emptyScope,getAncestors:()=>[],getCommentsBefore:()=>[],getDeclaredVariables:()=>[]};const context={id:"mock-rule",filename,physicalFilename:filename,cwd:"/",options:opts.options??rule.defaultOptions??[],settings:opts.settings??{},parserOptions:{},languageOptions:{},sourceCode,getFilename:()=>filename,getPhysicalFilename:()=>filename,getCwd:()=>"/",getSourceCode:()=>sourceCode,getScope:()=>emptyScope,getAncestors:()=>[],report:descriptor=>{reports.push(descriptor)}};const listeners=rule.create(context);return{listeners,reports,context}}
@@ -1,140 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stripIdentifierGap = stripIdentifierGap;
4
- exports.lastClause = lastClause;
5
- exports.identifierPosition = identifierPosition;
6
- exports.calleeText = calleeText;
7
- exports.isExemptExpression = isExemptExpression;
8
- exports.tagName = tagName;
9
- exports.createRawIdentifierRule = createRawIdentifierRule;
10
- const ast_node_types_1 = require("../ast-node-types");
11
- const messaging_1 = require("../messaging");
12
- const unscoped_mutation_rule_1 = require("./unscoped-mutation-rule");
13
- const IDENTIFIER_KEYWORDS = /\b(?:from|join|into|update|table|order\s+by|group\s+by|select|distinct\s+on)$/i;
14
- const GAP_CHAR = /[\s"'`[]/;
15
- function stripIdentifierGap(text) {
16
- let end = text.length;
17
- while (end > 0 && GAP_CHAR.test(text[end - 1]))
18
- end--;
19
- return text.slice(0, end);
20
- }
21
- const CLAUSE_KEYWORDS = /\b(select|from|where|group\s+by|having|order\s+by|limit|offset|union|returning|values|set)\b/gi;
22
- function lastClause(text) {
23
- const matches = [...text.matchAll(CLAUSE_KEYWORDS)];
24
- const last = matches.at(-1);
25
- return last ? last[1].toLowerCase().replace(/\s+/g, ' ') : '';
26
- }
27
- function identifierPosition(precedingText) {
28
- if (IDENTIFIER_KEYWORDS.test(stripIdentifierGap(precedingText)))
29
- return 'identifier';
30
- if (lastClause(precedingText) === 'order by')
31
- return 'sortDirection';
32
- return false;
33
- }
34
- function calleeText(node) {
35
- if (node.type === ast_node_types_1.AST_NODE_TYPES.Identifier)
36
- return node.name;
37
- if (node.type === ast_node_types_1.AST_NODE_TYPES.MemberExpression && !node.computed) {
38
- const object = calleeText(node.object);
39
- const property = calleeText(node.property);
40
- return object && property ? `${object}.${property}` : '';
41
- }
42
- return '';
43
- }
44
- function isExemptExpression(expr, identifierHelpers, tags) {
45
- if (expr.type === ast_node_types_1.AST_NODE_TYPES.Literal)
46
- return true;
47
- if (expr.type === ast_node_types_1.AST_NODE_TYPES.CallExpression) {
48
- if (identifierHelpers.includes(calleeText(expr.callee)))
49
- return true;
50
- }
51
- if (expr.type === ast_node_types_1.AST_NODE_TYPES.TaggedTemplateExpression) {
52
- const nested = tagName(expr.tag);
53
- return nested !== undefined && tags.includes(nested);
54
- }
55
- return false;
56
- }
57
- function tagName(tag) {
58
- if (tag.type === ast_node_types_1.AST_NODE_TYPES.Identifier)
59
- return tag.name;
60
- if (tag.type === ast_node_types_1.AST_NODE_TYPES.MemberExpression &&
61
- !tag.computed &&
62
- tag.property.type === ast_node_types_1.AST_NODE_TYPES.Identifier) {
63
- return tag.property.name;
64
- }
65
- return undefined;
66
- }
67
- function createRawIdentifierRule(config) {
68
- const tags = new Set(config.tags);
69
- return {
70
- meta: {
71
- type: config.meta.type,
72
- docs: { ...config.meta.docs },
73
- messages: {
74
- identifierInterpolation: (0, messaging_1.formatLLMMessage)({
75
- icon: messaging_1.MessageIcons.SECURITY,
76
- issueName: 'SQL Injection Risk',
77
- description: 'A table or column name is interpolated into a parameterized query. Bind parameters only ever substitute values, so this identifier is spliced into the SQL as text.',
78
- severity: 'CRITICAL',
79
- cwe: config.meta.docs.cwe,
80
- owasp: 'A03:2021',
81
- compliance: ['SOC2', 'PCI-DSS', 'NIST-CSF'],
82
- effort: 'medium',
83
- fix: config.fix,
84
- documentationLink: config.documentationLink,
85
- }),
86
- sortDirectionInterpolation: (0, messaging_1.formatLLMMessage)({
87
- icon: messaging_1.MessageIcons.SECURITY,
88
- issueName: 'SQL Injection Risk',
89
- description: 'A value is interpolated inside an ORDER BY clause, where a bind parameter cannot reach.',
90
- severity: 'HIGH',
91
- cwe: config.meta.docs.cwe,
92
- owasp: 'A03:2021',
93
- compliance: ['SOC2', 'PCI-DSS', 'NIST-CSF'],
94
- effort: 'low',
95
- fix: config.sortDirectionFix,
96
- documentationLink: config.documentationLink,
97
- }),
98
- },
99
- schema: [],
100
- },
101
- defaultOptions: [],
102
- create(context) {
103
- let bindings = new Set();
104
- return {
105
- Program(program) {
106
- bindings = (0, unscoped_mutation_rule_1.driverBindings)(program, config.modules);
107
- },
108
- TaggedTemplateExpression(node) {
109
- const name = tagName(node.tag);
110
- if (name === undefined || !tags.has(name))
111
- return;
112
- if (config.requireImport) {
113
- if (node.tag.type !== ast_node_types_1.AST_NODE_TYPES.Identifier)
114
- return;
115
- if (!bindings.has(name))
116
- return;
117
- }
118
- const { quasis, expressions } = node.quasi;
119
- expressions.forEach((expr, index) => {
120
- if (isExemptExpression(expr, config.identifierHelpers, config.tags))
121
- return;
122
- const preceding = quasis
123
- .slice(0, index + 1)
124
- .map((q) => q.value.raw)
125
- .join(' ');
126
- const position = identifierPosition(preceding);
127
- if (position === false)
128
- return;
129
- context.report({
130
- node: expr,
131
- messageId: position === 'identifier'
132
- ? 'identifierInterpolation'
133
- : 'sortDirectionInterpolation',
134
- });
135
- });
136
- },
137
- };
138
- },
139
- };
140
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.stripIdentifierGap=stripIdentifierGap;exports.lastClause=lastClause;exports.identifierPosition=identifierPosition;exports.calleeText=calleeText;exports.isExemptExpression=isExemptExpression;exports.tagName=tagName;exports.createRawIdentifierRule=createRawIdentifierRule;const ast_node_types_1=require("../ast-node-types");const messaging_1=require("../messaging");const unscoped_mutation_rule_1=require("./unscoped-mutation-rule");const IDENTIFIER_KEYWORDS=/\b(?:from|join|into|update|table|order\s+by|group\s+by|select|distinct\s+on)$/i;const GAP_CHAR=/[\s"'`[]/;function stripIdentifierGap(text){let end=text.length;while(end>0&&GAP_CHAR.test(text[end-1]))end--;return text.slice(0,end)}const CLAUSE_KEYWORDS=/\b(select|from|where|group\s+by|having|order\s+by|limit|offset|union|returning|values|set)\b/gi;function lastClause(text){const matches=[...text.matchAll(CLAUSE_KEYWORDS)];const last=matches.at(-1);return last?last[1].toLowerCase().replace(/\s+/g," "):""}function identifierPosition(precedingText){if(IDENTIFIER_KEYWORDS.test(stripIdentifierGap(precedingText)))return"identifier";if(lastClause(precedingText)==="order by")return"sortDirection";return false}function calleeText(node){if(node.type===ast_node_types_1.AST_NODE_TYPES.Identifier)return node.name;if(node.type===ast_node_types_1.AST_NODE_TYPES.MemberExpression&&!node.computed){const object=calleeText(node.object);const property=calleeText(node.property);return object&&property?`${object}.${property}`:""}return""}function isExemptExpression(expr,identifierHelpers,tags){if(expr.type===ast_node_types_1.AST_NODE_TYPES.Literal)return true;if(expr.type===ast_node_types_1.AST_NODE_TYPES.CallExpression){if(identifierHelpers.includes(calleeText(expr.callee)))return true}if(expr.type===ast_node_types_1.AST_NODE_TYPES.TaggedTemplateExpression){const nested=tagName(expr.tag);return nested!==void 0&&tags.includes(nested)}return false}function tagName(tag){if(tag.type===ast_node_types_1.AST_NODE_TYPES.Identifier)return tag.name;if(tag.type===ast_node_types_1.AST_NODE_TYPES.MemberExpression&&!tag.computed&&tag.property.type===ast_node_types_1.AST_NODE_TYPES.Identifier){return tag.property.name}return void 0}function createRawIdentifierRule(config){const tags=new Set(config.tags);return{meta:{type:config.meta.type,docs:{...config.meta.docs},messages:{identifierInterpolation:(0,messaging_1.formatLLMMessage)({icon:messaging_1.MessageIcons.SECURITY,issueName:"SQL Injection Risk",description:"A table or column name is interpolated into a parameterized query. Bind parameters only ever substitute values, so this identifier is spliced into the SQL as text.",severity:"CRITICAL",cwe:config.meta.docs.cwe,owasp:"A03:2021",compliance:["SOC2","PCI-DSS","NIST-CSF"],effort:"medium",fix:config.fix,documentationLink:config.documentationLink}),sortDirectionInterpolation:(0,messaging_1.formatLLMMessage)({icon:messaging_1.MessageIcons.SECURITY,issueName:"SQL Injection Risk",description:"A value is interpolated inside an ORDER BY clause, where a bind parameter cannot reach.",severity:"HIGH",cwe:config.meta.docs.cwe,owasp:"A03:2021",compliance:["SOC2","PCI-DSS","NIST-CSF"],effort:"low",fix:config.sortDirectionFix,documentationLink:config.documentationLink})},schema:[]},defaultOptions:[],create(context){let bindings=new Set;return{Program(program){bindings=(0,unscoped_mutation_rule_1.driverBindings)(program,config.modules)},TaggedTemplateExpression(node){const name=tagName(node.tag);if(name===void 0||!tags.has(name))return;if(config.requireImport){if(node.tag.type!==ast_node_types_1.AST_NODE_TYPES.Identifier)return;if(!bindings.has(name))return}const{quasis,expressions}=node.quasi;expressions.forEach((expr,index)=>{if(isExemptExpression(expr,config.identifierHelpers,config.tags))return;const preceding=quasis.slice(0,index+1).map(q=>q.value.raw).join(" ");const position=identifierPosition(preceding);if(position===false)return;context.report({node:expr,messageId:position==="identifier"?"identifierInterpolation":"sortDirectionInterpolation"})})}}}}}