-
-
Notifications
You must be signed in to change notification settings - Fork 62
perf: faster encode_url and decode_url
#441
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
base: master
Are you sure you want to change the base?
Conversation
lib/decode_url.ts
Outdated
|
|
||
| const decodeURL = (str: string) => { | ||
| if (parse(str).protocol) { | ||
| if (hasProtocolLikeNode(str)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are going to implement some loose check, why not just if (str.includes('://')?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am still not a fan of copying some regexp. How would we know if it is spec-compliant or not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This regexp is from nodejs https://github.com/nodejs/node/blob/a1244f04dea9148c44fd6daf60b5105f7a85ea12/lib/url.js#L96, and it is stricter than the one in RFC 3986 (https://www.rfc-editor.org/rfc/rfc3986#appendix-B). The regex in RFC 3986 is /^(([^:/?#]+):)/.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But whathappened if Node.js changes their implementation (maybe a ReDoS attack is discovered, maybe a CSRF PoC is created, and there is a new CVE created), how can we make sure our copied regexp is up to date?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there is such a concern, let's consider a less radical optimization method.

check list
Description
close #439
Additional information