Skip to content

Commit 4f8e4d2

Browse files
committed
Fix dangerous bare wildcard security issue
Prevent '*' pattern from matching all modules, which would disable dependency analysis and create security vulnerabilities. - Add safety check for bare wildcard patterns - Add comprehensive test coverage for security edge cases - Ensure valid wildcard patterns still work correctly
1 parent 0832edd commit 4f8e4d2

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/core/importType.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ function isInternalRegexMatch(name, settings) {
2424
}
2525

2626
function matchesCoreModulePattern(name, pattern) {
27+
// Prevent dangerous bare wildcard patterns
28+
if (pattern === '*') {
29+
return false;
30+
}
31+
2732
const regexPattern = pattern
2833
.replace(/[.+^${}()|[\]\\]/g, '\\$&')
2934
.replace(/\*/g, '.*');

tests/src/core/importType.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,21 @@ describe('importType(name)', function () {
183183
expect(importType('@other/package', mixedContext)).to.equal('external');
184184
});
185185

186+
it('should handle dangerous bare wildcard patterns safely', function () {
187+
const bareWildcardContext = testContext({ 'import/core-modules': ['*'] });
188+
189+
// A bare wildcard should NOT match everything - this would be dangerous
190+
expect(importType('react', bareWildcardContext)).to.equal('external');
191+
expect(importType('lodash', bareWildcardContext)).to.equal('external');
192+
expect(importType('@babel/core', bareWildcardContext)).to.equal('external');
193+
expect(importType('any-random-package', bareWildcardContext)).to.equal('external');
194+
195+
// However, valid wildcard patterns should still work
196+
const validWildcardContext = testContext({ 'import/core-modules': ['@my-org/*'] });
197+
expect(importType('@my-org/package', validWildcardContext)).to.equal('builtin');
198+
expect(importType('react', validWildcardContext)).to.equal('external');
199+
});
200+
186201
it("should return 'external' for module from 'node_modules' with default config", function () {
187202
expect(importType('resolve', context)).to.equal('external');
188203
});

0 commit comments

Comments
 (0)