@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.
- package/package.json +1 -1
- package/src/aria-definitions.js +1 -990
- package/src/ast/ast-utils.js +1 -133
- package/src/ast/index.js +1 -17
- package/src/ast-node-types.js +1 -174
- package/src/index.js +1 -43
- package/src/messaging/config.js +1 -98
- package/src/messaging/constants.js +1 -678
- package/src/messaging/formatters-ai.js +2 -176
- package/src/messaging/formatters-v2.js +10 -212
- package/src/messaging/formatters.js +3 -186
- package/src/messaging/index.js +1 -21
- package/src/messaging/types-v2.js +1 -2
- package/src/messaging/types.js +1 -2
- package/src/node/fs.js +1 -104
- package/src/node/index.js +1 -19
- package/src/node/os.js +1 -52
- package/src/node/path.js +1 -143
- package/src/resolver/dependency-analysis.js +1 -740
- package/src/resolver/index.js +1 -20
- package/src/resolver/resolver-adapter.js +1 -92
- package/src/resolver/resolver-detection.js +1 -189
- package/src/resolver/resolver.js +1 -206
- package/src/resolver.js +1 -17
- package/src/rule-creation/browser-escape-hatch-rule.js +1 -100
- package/src/rule-creation/hardcoded-credentials-rule.js +1 -143
- package/src/rule-creation/index.d.ts +1 -0
- package/src/rule-creation/index.js +1 -26
- package/src/rule-creation/mass-assignment-rule.js +1 -121
- package/src/rule-creation/mock-context.js +1 -39
- package/src/rule-creation/raw-identifier-rule.js +1 -140
- package/src/rule-creation/require-tls-rule.js +1 -190
- package/src/rule-creation/rule-creator.js +1 -70
- package/src/rule-creation/sdk-api-key-rule.js +1 -121
- package/src/rule-creation/sql-injection-rule.js +1 -207
- package/src/rule-creation/system-prompt-injection-rule.d.ts +78 -0
- package/src/rule-creation/system-prompt-injection-rule.js +1 -0
- package/src/rule-creation/unscoped-mutation-rule.js +1 -234
- package/src/security/index.js +1 -17
- package/src/security/security-utils.js +1 -461
- package/src/types/index.js +1 -18
- package/src/types/meta-augmentation.js +1 -2
- package/src/types/type-utils.js +1 -222
package/src/resolver/index.js
CHANGED
|
@@ -1,20 +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("./resolver"), exports);
|
|
18
|
-
__exportStar(require("./resolver-adapter"), exports);
|
|
19
|
-
__exportStar(require("./dependency-analysis"), exports);
|
|
20
|
-
__exportStar(require("./resolver-detection"), 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("./resolver"),exports);__exportStar(require("./resolver-adapter"),exports);__exportStar(require("./dependency-analysis"),exports);__exportStar(require("./resolver-detection"),exports);
|
|
@@ -1,92 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveWithExternalResolvers = resolveWithExternalResolvers;
|
|
4
|
-
const loadedResolvers = new Map();
|
|
5
|
-
function loadResolver(name) {
|
|
6
|
-
const cached = loadedResolvers.get(name);
|
|
7
|
-
if (cached !== undefined) {
|
|
8
|
-
return cached;
|
|
9
|
-
}
|
|
10
|
-
const potentialNames = [
|
|
11
|
-
name,
|
|
12
|
-
`eslint-import-resolver-${name}`,
|
|
13
|
-
name.startsWith('@') ? name : null,
|
|
14
|
-
].filter(Boolean);
|
|
15
|
-
let resolver = null;
|
|
16
|
-
for (const pkgName of potentialNames) {
|
|
17
|
-
try {
|
|
18
|
-
const loaded = require(pkgName);
|
|
19
|
-
if (loaded && typeof loaded.resolve === 'function') {
|
|
20
|
-
resolver = loaded;
|
|
21
|
-
break;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
catch (error) {
|
|
25
|
-
const err = error;
|
|
26
|
-
if (err.code !== 'MODULE_NOT_FOUND') {
|
|
27
|
-
console.warn(`Failed to load resolver ${pkgName}:`, error);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
loadedResolvers.set(name, resolver);
|
|
32
|
-
return resolver;
|
|
33
|
-
}
|
|
34
|
-
function normalizeResolverSettings(settings) {
|
|
35
|
-
const normalized = [];
|
|
36
|
-
if (typeof settings === 'string') {
|
|
37
|
-
normalized.push({ name: settings, config: {}, priority: 0 });
|
|
38
|
-
}
|
|
39
|
-
else if (Array.isArray(settings)) {
|
|
40
|
-
settings.forEach((item, index) => {
|
|
41
|
-
if (typeof item === 'string') {
|
|
42
|
-
normalized.push({ name: item, config: {}, priority: index });
|
|
43
|
-
}
|
|
44
|
-
else if (typeof item === 'object') {
|
|
45
|
-
Object.entries(item).forEach(([name, config]) => {
|
|
46
|
-
const priority = typeof config === 'object' &&
|
|
47
|
-
config !== null &&
|
|
48
|
-
'priority' in config
|
|
49
|
-
? config['priority'] || index
|
|
50
|
-
: index;
|
|
51
|
-
normalized.push({
|
|
52
|
-
name,
|
|
53
|
-
config: config,
|
|
54
|
-
priority,
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
else if (typeof settings === 'object') {
|
|
61
|
-
Object.entries(settings).forEach(([name, config], index) => {
|
|
62
|
-
const priority = typeof config === 'object' && config !== null && 'priority' in config
|
|
63
|
-
? config['priority'] || index
|
|
64
|
-
: index;
|
|
65
|
-
normalized.push({
|
|
66
|
-
name,
|
|
67
|
-
config: config,
|
|
68
|
-
priority,
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
return normalized.sort((a, b) => a.priority - b.priority);
|
|
73
|
-
}
|
|
74
|
-
function resolveWithExternalResolvers(source, file, settings) {
|
|
75
|
-
if (!settings)
|
|
76
|
-
return null;
|
|
77
|
-
const normalizedResolvers = normalizeResolverSettings(settings);
|
|
78
|
-
for (const { name, config } of normalizedResolvers) {
|
|
79
|
-
const resolver = loadResolver(name);
|
|
80
|
-
if (resolver && typeof resolver.resolve === 'function') {
|
|
81
|
-
try {
|
|
82
|
-
const result = resolver.resolve(source, file, config);
|
|
83
|
-
if (result.found && result.path) {
|
|
84
|
-
return result.path;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
catch {
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.resolveWithExternalResolvers=resolveWithExternalResolvers;const loadedResolvers=new Map;function loadResolver(name){const cached=loadedResolvers.get(name);if(cached!==void 0){return cached}const potentialNames=[name,`eslint-import-resolver-${name}`,name.startsWith("@")?name:null].filter(Boolean);let resolver=null;for(const pkgName of potentialNames){try{const loaded=require(pkgName);if(loaded&&typeof loaded.resolve==="function"){resolver=loaded;break}}catch(error){const err=error;if(err.code!=="MODULE_NOT_FOUND"){console.warn(`Failed to load resolver ${pkgName}:`,error)}}}loadedResolvers.set(name,resolver);return resolver}function normalizeResolverSettings(settings){const normalized=[];if(typeof settings==="string"){normalized.push({name:settings,config:{},priority:0})}else if(Array.isArray(settings)){settings.forEach((item,index)=>{if(typeof item==="string"){normalized.push({name:item,config:{},priority:index})}else if(typeof item==="object"){Object.entries(item).forEach(([name,config])=>{const priority=typeof config==="object"&&config!==null&&"priority"in config?config["priority"]||index:index;normalized.push({name,config,priority})})}})}else if(typeof settings==="object"){Object.entries(settings).forEach(([name,config],index)=>{const priority=typeof config==="object"&&config!==null&&"priority"in config?config["priority"]||index:index;normalized.push({name,config,priority})})}return normalized.sort((a,b)=>a.priority-b.priority)}function resolveWithExternalResolvers(source,file,settings){if(!settings)return null;const normalizedResolvers=normalizeResolverSettings(settings);for(const{name,config}of normalizedResolvers){const resolver=loadResolver(name);if(resolver&&typeof resolver.resolve==="function"){try{const result=resolver.resolve(source,file,config);if(result.found&&result.path){return result.path}}catch{}}}return null}
|
|
@@ -1,189 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.detectResolvers = detectResolvers;
|
|
4
|
-
exports.compareResolverPriority = compareResolverPriority;
|
|
5
|
-
exports.generateRecommendedConfig = generateRecommendedConfig;
|
|
6
|
-
exports.migrateFromEslintImport = migrateFromEslintImport;
|
|
7
|
-
exports.validateResolverConfig = validateResolverConfig;
|
|
8
|
-
const fs_1 = require("../node/fs");
|
|
9
|
-
function detectResolvers(workspaceRoot) {
|
|
10
|
-
const results = [];
|
|
11
|
-
const tsconfigPath = (0, fs_1.findFileUpward)('tsconfig.json', workspaceRoot);
|
|
12
|
-
results.push({
|
|
13
|
-
name: 'typescript',
|
|
14
|
-
detected: !!tsconfigPath,
|
|
15
|
-
config: tsconfigPath ? { alwaysTryTypes: true } : undefined,
|
|
16
|
-
reason: tsconfigPath ? 'Found tsconfig.json' : 'No tsconfig.json found',
|
|
17
|
-
});
|
|
18
|
-
const webpackConfig = (0, fs_1.findFileUpward)('webpack.config.js', workspaceRoot) ||
|
|
19
|
-
(0, fs_1.findFileUpward)('webpack.config.ts', workspaceRoot);
|
|
20
|
-
results.push({
|
|
21
|
-
name: 'webpack',
|
|
22
|
-
detected: !!webpackConfig,
|
|
23
|
-
config: webpackConfig ? { config: webpackConfig } : undefined,
|
|
24
|
-
reason: webpackConfig
|
|
25
|
-
? `Found ${webpackConfig.split('/').pop()}`
|
|
26
|
-
: 'No webpack config found',
|
|
27
|
-
});
|
|
28
|
-
const viteConfig = (0, fs_1.findFileUpward)('vite.config.js', workspaceRoot) ||
|
|
29
|
-
(0, fs_1.findFileUpward)('vite.config.ts', workspaceRoot) ||
|
|
30
|
-
(0, fs_1.findFileUpward)('vite.config.mjs', workspaceRoot);
|
|
31
|
-
results.push({
|
|
32
|
-
name: 'vite',
|
|
33
|
-
detected: !!viteConfig,
|
|
34
|
-
config: viteConfig ? { config: viteConfig } : undefined,
|
|
35
|
-
reason: viteConfig
|
|
36
|
-
? `Found ${viteConfig.split('/').pop()}`
|
|
37
|
-
: 'No vite config found',
|
|
38
|
-
});
|
|
39
|
-
const rollupConfig = (0, fs_1.findFileUpward)('rollup.config.js', workspaceRoot) ||
|
|
40
|
-
(0, fs_1.findFileUpward)('rollup.config.ts', workspaceRoot);
|
|
41
|
-
results.push({
|
|
42
|
-
name: 'rollup',
|
|
43
|
-
detected: !!rollupConfig,
|
|
44
|
-
config: rollupConfig ? { config: rollupConfig } : undefined,
|
|
45
|
-
reason: rollupConfig
|
|
46
|
-
? `Found ${rollupConfig.split('/').pop()}`
|
|
47
|
-
: 'No rollup config found',
|
|
48
|
-
});
|
|
49
|
-
const packageJson = (0, fs_1.findFileUpward)('package.json', workspaceRoot);
|
|
50
|
-
let hasReact = false;
|
|
51
|
-
if (packageJson) {
|
|
52
|
-
try {
|
|
53
|
-
hasReact = packageJson.includes('react');
|
|
54
|
-
}
|
|
55
|
-
catch {
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
results.push({
|
|
59
|
-
name: 'css',
|
|
60
|
-
detected: hasReact,
|
|
61
|
-
config: hasReact ? { extensions: ['.css', '.scss', '.sass'] } : undefined,
|
|
62
|
-
reason: hasReact ? 'React project detected' : 'Not a React project',
|
|
63
|
-
});
|
|
64
|
-
return results;
|
|
65
|
-
}
|
|
66
|
-
function compareResolverPriority(aName, bName) {
|
|
67
|
-
const priorityOrder = ['typescript', 'webpack', 'vite', 'rollup', 'css'];
|
|
68
|
-
const aIndex = priorityOrder.indexOf(aName);
|
|
69
|
-
const bIndex = priorityOrder.indexOf(bName);
|
|
70
|
-
return (aIndex === -1 ? 999 : aIndex) - (bIndex === -1 ? 999 : bIndex);
|
|
71
|
-
}
|
|
72
|
-
function generateRecommendedConfig(workspaceRoot) {
|
|
73
|
-
const detected = detectResolvers(workspaceRoot);
|
|
74
|
-
const availableResolvers = detected.filter((r) => r.detected);
|
|
75
|
-
const settings = {};
|
|
76
|
-
const recommendations = [];
|
|
77
|
-
if (availableResolvers.length === 0) {
|
|
78
|
-
settings['import/resolver'] = 'node';
|
|
79
|
-
recommendations.push('Using basic Node.js resolution (no bundler config detected)');
|
|
80
|
-
return { settings, recommendations };
|
|
81
|
-
}
|
|
82
|
-
const prioritized = availableResolvers.sort((a, b) => compareResolverPriority(a.name, b.name));
|
|
83
|
-
const resolverConfig = {};
|
|
84
|
-
prioritized.forEach((resolver, index) => {
|
|
85
|
-
resolverConfig[resolver.name] = {
|
|
86
|
-
...resolver.config,
|
|
87
|
-
priority: index,
|
|
88
|
-
};
|
|
89
|
-
});
|
|
90
|
-
settings['import/resolver'] = resolverConfig;
|
|
91
|
-
recommendations.push(`Auto-detected ${availableResolvers.length} resolvers:`);
|
|
92
|
-
availableResolvers.forEach((r) => {
|
|
93
|
-
recommendations.push(` ✓ ${r.name}: ${r.reason}`);
|
|
94
|
-
});
|
|
95
|
-
return { settings, recommendations };
|
|
96
|
-
}
|
|
97
|
-
function migrateFromEslintImport(oldConfig) {
|
|
98
|
-
const migrated = {};
|
|
99
|
-
const warnings = [];
|
|
100
|
-
const suggestions = [];
|
|
101
|
-
const oldSettings = oldConfig['settings'];
|
|
102
|
-
if (oldSettings &&
|
|
103
|
-
typeof oldSettings === 'object' &&
|
|
104
|
-
'import/resolver' in oldSettings) {
|
|
105
|
-
migrated['settings'] = {
|
|
106
|
-
...oldSettings,
|
|
107
|
-
};
|
|
108
|
-
suggestions.push('Resolver settings preserved - no changes needed');
|
|
109
|
-
}
|
|
110
|
-
const oldRules = oldConfig['rules'];
|
|
111
|
-
if (oldRules && typeof oldRules === 'object') {
|
|
112
|
-
const newRules = {};
|
|
113
|
-
Object.entries(oldRules).forEach(([ruleName, ruleConfig]) => {
|
|
114
|
-
if (ruleName.startsWith('import/')) {
|
|
115
|
-
const ruleMappings = {
|
|
116
|
-
'import/no-unresolved': 'import-next/no-unresolved',
|
|
117
|
-
'import/no-cycle': 'import-next/no-cycle',
|
|
118
|
-
'import/no-self-import': 'import-next/no-self-import',
|
|
119
|
-
'import/no-absolute-path': 'import-next/no-absolute-path',
|
|
120
|
-
'import/no-dynamic-require': 'import-next/no-dynamic-require',
|
|
121
|
-
'import/no-webpack-loader-syntax': 'import-next/no-webpack-loader-syntax',
|
|
122
|
-
};
|
|
123
|
-
if (ruleMappings[ruleName]) {
|
|
124
|
-
newRules[ruleMappings[ruleName]] = ruleConfig;
|
|
125
|
-
suggestions.push(`Migrated ${ruleName} → ${ruleMappings[ruleName]}`);
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
newRules[ruleName] = ruleConfig;
|
|
129
|
-
warnings.push(`Rule ${ruleName} not automatically migrated - may need manual adjustment`);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
newRules[ruleName] = ruleConfig;
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
migrated['rules'] = newRules;
|
|
137
|
-
}
|
|
138
|
-
return { migrated, warnings, suggestions };
|
|
139
|
-
}
|
|
140
|
-
function validateResolverConfig(settings) {
|
|
141
|
-
const errors = [];
|
|
142
|
-
const warnings = [];
|
|
143
|
-
const resolverSettings = settings['import/resolver'];
|
|
144
|
-
if (!resolverSettings) {
|
|
145
|
-
warnings.push('No import/resolver settings found - using defaults');
|
|
146
|
-
return { valid: true, errors, warnings };
|
|
147
|
-
}
|
|
148
|
-
if (typeof resolverSettings === 'string') {
|
|
149
|
-
if (!resolverSettings.trim()) {
|
|
150
|
-
errors.push('Resolver name cannot be empty');
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
else if (Array.isArray(resolverSettings)) {
|
|
154
|
-
resolverSettings.forEach((item, index) => {
|
|
155
|
-
if (typeof item === 'string') {
|
|
156
|
-
if (!item.trim()) {
|
|
157
|
-
errors.push(`Resolver at index ${index} cannot be empty`);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
else if (typeof item === 'object' && item !== null) {
|
|
161
|
-
const entries = Object.entries(item);
|
|
162
|
-
if (entries.length === 0) {
|
|
163
|
-
errors.push(`Resolver object at index ${index} is empty`);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
errors.push(`Invalid resolver format at index ${index}`);
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
else if (typeof resolverSettings === 'object') {
|
|
172
|
-
Object.entries(resolverSettings).forEach(([name, config]) => {
|
|
173
|
-
if (!name.trim()) {
|
|
174
|
-
errors.push('Resolver name cannot be empty');
|
|
175
|
-
}
|
|
176
|
-
if (typeof config !== 'object' || config === null) {
|
|
177
|
-
errors.push(`Resolver ${name} config must be an object`);
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
errors.push('Resolver settings must be a string, array, or object');
|
|
183
|
-
}
|
|
184
|
-
return {
|
|
185
|
-
valid: errors.length === 0,
|
|
186
|
-
errors,
|
|
187
|
-
warnings,
|
|
188
|
-
};
|
|
189
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.detectResolvers=detectResolvers;exports.compareResolverPriority=compareResolverPriority;exports.generateRecommendedConfig=generateRecommendedConfig;exports.migrateFromEslintImport=migrateFromEslintImport;exports.validateResolverConfig=validateResolverConfig;const fs_1=require("../node/fs");function detectResolvers(workspaceRoot){const results=[];const tsconfigPath=(0,fs_1.findFileUpward)("tsconfig.json",workspaceRoot);results.push({name:"typescript",detected:!!tsconfigPath,config:tsconfigPath?{alwaysTryTypes:true}:void 0,reason:tsconfigPath?"Found tsconfig.json":"No tsconfig.json found"});const webpackConfig=(0,fs_1.findFileUpward)("webpack.config.js",workspaceRoot)||(0,fs_1.findFileUpward)("webpack.config.ts",workspaceRoot);results.push({name:"webpack",detected:!!webpackConfig,config:webpackConfig?{config:webpackConfig}:void 0,reason:webpackConfig?`Found ${webpackConfig.split("/").pop()}`:"No webpack config found"});const viteConfig=(0,fs_1.findFileUpward)("vite.config.js",workspaceRoot)||(0,fs_1.findFileUpward)("vite.config.ts",workspaceRoot)||(0,fs_1.findFileUpward)("vite.config.mjs",workspaceRoot);results.push({name:"vite",detected:!!viteConfig,config:viteConfig?{config:viteConfig}:void 0,reason:viteConfig?`Found ${viteConfig.split("/").pop()}`:"No vite config found"});const rollupConfig=(0,fs_1.findFileUpward)("rollup.config.js",workspaceRoot)||(0,fs_1.findFileUpward)("rollup.config.ts",workspaceRoot);results.push({name:"rollup",detected:!!rollupConfig,config:rollupConfig?{config:rollupConfig}:void 0,reason:rollupConfig?`Found ${rollupConfig.split("/").pop()}`:"No rollup config found"});const packageJson=(0,fs_1.findFileUpward)("package.json",workspaceRoot);let hasReact=false;if(packageJson){try{hasReact=packageJson.includes("react")}catch{}}results.push({name:"css",detected:hasReact,config:hasReact?{extensions:[".css",".scss",".sass"]}:void 0,reason:hasReact?"React project detected":"Not a React project"});return results}function compareResolverPriority(aName,bName){const priorityOrder=["typescript","webpack","vite","rollup","css"];const aIndex=priorityOrder.indexOf(aName);const bIndex=priorityOrder.indexOf(bName);return(aIndex===-1?999:aIndex)-(bIndex===-1?999:bIndex)}function generateRecommendedConfig(workspaceRoot){const detected=detectResolvers(workspaceRoot);const availableResolvers=detected.filter(r=>r.detected);const settings={};const recommendations=[];if(availableResolvers.length===0){settings["import/resolver"]="node";recommendations.push("Using basic Node.js resolution (no bundler config detected)");return{settings,recommendations}}const prioritized=availableResolvers.sort((a,b)=>compareResolverPriority(a.name,b.name));const resolverConfig={};prioritized.forEach((resolver,index)=>{resolverConfig[resolver.name]={...resolver.config,priority:index}});settings["import/resolver"]=resolverConfig;recommendations.push(`Auto-detected ${availableResolvers.length} resolvers:`);availableResolvers.forEach(r=>{recommendations.push(` \u2713 ${r.name}: ${r.reason}`)});return{settings,recommendations}}function migrateFromEslintImport(oldConfig){const migrated={};const warnings=[];const suggestions=[];const oldSettings=oldConfig["settings"];if(oldSettings&&typeof oldSettings==="object"&&"import/resolver"in oldSettings){migrated["settings"]={...oldSettings};suggestions.push("Resolver settings preserved - no changes needed")}const oldRules=oldConfig["rules"];if(oldRules&&typeof oldRules==="object"){const newRules={};Object.entries(oldRules).forEach(([ruleName,ruleConfig])=>{if(ruleName.startsWith("import/")){const ruleMappings={"import/no-unresolved":"import-next/no-unresolved","import/no-cycle":"import-next/no-cycle","import/no-self-import":"import-next/no-self-import","import/no-absolute-path":"import-next/no-absolute-path","import/no-dynamic-require":"import-next/no-dynamic-require","import/no-webpack-loader-syntax":"import-next/no-webpack-loader-syntax"};if(ruleMappings[ruleName]){newRules[ruleMappings[ruleName]]=ruleConfig;suggestions.push(`Migrated ${ruleName} \u2192 ${ruleMappings[ruleName]}`)}else{newRules[ruleName]=ruleConfig;warnings.push(`Rule ${ruleName} not automatically migrated - may need manual adjustment`)}}else{newRules[ruleName]=ruleConfig}});migrated["rules"]=newRules}return{migrated,warnings,suggestions}}function validateResolverConfig(settings){const errors=[];const warnings=[];const resolverSettings=settings["import/resolver"];if(!resolverSettings){warnings.push("No import/resolver settings found - using defaults");return{valid:true,errors,warnings}}if(typeof resolverSettings==="string"){if(!resolverSettings.trim()){errors.push("Resolver name cannot be empty")}}else if(Array.isArray(resolverSettings)){resolverSettings.forEach((item,index)=>{if(typeof item==="string"){if(!item.trim()){errors.push(`Resolver at index ${index} cannot be empty`)}}else if(typeof item==="object"&&item!==null){const entries=Object.entries(item);if(entries.length===0){errors.push(`Resolver object at index ${index} is empty`)}}else{errors.push(`Invalid resolver format at index ${index}`)}})}else if(typeof resolverSettings==="object"){Object.entries(resolverSettings).forEach(([name,config])=>{if(!name.trim()){errors.push("Resolver name cannot be empty")}if(typeof config!=="object"||config===null){errors.push(`Resolver ${name} config must be an object`)}})}else{errors.push("Resolver settings must be a string, array, or object")}return{valid:errors.length===0,errors,warnings}}
|
package/src/resolver/resolver.js
CHANGED
|
@@ -1,206 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MissingResolverPeerError = void 0;
|
|
4
|
-
exports.getResolverPerformanceMetrics = getResolverPerformanceMetrics;
|
|
5
|
-
exports.resolveModule = resolveModule;
|
|
6
|
-
exports.clearResolverCache = clearResolverCache;
|
|
7
|
-
const fs_1 = require("../node/fs");
|
|
8
|
-
const path_1 = require("../node/path");
|
|
9
|
-
const resolver_adapter_1 = require("./resolver-adapter");
|
|
10
|
-
const oxcResolverCache = new Map();
|
|
11
|
-
let factoryRef;
|
|
12
|
-
class MissingResolverPeerError extends Error {
|
|
13
|
-
name = 'MissingResolverPeerError';
|
|
14
|
-
}
|
|
15
|
-
exports.MissingResolverPeerError = MissingResolverPeerError;
|
|
16
|
-
function loadResolverFactory() {
|
|
17
|
-
if (factoryRef) {
|
|
18
|
-
return factoryRef;
|
|
19
|
-
}
|
|
20
|
-
try {
|
|
21
|
-
factoryRef = require('oxc-resolver')
|
|
22
|
-
.ResolverFactory;
|
|
23
|
-
}
|
|
24
|
-
catch (cause) {
|
|
25
|
-
throw new MissingResolverPeerError('Import resolution requires the optional peer dependency "oxc-resolver", ' +
|
|
26
|
-
'which is not installed. Install it alongside this plugin:\n\n' +
|
|
27
|
-
' npm install --save-dev oxc-resolver\n', { cause });
|
|
28
|
-
}
|
|
29
|
-
return factoryRef;
|
|
30
|
-
}
|
|
31
|
-
const tsconfigPathCache = new Map();
|
|
32
|
-
function findTsconfigPath(fromFile) {
|
|
33
|
-
const startDir = (0, path_1.getDirname)(fromFile);
|
|
34
|
-
const cached = tsconfigPathCache.get(startDir);
|
|
35
|
-
if (cached !== undefined) {
|
|
36
|
-
return cached;
|
|
37
|
-
}
|
|
38
|
-
const result = (0, fs_1.findFileUpward)('tsconfig.json', startDir);
|
|
39
|
-
let dir = startDir;
|
|
40
|
-
const root = (0, path_1.resolvePath)('/');
|
|
41
|
-
while (dir !== root) {
|
|
42
|
-
tsconfigPathCache.set(dir, result);
|
|
43
|
-
if (result && (0, path_1.getDirname)(result) === dir)
|
|
44
|
-
break;
|
|
45
|
-
const parent = (0, path_1.getDirname)(dir);
|
|
46
|
-
if (parent === dir)
|
|
47
|
-
break;
|
|
48
|
-
dir = parent;
|
|
49
|
-
}
|
|
50
|
-
return result;
|
|
51
|
-
}
|
|
52
|
-
function getOxcResolver(options, fromFile) {
|
|
53
|
-
const extensions = options.extensions || [
|
|
54
|
-
'.ts',
|
|
55
|
-
'.tsx',
|
|
56
|
-
'.js',
|
|
57
|
-
'.jsx',
|
|
58
|
-
'.d.ts',
|
|
59
|
-
'.json',
|
|
60
|
-
'.node',
|
|
61
|
-
];
|
|
62
|
-
const conditionNames = options.conditionNames || [
|
|
63
|
-
'import',
|
|
64
|
-
'require',
|
|
65
|
-
'node',
|
|
66
|
-
'default',
|
|
67
|
-
'types',
|
|
68
|
-
];
|
|
69
|
-
const mainFields = options.mainFields || ['module', 'main'];
|
|
70
|
-
const tsconfigPath = findTsconfigPath(fromFile);
|
|
71
|
-
const key = `${extensions.join(',')}|${conditionNames.join(',')}|${mainFields.join(',')}|${tsconfigPath || ''}`;
|
|
72
|
-
const cached = oxcResolverCache.get(key);
|
|
73
|
-
if (cached) {
|
|
74
|
-
return cached;
|
|
75
|
-
}
|
|
76
|
-
const resolverOptions = {
|
|
77
|
-
extensions,
|
|
78
|
-
conditionNames,
|
|
79
|
-
mainFields,
|
|
80
|
-
mainFiles: ['index'],
|
|
81
|
-
modules: ['node_modules'],
|
|
82
|
-
};
|
|
83
|
-
if (tsconfigPath) {
|
|
84
|
-
resolverOptions['tsconfig'] = {
|
|
85
|
-
configFile: tsconfigPath,
|
|
86
|
-
references: 'auto',
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
const ResolverFactory = loadResolverFactory();
|
|
90
|
-
const resolver = new ResolverFactory(resolverOptions);
|
|
91
|
-
oxcResolverCache.set(key, resolver);
|
|
92
|
-
return resolver;
|
|
93
|
-
}
|
|
94
|
-
function isCssImport(importPath) {
|
|
95
|
-
if (/\.(css|scss|sass|less|styl)$/i.test(importPath)) {
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
98
|
-
if (importPath.startsWith('./') || importPath.startsWith('../')) {
|
|
99
|
-
return !/\.\w+$/.test(importPath);
|
|
100
|
-
}
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
|
-
function resolveCssImport(importPath, fromFile) {
|
|
104
|
-
const fromDir = (0, path_1.getDirname)(fromFile);
|
|
105
|
-
if (importPath.startsWith('.')) {
|
|
106
|
-
const resolved = (0, path_1.resolvePath)(fromDir, importPath);
|
|
107
|
-
if ((0, fs_1.fileExistsSync)(resolved)) {
|
|
108
|
-
const stats = (0, fs_1.statSync)(resolved);
|
|
109
|
-
if (stats && stats.isFile()) {
|
|
110
|
-
return resolved;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
const cssExtensions = ['.css', '.scss', '.sass', '.less', '.styl'];
|
|
114
|
-
for (const ext of cssExtensions) {
|
|
115
|
-
const withExt = resolved + ext;
|
|
116
|
-
if ((0, fs_1.fileExistsSync)(withExt)) {
|
|
117
|
-
const stats = (0, fs_1.statSync)(withExt);
|
|
118
|
-
if (stats && stats.isFile()) {
|
|
119
|
-
return withExt;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
for (const ext of cssExtensions) {
|
|
124
|
-
const indexFile = (0, path_1.joinPath)(resolved, `index${ext}`);
|
|
125
|
-
if ((0, fs_1.fileExistsSync)(indexFile)) {
|
|
126
|
-
const stats = (0, fs_1.statSync)(indexFile);
|
|
127
|
-
if (stats && stats.isFile()) {
|
|
128
|
-
return indexFile;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return null;
|
|
134
|
-
}
|
|
135
|
-
function getResolverPerformanceMetrics() {
|
|
136
|
-
return [];
|
|
137
|
-
}
|
|
138
|
-
function resolveModule(importPath, fromFile, options = {}) {
|
|
139
|
-
try {
|
|
140
|
-
if (importPath.startsWith('.') &&
|
|
141
|
-
!(options.cssSupport && isCssImport(importPath))) {
|
|
142
|
-
const context = (0, path_1.getDirname)(fromFile);
|
|
143
|
-
const defaultExtensions = [
|
|
144
|
-
'.ts',
|
|
145
|
-
'.tsx',
|
|
146
|
-
'.js',
|
|
147
|
-
'.jsx',
|
|
148
|
-
'.d.ts',
|
|
149
|
-
'.json',
|
|
150
|
-
];
|
|
151
|
-
const extensions = options.extensions || defaultExtensions;
|
|
152
|
-
const resolved = (0, path_1.resolvePath)(context, importPath);
|
|
153
|
-
const exactStats = (0, fs_1.statSync)(resolved);
|
|
154
|
-
if (exactStats && exactStats.isFile()) {
|
|
155
|
-
return resolved;
|
|
156
|
-
}
|
|
157
|
-
for (const ext of extensions) {
|
|
158
|
-
if ((0, fs_1.fileExistsSync)(resolved + ext)) {
|
|
159
|
-
return resolved + ext;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
for (const ext of extensions) {
|
|
163
|
-
const indexFile = (0, path_1.joinPath)(resolved, `index${ext}`);
|
|
164
|
-
if ((0, fs_1.fileExistsSync)(indexFile)) {
|
|
165
|
-
return indexFile;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
if (options.resolverSettings) {
|
|
170
|
-
const externalResult = (0, resolver_adapter_1.resolveWithExternalResolvers)(importPath, fromFile, options.resolverSettings);
|
|
171
|
-
if (externalResult) {
|
|
172
|
-
return externalResult;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
if (options.cssSupport && isCssImport(importPath)) {
|
|
176
|
-
const cssResult = resolveCssImport(importPath, fromFile);
|
|
177
|
-
if (cssResult) {
|
|
178
|
-
return cssResult;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
const resolver = getOxcResolver(options, fromFile);
|
|
182
|
-
const context = (0, path_1.getDirname)(fromFile);
|
|
183
|
-
try {
|
|
184
|
-
const result = resolver.sync(context, importPath);
|
|
185
|
-
if (result && result.path) {
|
|
186
|
-
return result.path;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
catch {
|
|
190
|
-
}
|
|
191
|
-
return null;
|
|
192
|
-
}
|
|
193
|
-
catch (error) {
|
|
194
|
-
if (error instanceof MissingResolverPeerError) {
|
|
195
|
-
throw error;
|
|
196
|
-
}
|
|
197
|
-
return null;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
function clearResolverCache() {
|
|
201
|
-
for (const resolver of oxcResolverCache.values()) {
|
|
202
|
-
resolver.clearCache();
|
|
203
|
-
}
|
|
204
|
-
oxcResolverCache.clear();
|
|
205
|
-
tsconfigPathCache.clear();
|
|
206
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.MissingResolverPeerError=void 0;exports.getResolverPerformanceMetrics=getResolverPerformanceMetrics;exports.resolveModule=resolveModule;exports.clearResolverCache=clearResolverCache;const fs_1=require("../node/fs");const path_1=require("../node/path");const resolver_adapter_1=require("./resolver-adapter");const oxcResolverCache=new Map;let factoryRef;class MissingResolverPeerError extends Error{name="MissingResolverPeerError"}exports.MissingResolverPeerError=MissingResolverPeerError;function loadResolverFactory(){if(factoryRef){return factoryRef}try{factoryRef=require("oxc-resolver").ResolverFactory}catch(cause){throw new MissingResolverPeerError('Import resolution requires the optional peer dependency "oxc-resolver", which is not installed. Install it alongside this plugin:\n\n npm install --save-dev oxc-resolver\n',{cause})}return factoryRef}const tsconfigPathCache=new Map;function findTsconfigPath(fromFile){const startDir=(0,path_1.getDirname)(fromFile);const cached=tsconfigPathCache.get(startDir);if(cached!==void 0){return cached}const result=(0,fs_1.findFileUpward)("tsconfig.json",startDir);let dir=startDir;const root=(0,path_1.resolvePath)("/");while(dir!==root){tsconfigPathCache.set(dir,result);if(result&&(0,path_1.getDirname)(result)===dir)break;const parent=(0,path_1.getDirname)(dir);if(parent===dir)break;dir=parent}return result}function getOxcResolver(options,fromFile){const extensions=options.extensions||[".ts",".tsx",".js",".jsx",".d.ts",".json",".node"];const conditionNames=options.conditionNames||["import","require","node","default","types"];const mainFields=options.mainFields||["module","main"];const tsconfigPath=findTsconfigPath(fromFile);const key=`${extensions.join(",")}|${conditionNames.join(",")}|${mainFields.join(",")}|${tsconfigPath||""}`;const cached=oxcResolverCache.get(key);if(cached){return cached}const resolverOptions={extensions,conditionNames,mainFields,mainFiles:["index"],modules:["node_modules"]};if(tsconfigPath){resolverOptions["tsconfig"]={configFile:tsconfigPath,references:"auto"}}const ResolverFactory=loadResolverFactory();const resolver=new ResolverFactory(resolverOptions);oxcResolverCache.set(key,resolver);return resolver}function isCssImport(importPath){if(/\.(css|scss|sass|less|styl)$/i.test(importPath)){return true}if(importPath.startsWith("./")||importPath.startsWith("../")){return!/\.\w+$/.test(importPath)}return false}function resolveCssImport(importPath,fromFile){const fromDir=(0,path_1.getDirname)(fromFile);if(importPath.startsWith(".")){const resolved=(0,path_1.resolvePath)(fromDir,importPath);if((0,fs_1.fileExistsSync)(resolved)){const stats=(0,fs_1.statSync)(resolved);if(stats&&stats.isFile()){return resolved}}const cssExtensions=[".css",".scss",".sass",".less",".styl"];for(const ext of cssExtensions){const withExt=resolved+ext;if((0,fs_1.fileExistsSync)(withExt)){const stats=(0,fs_1.statSync)(withExt);if(stats&&stats.isFile()){return withExt}}}for(const ext of cssExtensions){const indexFile=(0,path_1.joinPath)(resolved,`index${ext}`);if((0,fs_1.fileExistsSync)(indexFile)){const stats=(0,fs_1.statSync)(indexFile);if(stats&&stats.isFile()){return indexFile}}}}return null}function getResolverPerformanceMetrics(){return[]}function resolveModule(importPath,fromFile,options={}){try{if(importPath.startsWith(".")&&!(options.cssSupport&&isCssImport(importPath))){const context2=(0,path_1.getDirname)(fromFile);const defaultExtensions=[".ts",".tsx",".js",".jsx",".d.ts",".json"];const extensions=options.extensions||defaultExtensions;const resolved=(0,path_1.resolvePath)(context2,importPath);const exactStats=(0,fs_1.statSync)(resolved);if(exactStats&&exactStats.isFile()){return resolved}for(const ext of extensions){if((0,fs_1.fileExistsSync)(resolved+ext)){return resolved+ext}}for(const ext of extensions){const indexFile=(0,path_1.joinPath)(resolved,`index${ext}`);if((0,fs_1.fileExistsSync)(indexFile)){return indexFile}}}if(options.resolverSettings){const externalResult=(0,resolver_adapter_1.resolveWithExternalResolvers)(importPath,fromFile,options.resolverSettings);if(externalResult){return externalResult}}if(options.cssSupport&&isCssImport(importPath)){const cssResult=resolveCssImport(importPath,fromFile);if(cssResult){return cssResult}}const resolver=getOxcResolver(options,fromFile);const context=(0,path_1.getDirname)(fromFile);try{const result=resolver.sync(context,importPath);if(result&&result.path){return result.path}}catch{}return null}catch(error){if(error instanceof MissingResolverPeerError){throw error}return null}}function clearResolverCache(){for(const resolver of oxcResolverCache.values()){resolver.clearCache()}oxcResolverCache.clear();tsconfigPathCache.clear()}
|
package/src/resolver.js
CHANGED
|
@@ -1,17 +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("./resolver/index"), 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("./resolver/index"),exports);
|
|
@@ -1,100 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BROWSER_ESCAPE_FLAG = void 0;
|
|
4
|
-
exports.readFlag = readFlag;
|
|
5
|
-
exports.createBrowserEscapeHatchRule = createBrowserEscapeHatchRule;
|
|
6
|
-
const rule_creator_1 = require("./rule-creator");
|
|
7
|
-
const messaging_1 = require("../messaging");
|
|
8
|
-
const sdk_api_key_rule_1 = require("./sdk-api-key-rule");
|
|
9
|
-
exports.BROWSER_ESCAPE_FLAG = 'dangerouslyAllowBrowser';
|
|
10
|
-
function isFlagProperty(prop) {
|
|
11
|
-
return (prop.type !== 'SpreadElement' &&
|
|
12
|
-
!prop.computed &&
|
|
13
|
-
((prop.key.type === 'Identifier' && prop.key.name === exports.BROWSER_ESCAPE_FLAG) ||
|
|
14
|
-
(prop.key.type === 'Literal' && prop.key.value === exports.BROWSER_ESCAPE_FLAG)));
|
|
15
|
-
}
|
|
16
|
-
function readFlag(options) {
|
|
17
|
-
const props = options.properties;
|
|
18
|
-
const index = props.findIndex(isFlagProperty);
|
|
19
|
-
if (index === -1) {
|
|
20
|
-
return props.some((prop) => prop.type === 'SpreadElement') ? 'unreadable' : 'absent';
|
|
21
|
-
}
|
|
22
|
-
for (let i = index + 1; i < props.length; i++) {
|
|
23
|
-
if (props[i].type === 'SpreadElement')
|
|
24
|
-
return 'unreadable';
|
|
25
|
-
}
|
|
26
|
-
const value = props[index].value;
|
|
27
|
-
if (value.type === 'Literal' && value.value === true)
|
|
28
|
-
return 'enabled';
|
|
29
|
-
if (value.type === 'Literal')
|
|
30
|
-
return 'absent';
|
|
31
|
-
return 'unreadable';
|
|
32
|
-
}
|
|
33
|
-
function createBrowserEscapeHatchRule(config) {
|
|
34
|
-
return (0, rule_creator_1.createRule)({
|
|
35
|
-
name: config.ruleName,
|
|
36
|
-
meta: {
|
|
37
|
-
type: 'problem',
|
|
38
|
-
docs: {
|
|
39
|
-
url: config.docsUrl,
|
|
40
|
-
description: `Forbid ${exports.BROWSER_ESCAPE_FLAG}, which exposes the ${config.vendor} API key to the client`,
|
|
41
|
-
cwe: 'CWE-522',
|
|
42
|
-
cvss: 8.6,
|
|
43
|
-
},
|
|
44
|
-
messages: {
|
|
45
|
-
browserKeyExposure: (0, messaging_1.formatLLMMessage)({
|
|
46
|
-
icon: messaging_1.MessageIcons.SECURITY,
|
|
47
|
-
issueName: `${config.vendor} API Key Exposed to the Browser`,
|
|
48
|
-
cwe: 'CWE-522',
|
|
49
|
-
owasp: 'A07:2021',
|
|
50
|
-
cvss: 8.6,
|
|
51
|
-
description: 'dangerouslyAllowBrowser lets the SDK run client-side, which ships the API key to every visitor',
|
|
52
|
-
severity: 'HIGH',
|
|
53
|
-
compliance: ['SOC2', 'PCI-DSS'],
|
|
54
|
-
fix: `Call ${config.vendor} from a server route and forward the result, so the key never leaves the server`,
|
|
55
|
-
documentationLink: config.documentationLink,
|
|
56
|
-
}),
|
|
57
|
-
},
|
|
58
|
-
schema: [],
|
|
59
|
-
},
|
|
60
|
-
defaultOptions: [],
|
|
61
|
-
create(context) {
|
|
62
|
-
let importsSdk = false;
|
|
63
|
-
const candidates = [];
|
|
64
|
-
function inspect(node, args) {
|
|
65
|
-
const options = args[0];
|
|
66
|
-
if (options?.type !== 'ObjectExpression')
|
|
67
|
-
return;
|
|
68
|
-
if (readFlag(options) === 'enabled')
|
|
69
|
-
candidates.push(node);
|
|
70
|
-
}
|
|
71
|
-
return {
|
|
72
|
-
ImportDeclaration(node) {
|
|
73
|
-
if ((0, sdk_api_key_rule_1.matchesModule)(String(node.source.value), config.modules))
|
|
74
|
-
importsSdk = true;
|
|
75
|
-
},
|
|
76
|
-
NewExpression(node) {
|
|
77
|
-
inspect(node, node.arguments);
|
|
78
|
-
},
|
|
79
|
-
CallExpression(node) {
|
|
80
|
-
if (node.callee.type === 'Identifier' &&
|
|
81
|
-
node.callee.name === 'require' &&
|
|
82
|
-
node.arguments[0]?.type === 'Literal' &&
|
|
83
|
-
typeof node.arguments[0].value === 'string' &&
|
|
84
|
-
(0, sdk_api_key_rule_1.matchesModule)(node.arguments[0].value, config.modules)) {
|
|
85
|
-
importsSdk = true;
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
inspect(node, node.arguments);
|
|
89
|
-
},
|
|
90
|
-
'Program:exit'() {
|
|
91
|
-
if (!importsSdk)
|
|
92
|
-
return;
|
|
93
|
-
for (const node of candidates) {
|
|
94
|
-
context.report({ node, messageId: 'browserKeyExposure' });
|
|
95
|
-
}
|
|
96
|
-
},
|
|
97
|
-
};
|
|
98
|
-
},
|
|
99
|
-
});
|
|
100
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.BROWSER_ESCAPE_FLAG=void 0;exports.readFlag=readFlag;exports.createBrowserEscapeHatchRule=createBrowserEscapeHatchRule;const rule_creator_1=require("./rule-creator");const messaging_1=require("../messaging");const sdk_api_key_rule_1=require("./sdk-api-key-rule");exports.BROWSER_ESCAPE_FLAG="dangerouslyAllowBrowser";function isFlagProperty(prop){return prop.type!=="SpreadElement"&&!prop.computed&&(prop.key.type==="Identifier"&&prop.key.name===exports.BROWSER_ESCAPE_FLAG||prop.key.type==="Literal"&&prop.key.value===exports.BROWSER_ESCAPE_FLAG)}function readFlag(options){const props=options.properties;const index=props.findIndex(isFlagProperty);if(index===-1){return props.some(prop=>prop.type==="SpreadElement")?"unreadable":"absent"}for(let i=index+1;i<props.length;i++){if(props[i].type==="SpreadElement")return"unreadable"}const value=props[index].value;if(value.type==="Literal"&&value.value===true)return"enabled";if(value.type==="Literal")return"absent";return"unreadable"}function createBrowserEscapeHatchRule(config){return(0,rule_creator_1.createRule)({name:config.ruleName,meta:{type:"problem",docs:{url:config.docsUrl,description:`Forbid ${exports.BROWSER_ESCAPE_FLAG}, which exposes the ${config.vendor} API key to the client`,cwe:"CWE-522",cvss:8.6},messages:{browserKeyExposure:(0,messaging_1.formatLLMMessage)({icon:messaging_1.MessageIcons.SECURITY,issueName:`${config.vendor} API Key Exposed to the Browser`,cwe:"CWE-522",owasp:"A07:2021",cvss:8.6,description:"dangerouslyAllowBrowser lets the SDK run client-side, which ships the API key to every visitor",severity:"HIGH",compliance:["SOC2","PCI-DSS"],fix:`Call ${config.vendor} from a server route and forward the result, so the key never leaves the server`,documentationLink:config.documentationLink})},schema:[]},defaultOptions:[],create(context){let importsSdk=false;const candidates=[];function inspect(node,args){const options=args[0];if(options?.type!=="ObjectExpression")return;if(readFlag(options)==="enabled")candidates.push(node)}return{ImportDeclaration(node){if((0,sdk_api_key_rule_1.matchesModule)(String(node.source.value),config.modules))importsSdk=true},NewExpression(node){inspect(node,node.arguments)},CallExpression(node){if(node.callee.type==="Identifier"&&node.callee.name==="require"&&node.arguments[0]?.type==="Literal"&&typeof node.arguments[0].value==="string"&&(0,sdk_api_key_rule_1.matchesModule)(node.arguments[0].value,config.modules)){importsSdk=true;return}inspect(node,node.arguments)},"Program:exit"(){if(!importsSdk)return;for(const node of candidates){context.report({node,messageId:"browserKeyExposure"})}}}}})}
|