CVE-2021-38186
Description
An issue was discovered in the comrak crate before 0.10.1 for Rust. It mishandles & characters, leading to XSS via &# HTML entities.
AI Insight
LLM-synthesized narrative grounded in this CVE's description and references.
Comrak Rust crate before 0.10.1 mishandles & characters, allowing XSS via crafted HTML entities.
Vulnerability
The comrak crate (a CommonMark and GFM Markdown parser/renderer) before version 0.10.1 mishandles & characters, leading to cross-site scripting (XSS) via &# HTML entities [1][2]. The bug exists in the HTML entity parsing logic, allowing an attacker to inject arbitrary HTML/JavaScript when user-supplied Markdown is rendered.
Exploitation
An attacker can craft Markdown input containing malicious &# sequences that bypass sanitization. No special privileges are required; the attacker only needs to submit the crafted Markdown to an application using the vulnerable comrak version. The parser incorrectly processes these entities, resulting in the injection of arbitrary HTML attributes or script tags.
Impact
Successful exploitation leads to stored or reflected XSS, depending on the application context. The attacker can execute arbitrary JavaScript in the victim's browser, potentially stealing cookies, session tokens, or performing actions on behalf of the user. The vulnerability affects all uses of comrak before 0.10.1.
Mitigation
The issue is fixed in comrak version 0.10.1, released on May 4, 2021 [3][4]. Users should upgrade to 0.10.1 or later. No workarounds are documented; upgrading is the recommended action.
AI Insight generated on May 21, 2026. Synthesized from this CVE's description and the cited reference URLs; citations are validated against the source bundle.
Affected packages
Versions sourced from the GitHub Security Advisory.
| Package | Affected versions | Patched versions |
|---|---|---|
comrakcrates.io | < 0.10.1 | 0.10.1 |
Affected products
2- comrak/comrakdescription
Patches
1b72340cabe47SECURITY: escape ampersands in hrefs
2 files changed · +9 −1
src/html.rs+1 −1 modified@@ -275,7 +275,7 @@ impl<'o> HtmlFormatter<'o> { lazy_static! { static ref HREF_SAFE: [bool; 256] = { let mut a = [false; 256]; - for &c in b"-_.+!*'(),%#@?=;:/,+&$~abcdefghijklmnopqrstuvwxyz".iter() { + for &c in b"-_.+!*(),%#@?=;:/,+$~abcdefghijklmnopqrstuvwxyz".iter() { a[c as usize] = true; } for &c in b"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".iter() {
src/tests.rs+8 −0 modified@@ -421,6 +421,14 @@ fn reference_links() { ); } +#[test] +fn link_entity_regression() { + html( + "[link](javascript:alert('XSS'))", + "<p><a href=\"&#x6A&#x61&#x76&#x61&#x73&#x63&#x72&#x69&#x70&#x74&#x3A&#x61&#x6C&#x65&#x72&#x74&#x28&#x27&#x58&#x53&#x53&#x27&#x29\">link</a></p>\n", + ); +} + #[test] fn strikethrough() { html_opts!(
Vulnerability mechanics
Generated on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.
References
7- github.com/advisories/GHSA-6wj2-g87r-pm62ghsaADVISORY
- nvd.nist.gov/vuln/detail/CVE-2021-38186ghsaADVISORY
- github.com/kivikakk/comrak/commit/b72340cabe4749952530b4fb6b4fcc706bc973e5ghsaWEB
- github.com/kivikakk/comrak/compare/0.10.0...0.10.1ghsaWEB
- github.com/kivikakk/comrak/releases/tag/0.10.1ghsaWEB
- raw.githubusercontent.com/rustsec/advisory-db/main/crates/comrak/RUSTSEC-2021-0063.mdmitrex_refsource_MISC
- rustsec.org/advisories/RUSTSEC-2021-0063.htmlghsax_refsource_MISCWEB
News mentions
0No linked articles in our index yet.