Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix(linky): handle the double quote character in email addresses #8964

Closed
wants to merge 1 commit into from

Conversation

lgalfaso
Copy link
Contributor

@lgalfaso lgalfaso commented Sep 5, 2014

Handle the double quote character as part of the domain in email addresses

Closes #8945

Handle the double quote character as part of the domain
in email addresses

Closes angular#8945
@lorenzhs
Copy link

I can confirm that this fixes #9256 in that no exception is raised, but the linkification isn't optimal

@lgalfaso
Copy link
Contributor Author

@lorenzhs I agree that the linkification is not optimal. This patch is not about fixing the regex that is used for emails or URLs, just about not generating an exception when quotes are part of what will end up being linkified

@lorenzhs
Copy link

@lgalfaso Yes, absolutely. Linkification can be optimised later on, but raising an exception on a valid input is a lot worse.

@IgorMinar
Copy link
Contributor

I don't think that this fixes #8945.

I think the right thing to do in the example provided in that issue is not to translate that snippet of text into a link.

@IgorMinar IgorMinar modified the milestones: Purgatory, 1.3.0 Oct 7, 2014
@lgalfaso
Copy link
Contributor Author

lgalfaso commented Oct 7, 2014

@IgorMinar this fixes a potential security issue. If tomorrow the regex is changed so it accepts spaces and quotes (for whatever reason) then

Valid case

This is some text, and we enhanced the email regex so it is able to accept comments in the email
foo@(comment goes here)bar.com

would get transformed to

This is some text, and we enhanced the email regex so it is able to accept comments in the email
<a href="mailto:foo@(comment goes here)bar.com">foo@(comment goes here)bar.com</a>

but

foo@(comment" onclick="alert(1);" id="goes here)bar.com

would get transformed to

<a href="foo@(comment" onclick="alert(1);" id="goes here)bar.com">foo@(comment" onclick="alert(1);" id="goes here)bar.com</a>
foo@(comment" onclick="alert(1);" id="goes here)bar.com

Fixing the regex is another issue (the same can be said by URLs)

@jeffbcross jeffbcross force-pushed the master branch 3 times, most recently from 8292c21 to 7b9fddf Compare October 9, 2014 20:43
@@ -142,7 +142,7 @@ angular.module('ngSanitize').filter('linky', ['$sanitize', function($sanitize) {
html.push('" ');
}
html.push('href="');
html.push(url);
html.push(url.replace('"', '&quot;'));
Copy link
Contributor

Choose a reason for hiding this comment

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

@lgalfaso - from what I read here - https://url.spec.whatwg.org/#url-parsing - we should be percent-encoding characters, rather than HTML encoding them. So the double quotes would be encoded as %22. Here is a link to the spec: http://tools.ietf.org/html/rfc3696#section-4.1

I was wondering if we should go a step further and percent encode all the non-URL code points, which includes ".

Copy link
Contributor

Choose a reason for hiding this comment

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

But otherwise, I think this is a good compromise before we try improve our email parsing, which I now see if rather complicated if you allow comments and quoted sections...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@petebacondarwin it is true that quotes need to be percent encoded, but if something reaches this point then we do not care what it is. We just have to put it inside an html attribute, where we need to encode the double quotes as this is a double-quotes attribute value http://www.w3.org/TR/html-markup/syntax.html#syntax-attr-double-quoted

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that the regex that we use to detect emails and urls need some help, I am not trying to fix that, I am just trying to make linky generate valid html so angular does not break for people that use linky with user content

Copy link
Contributor

Choose a reason for hiding this comment

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

So I think what you are saying is that since "Pete Bacon Darwin"@example.com is a valid email (even with unencoded double quotes) then this ought to be allowed as a value to be put into an anchor element's href attribute, and that when serializing this attribute we should only be HTML encoding it.

I am good with that. Let's go with this and then put out a PR Plz issue for better improving the email/URL identification in linky - perhaps looking at something like https://github.com/FogCreek/email-addresses

I'll merge.

@lgalfaso lgalfaso closed this in 8ee8ffe Nov 23, 2014
lgalfaso added a commit that referenced this pull request Nov 23, 2014
Email addresses can (under certain restrictions) include double quote
characters. See http://tools.ietf.org/html/rfc3696#section-3.

For example, `"Jo Bloggs"@abc.com` is a valid email address.

When serializing emails to the `href` attribute of an anchor element,
we must HTML encode these double quote characters. See
http://www.w3.org/TR/html-markup/syntax.html#syntax-attr-double-quoted

This commit does not attempt to improve the functionality (i.e. regex)
that attempts to identify email addresses in a general string.

Closes #8945
Closes #8964
Closes #5946
Closes #10090
Closes #9256
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Linky filter breaks with certain input
6 participants