-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
web link addon doesn't parse URLs containing %20
properly
#4934
Comments
Thx for finding this edge case, its indeed not covered currently. Would an additional clause w'o the Background on the weird looking additional check - Whether that additional test is really needed or a sloppier handling would be sufficient - idk for sure. I normally try to go with security first, and since we outsource the URL construction to the browser with |
Not sure if I understand what you're proposing :) Can you give an example? I think what we could do is to test only the if (!text.startsWith(url.origin)) {
continue
} What do you think? Additionally I think having some counter-examples to test with would be a good idea, like, in what situations does the regex matches, but |
Sure, something like this (could be nicer formatted 😅 ): try {
const url = new URL(text);
const urlText = url.toString(); // maybe url.href is better here?
const urlTextDecoded = decodeURI(url.toString());
if (text !== urlText
&& text + '/' !== urlText
&& text !== urlTextDecoded
&& text + '/' != urlTextDecoded)
{
continue;
}
} catch (e) {
continue;
} You are prolly right with your function urlLeftSide(url: URL) {
if (url.password && url.username)
return `${url.protocol}//${url.username}:${url.password}@${url.host}`;
if (url.username)
return `${url.protocol}//${url.username}@${url.host}`;
return `${url.protocol}//${url.host}`;
}
...
if (!text.startsWith(urlLeftSide(url))) {
continue
} (Not quite sure if this will treat IPv6 urls correctly, it most likely does...) Blacklist testing would be awesome, plz feel free to add test cases for that. Currently its only whitelist tested. |
Good point, this seems to work, should I submit a PR?
It does seem fine, yes.
Yea I just can't come up with a URL that goes through the regex, but that should be blacklisted 😅 |
That would be nice, sure. 😺
Yeah that would need some reverse engineering from the |
Great, thank you -- submitted the PR here: #4937 |
https://github.com/xtermjs/xterm.js/blob/master/addons/addon-web-links/src/WebLinkProvider.ts seems to break on URLs containing
%20
(and other UTF-8-encoded symbols).The issue comes from this line:
https://github.com/xtermjs/xterm.js/blob/master/addons/addon-web-links/src/WebLinkProvider.ts#L68
decodeURI
decodes%20
so a URL likehttp://test.com?param=a%20b
gets decoded tohttp://test.com?param=a b
, which makes thetext
not equal tourlText
.I'd be happy to approach fixing this and sending a PR, but I'm honestly not sure what this test is protecting us from -- in which case
new URL(text)
would succeed buttext
would not beurlText
and that wouldn't be a false positive?Details
(I don't think this matters for this specific bug)
Steps to reproduce
echo "http://test.com"; echo "http://test.com?param=a%20b"
The text was updated successfully, but these errors were encountered: