Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions __tests__/resolvers/exotics/registry-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,22 @@ test('resolves scoped yarn: package', () => {

expect(resolver.name).toEqual('@org/foo');
});

describe('RegistryResolver DOS regression test', () => {
const MAX_MS = 200;

test('long fragment without # should finish quickly and throw', () => {
const fragment = '\u0000' + '\u0000:'.repeat(100000) + '\n1\n';
const reqWithReporter: any = {
reporter: {lang: (_key, frag) => `invalidFragment: ${String(frag).slice(0, 16)}...`},
};

const start = Date.now();
expect(() => {
new RegistryResolver((reqWithReporter: any), fragment);
}).toThrow(MessageError);
const duration = Date.now() - start;

expect(duration).toBeLessThan(MAX_MS);
});
});
2 changes: 1 addition & 1 deletion src/resolvers/exotics/registry-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class RegistryResolver extends ExoticResolver {
constructor(request: PackageRequest, fragment: string) {
super(request, fragment);

const match = fragment.match(/^(\S+):(@?.*?)(@(.*?)|)$/);
const match = fragment.match(/^(\S+):(@?(?:(?![@:]).)*?)(@((?:(?![@:]).)*?)|)$/);
if (match) {
this.range = match[4] || 'latest';
this.name = match[2];
Expand Down