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

fix: prevent linking text with directional change char #388

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yadue
Copy link
Contributor

@yadue yadue commented Sep 8, 2022

This PR would disable linking for urls with directional change characters

Fixes #377

@dbrgn
Copy link

dbrgn commented Sep 8, 2022

Hmm, this isn't the worst idea, and is much better than stripping characters. It would mean however that people putting URLs in the middle of text in Arabic or Hebrew will not get linked URLs at all. (Not saying this isn't viable, but if this solution is accepted then at least a warning should be shown about this.)

@@ -110,6 +110,10 @@ export function isDomainLabelChar(char: string): boolean {
return char === '_' || isDomainLabelStartChar(char);
}

export function hasDirectionalChar(char: string) {
Copy link
Owner

@gregjacobs gregjacobs Sep 8, 2022

Choose a reason for hiding this comment

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

Minor, but can we rename this to isDirectionOverrideChar, and add a jsdoc comment above it explaining why it's used?

Can add a link for #377 too inside the jsdoc to point developers to the original issue that this new function solves

@@ -1032,6 +1032,13 @@ describe('Autolinker Url Matching >', () => {
});
});

describe('unicode exploits', () => {
fit('text with directional change characters should not be linked', () => {
Copy link
Owner

Choose a reason for hiding this comment

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

Careful: fit -> it

describe('unicode exploits', () => {
fit('text with directional change characters should not be linked', () => {
expect(autolinker.link('foo.com\u202Ebar.com')).toBe('foo.com\u202Ebar.com');
expect(autolinker.link('foo.com\u202Emoc.rab')).toBe('foo.com\u202Emoc.rab');
Copy link
Owner

Choose a reason for hiding this comment

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

In addition to the domain name tests here, we should add tests for when the \u202E char appears in the path, query string, and hash sections of the URL.

Also, can we add tests for each of the direction override chars like you had in #386?

@gregjacobs
Copy link
Owner

Hey @yadue, I mentioned in #377 but should mention it here too: would you like to take a stab at URL-encoding the RTLO chars rather than rejecting the match? This might end up being our ideal solution. Thoughts?

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.

Autolinker vulnerable to RTLO URL spoofing attacks
3 participants