Skip to content

Unicode 202E vuln fix #382

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

Closed
wants to merge 2 commits into from
Closed
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
3 changes: 3 additions & 0 deletions src/match/url-match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ export class UrlMatch extends Match {
getAnchorHref() {
let url = this.getUrl();

//Strip malicious Unicode SNYK-AUTOLINKER-2438289
url.replace('\u202E', '');
Copy link

@bassammaged bassammaged Aug 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I suggest Strip the most RTLO common format U+202E and %E2%80%AE beside \u202E

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should also be replaced globally with /\u202E/g

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would that be immune to ReDoS?

https://en.wikipedia.org/wiki/ReDoS

Copy link
Owner

@gregjacobs gregjacobs Aug 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, not sure how this would actually fix the issue because the code isn't re-assigning the replacement result back to url. The code would need to be:

url = url.replace(/\u202E/g, '');

Does your new test pass even without this new line of code?

Copy link

@xfournet xfournet Sep 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

even after correction of the test (see remark in autolinker-url.spec.ts) the test is failing whatever the changes here:

  • with this line
  • with the update line according greg comment
  • without this line

in my observation the \u202e char is never reaching this method because of parseHtml


return url.replace(/&/g, '&'); // any &'s in the URL should be converted back to '&' if they were displayed as & in the source html
}

Expand Down
9 changes: 8 additions & 1 deletion tests/autolinker-url.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1203,8 +1203,15 @@ describe('Autolinker Url Matching -', () => {
);
});

describe('unicode exploits', () => {
it('should strip out Right-To-Left Override Unicode characters for security', () => {
var result = autolinker.link('https://legit.ok/files\u202E4pm.asia');
expect(result).toBe('<a href="https://legit.ok/files4pm.asia"></a>');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the expected result should be '<a href="https://legit.ok/files4pm.asia">legit.ok/files4pm.asia</a>'

});
});

describe('combination example', () => {
it(`should automatically link all of the URLs of many different forms`, () => {
it('should automatically link all of the URLs of many different forms', () => {
let inputStr = `
Joe went to http://yahoo.com and http://localhost today along with http://localhost:8000.
He also had a path on localhost: http://localhost:8000/abc, and a query string: http://localhost:8000?abc
Expand Down