Code Monkey home page Code Monkey logo

Comments (6)

Jawvig avatar Jawvig commented on August 16, 2024

This is unlikely to change the result, but I did note in RFC 2368 that the comma should apparently be encoded. See http://www.ietf.org/rfc/rfc2368.txt and in particular the example at the end of page 1.

From: Alexander [mailto:[email protected]]
Sent: 07 August 2015 17:38
To: mganss/HtmlSanitizer [email protected]
Subject: [HtmlSanitizer] Throws exception on multiple recipients in a email. (#41)

Sanitize the following html with enabled mailto: scheme:

Bang Bang

Actual:

System.UriFormatException : Invalid URI: The hostname could not be parsed.
at System.Uri.CreateHostStringHelper(String str, UInt16 idx, UInt16 end, ref Flags flags, ref String scopeId)
at System.Uri.CreateHostString()
at System.Uri.GetComponentsHelper(UriComponents uriComponents, UriFormat uriFormat)
at System.Uri.GetComponents(UriComponents components, UriFormat format)
at System.Uri.get_AbsoluteUri()
at Ganss.XSS.HtmlSanitizer.SanitizeUrl(String url, String baseUrl)
at Ganss.XSS.HtmlSanitizer.Sanitize(String html, String baseUrl, IOutputFormatter outputFormatter)

Expected:
No exception is thrown.


Reply to this email directly or view it on GitHub #41 . https://github.com/notifications/beacon/AAdzyfApWqVifRBd-YwDFboS6sleQdlcks5olNaDgaJpZM4Fnq7y.gif

from htmlsanitizer.

304NotModified avatar 304NotModified commented on August 16, 2024

I think HtmlSanitizer should "eat" the exception?

from htmlsanitizer.

shivinsky avatar shivinsky commented on August 16, 2024

@Jawvig seems like System.Uri is not very consistent. For example, I could not reproduce the same behaviour for http: scheme.
So, I agree with @304NotModified. Probably, ignoring exception and stripping "invalid" href is way to go.

from htmlsanitizer.

304NotModified avatar 304NotModified commented on August 16, 2024

Some info about the (annoying) system uri. See #8
http://blogs.msdn.com/b/ncl/archive/2010/02/23/system-uri-f-a-q.aspx

from htmlsanitizer.

304NotModified avatar 304NotModified commented on August 16, 2024

Ps @mganss great covery results!

from htmlsanitizer.

mganss avatar mganss commented on August 16, 2024

@Jawvig RFC 2368 was superseded by RFC 6068 which allows unencoded commas:

mailtoURI    = "mailto:" [ to ] [ hfields ]
to           = addr-spec *("," addr-spec )
...

In .NET 4.5 and above no exception is thrown because Uri.TryCreate() returns false and the URI is stripped. But of course this means that System.Uri is currently not compliant with RFC 6068 and Microsoft doesn't seem to have the intention to fix it soon: https://connect.microsoft.com/VisualStudio/feedback/details/794758/system-uri-incorrectly-rejects-mailto-uris

I agree that the best way to deal with this issue is to catch the exception and strip the URI although it's legal. If someone insisted on keeping these kinds of URIs, they'd have to handle RemovingAttribute and check the URI themselves.

@304NotModified Thanks 😄

from htmlsanitizer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.