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

Unicode 202E vuln fix #382

Closed
wants to merge 2 commits into from
Closed

Unicode 202E vuln fix #382

wants to merge 2 commits into from

Conversation

Gilgahex
Copy link

@Gilgahex Gilgahex commented Aug 2, 2022

I even added a test, wow TDD works!

@@ -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

Update so we can just merge everything
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>'

@gregjacobs
Copy link
Owner

Hey @Gilgahex, went with another PR for the fix (#386). Thanks for contributing though!

@gregjacobs gregjacobs closed this Sep 7, 2022
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

Successfully merging this pull request may close these issues.

5 participants