Angular: Sanitization bypass via directive host bindings on concrete host elements in @angular/core and @angular/compiler
Affected releases · @angular/compiler
- 22.x22.0.0 – 22.0.8Fixed in 22.1.0
- 21.x21.0.0 – 21.2.19Fixed in 21.2.20
- 20.x20.0.0 – 20.3.27Fixed in 20.3.28
- 19.x19.0.0 – 19.2.25No fix on this line yet
- 18.x and older2.0.0 – 18.2.14No fix, no longer updated
On 22.x, the newest line:
npm install @angular/compiler@22.1.0Affected
22.0.0 – 22.0.8
9 releases
Fixed
22.1.0 – 22.2.3
13 releases, latest
Affected
21.0.0 – 21.2.19
37 releases
Fixed
21.2.20 – 21.2.25
6 releases
Affected
20.0.0 – 20.3.27
49 releases
Fixed
20.3.28 – 20.3.34
7 releases
Affected
19.0.0 – 19.2.25
43 releases
Affected
18.0.0 – 18.2.14
29 releases
Affected
17.0.0 – 17.3.12
32 releases
Affected
16.0.0 – 16.2.12
30 releases
Affected
15.0.0 – 15.2.10
22 releases
Affected
14.0.0 – 14.3.0
26 releases
Affected
13.0.0 – 13.4.0
30 releases
Affected
12.0.0 – 12.2.17
30 releases
Affected
11.0.0 – 11.2.14
28 releases
Affected
10.0.0 – 10.2.5
28 releases
Affected
9.0.0 – 9.1.13
22 releases
Affected
8.0.0 – 8.2.14
23 releases
Affected
7.0.0 – 7.2.16
27 releases
Affected
6.0.0 – 6.1.10
20 releases
Affected
5.0.0 – 5.2.11
22 releases
Affected
4.0.0 – 4.4.7
30 releases
Affected
2.0.0 – 2.4.10
24 releases
Affected releases · @angular/core
- 22.x22.0.0 – 22.0.8Fixed in 22.1.0
- 21.x21.0.0 – 21.2.19Fixed in 21.2.20
- 20.x20.0.0 – 20.3.27Fixed in 20.3.28
- 19.x19.0.0 – 19.2.25No fix on this line yet
- 18.x and older2.0.0 – 18.2.14No fix, no longer updated
On 22.x, the newest line:
npm install @angular/core@22.1.0Affected
22.0.0 – 22.0.8
9 releases
Fixed
22.1.0 – 22.2.3
13 releases, latest
Affected
21.0.0 – 21.2.19
37 releases
Fixed
21.2.20 – 21.2.25
6 releases
Affected
20.0.0 – 20.3.27
49 releases
Fixed
20.3.28 – 20.3.34
7 releases
Affected
19.0.0 – 19.2.25
43 releases
Affected
18.0.0 – 18.2.14
29 releases
Affected
17.0.0 – 17.3.12
32 releases
Affected
16.0.0 – 16.2.12
30 releases
Affected
15.0.0 – 15.2.10
22 releases
Affected
14.0.0 – 14.3.0
26 releases
Affected
13.0.0 – 13.4.0
30 releases
Affected
12.0.0 – 12.2.17
30 releases
Affected
11.0.0 – 11.2.14
28 releases
Affected
10.0.0 – 10.2.5
28 releases
Affected
9.0.0 – 9.1.13
22 releases
Affected
8.0.0 – 8.2.14
23 releases
Affected
7.0.0 – 7.2.16
27 releases
Affected
6.0.0 – 6.1.10
20 releases
Affected
5.0.0 – 5.2.11
22 releases
Affected
4.0.0 – 4.4.7
30 releases
Affected
2.0.0 – 2.4.10
24 releases
Is your project affected?
Paste your package.json, or type the range you declare for @angular/compiler. It is read in your browser and sent nowhere.
Is your project affected?
Paste your package.json, or type the range you declare for @angular/core. It is read in your browser and sent nowhere.
What happens
Angular automatically sanitizes untrusted values bound to security-sensitive DOM sinks (such as href, src, action, xlink:href, and data) to protect against Cross-Site Scripting (XSS).
Prior to the fix, the Angular compiler determined the SecurityContext for directive host bindings (host: {'[attr.href]': 'value'} or @HostBinding('attr.href')) based solely on the declaring directive or component selector at compile time, rather than the concrete host element that the directive was applied to.
When a directive with a security-sensitive host binding was applied to a different concrete host element—such as through:
hostDirectivescomposition,Class inheritance of host bindings,
Dynamic component instantiation (
createComponentwith customhostElementor dynamic directives),Elements with SVG/MathML namespaces (e.g.
<svg:a>,<math>), orElements using tag-neutral selectors (e.g.
:not(...)),
the compiler either failed to associate a sanitizer with the host binding or attached an incorrect security context. As a result, untrusted inputs (e.g. javascript:... URLs) bound via the host binding would be written to the DOM attribute without passing through Angular's built-in sanitizer.
Impact
An attacker capable of controlling the value bound to an affected directive host binding could execute arbitrary JavaScript in the user's browser context (Cross-Site Scripting).
Patches
This issue has been resolved in versions:
22.1.021.2.2020.3.28
Workarounds
Ensure that any user-controlled values assigned to properties bound via directive host bindings are explicitly sanitized using DomSanitizer.sanitize(SecurityContext.URL, ...) before assignment, or restrict the input to validated safe URL schemes (e.g. http://, https://).