Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execution times with double star syntax and dashes #121

Open
lenovouser opened this issue Oct 4, 2023 · 0 comments
Open

Execution times with double star syntax and dashes #121

lenovouser opened this issue Oct 4, 2023 · 0 comments

Comments

@lenovouser
Copy link

Platform: macOS
Architecture: arm64
Node: v18.18.0

The double-star syntax is unnecessary, since it also works with a single star, but I still want to report this to hopefully get it fixed.

If you execute the code below:

  • Example 1 runs fine
  • Example 2 takes about 20 seconds
  • Example 3 never ends and freezes the event loop completely (not entirely sure, but it seems like it) - including HTTP servers running in the same process. In case you make the mistake to have double stars somewhere in your patterns this makes your service extremely vulnerable to DOS attacks.
const { URLPattern } = require('urlpattern-polyfill');

const pattern = new URLPattern({ hostname: '**.google.com' });

const check = value => {
    if (pattern.test(value)) {
        return;
    }

    return value;
};

const start1 = process.hrtime.bigint();
const result1 = check('https://example.com');
const end1 = process.hrtime.bigint();

console.log(result1);
console.log('took ' + (end1 - start1) / 1000n + 'ms');

const start2 = process.hrtime.bigint();
const result2 = check('https://subdomain.subdomain.example.com');
const end2 = process.hrtime.bigint();

console.log(result2);
console.log('took ' + (end2 - start2) / 1_000_000n + 's');

const start3 = process.hrtime.bigint();
const result3 = check('https://dash-subdomain.subdomain.example.com');
const end3 = process.hrtime.bigint();

console.log(result3);
console.log('took ' + (end3 - start3) / 1_000_000n + 's');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant