# CVE-2021-4231: Angular XSS via HTML comment handling

Source: https://junglewise.ai/threats/cve-2021-4231-angular-xss-via-html-comment-handling  
Publisher: Junglewise Threat Intelligence, https://junglewise.ai/threats  
Published: 2022-05-27. Updated: 2026-09-25  
License: CC BY 4.0 with a link back

CVE-2021-4231 · Severity: low · CVSS 3.1 · Published 2022-05-27

Angular, a popular web framework used to build dynamic web applications, is vulnerable to Cross-Site Scripting (XSS) attacks through improper handling of HTML comments. An attacker with application access can inject malicious scripts into comments, potentially allowing them to execute code in other users' browsers and steal sensitive data or perform unauthorized actions.

Technologies: [@angular/core (npm)](https://junglewise.ai/threats/technologies/angular-core). Vendors: [npm](https://junglewise.ai/threats/vendors/npm).

## Quick answers

**Is CVE-2021-4231 exploited in the wild?** No. Junglewise Threat Intelligence has no report of CVE-2021-4231 being exploited in the wild.

**How severe is CVE-2021-4231?** Low severity, with a CVSS score of 3.1, published 27 May 2022.

**Which products and versions are affected?** @angular/core (npm) SEMVER:introduced=11.0.0,fixed=11.0.5.

**Is there a fix for CVE-2021-4231?** Yes. @angular/core (npm): upgrade to 11.0.5 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.

**How is CVE-2021-4231 attacked?** It is attacked over the network.

**Am I affected by CVE-2021-4231?** Check whether you run @angular/core (npm) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

## How to fix

- @angular/core (npm): upgrade to 11.0.5 or later

  ```sh
  npm install @angular/core@11.0.5
  ```


## Technical details

The vulnerability is a Cross-Site Scripting (CWE-79) flaw in Angular's comment handling logic. The root cause is improper escaping of content inserted into HTML comment nodes; attackers can craft specially-formed strings that break out of comment delimiters ("--&gt;") despite the lack of standard HTML escaping mechanisms. The attack requires authentication and user interaction to exploit. An attacker can inject malicious JavaScript that executes in the context of other users' browsers, potentially leading to session hijacking, credential theft, or data exfiltration. Patches are available in Angular versions 10.2.5, 11.0.5, and 11.1.0-next.3.

## Affected products

- Google Angular up to 11.0.4, 11.1.0-next.2, and prior versions

## Identifiers

- CVE-2021-4231
- GHSA-c75v-2vq8-878f

## Timeline

- 2022-05-26: disclosed: NVD published date
- 2022-05-27: patched: Advisory released; patches available in v10.2.5, v11.0.5, v11.1.0-next.3

## References

- [https://github.com/angular/angular/issues/40136](https://github.com/angular/angular/issues/40136)

## Related threats

- [Angular sanitization bypass in directive host bindings](https://junglewise.ai/threats/cve-2026-88057-angular-sanitization-bypass-in-directive-host-bindings)
- [Angular i18n Cross-Site Scripting via event-handler attributes](https://junglewise.ai/threats/cve-2026-69151-angular-i18n-cross-site-scripting-via-event-handler-attributes)
- [Google Angular DOM Clobbering in Client Hydration](https://junglewise.ai/threats/cve-2026-54267-google-angular-dom-clobbering-in-client-hydration)
- [Angular XSS via dynamic component mounting on script elements](https://junglewise.ai/threats/cve-2026-52725-angular-xss-via-dynamic-component-mounting-on-script-elements)
- [Google Angular XSS bypass via namespaced elements and attributes](https://junglewise.ai/threats/cve-2026-50557-google-angular-xss-bypass-via-namespaced-elements-and-attributes)
