If you’re still migrating an old AngularJS app to modern Angular with @angular/upgrade, there’s a security fix to apply. On 3 December 2026 the Angular team published advisory GHSA-xv7p-c2jx-4fj7, a cross-site scripting (XSS) flaw in downgradeComponent(). It’s rated Moderate (CVSS v4 6.3) and is an incomplete fix for an earlier advisory, GHSA-ffj9-42qx-f38h.
The patched releases are 22.3.2, 21.2.27 and 20.3.36. Angular 19 and earlier are past end of support and won’t be patched. This post explains who’s affected, how the attack works, how to upgrade, and what to do if you can’t upgrade straight away.
Are you affected?
Only hybrid applications are at risk. All three of these must be true:
- You use
downgradeComponent()from@angular/upgradeto render Angular components inside AngularJS templates. - An AngularJS directive writes into the downgraded component’s host element before Angular reads it. That includes a directive on the same element with
priority > 0(such asng-controller, at priority 500), a directive at priority 0 whose name sorts alphabetically before your component’s, or an ancestor directive’scontrollerorpreLinkhook that changes the host element. - What it writes includes untrusted user input.
Pure Angular apps that don’t use @angular/upgrade aren’t affected. Production AOT builds are affected, because the dangerous evaluation happens in AngularJS’s $compile(), not Angular’s compiler.
Affected and patched versions
| Line | Affected | Fixed in |
|---|---|---|
| 22.x | 22.0.0 to below 22.3.2 | 22.3.2 |
| 21.x | 21.0.0 to below 21.2.27 | 21.2.27 |
| 20.x | 20.0.0 to below 20.3.36 | 20.3.36 |
| 19.x and older | up to 19.2.25 | not patched (end of support) |
How the attack works
downgradeComponent() captures the host element’s child nodes so it can project them into your Angular component. Those nodes are later passed through AngularJS’s $compile(). Any {{ ... }} interpolation in them runs as an AngularJS expression.
The earlier fix moved that capture into the directive’s controller, assuming it runs before anything else touches the element. But AngularJS creates controllers during linking. Directives with a higher priority, or ancestor hooks, can still run first. If one of them writes user data into the host, even with “safe” APIs like $element.text(), the data is captured and compiled.
The advisory’s example is a typical hybrid pattern:
angular.module('hybridApp', [])
.directive('userBadge', downgradeComponent({ component: UserBadge }))
.directive('commentText', () => ({
restrict: 'A',
priority: 10,
controller: ['$element', function ($el) {
$el.text(userText); // userText comes from a user
}],
}));
<user-badge comment-text></user-badge>
If userText contains an AngularJS expression such as {{constructor.constructor('alert(document.domain)')()}}, it runs in the victim’s browser. The attacker can then act as the user on your origin, which is classic stored or reflected XSS.
Fix 1: upgrade (recommended)
Upgrade @angular/upgrade to the patched release for your major version. Keep all @angular/* packages on the same version, so use ng update or update them together:
# Angular 22
ng update @angular/[email protected] @angular/cli
# or update the packages directly
npm install @angular/[email protected] @angular/[email protected] @angular/[email protected] \
@angular/[email protected] @angular/[email protected]
# Angular 21 LTS
npm install @angular/[email protected] # plus the matching @angular/* packages
# Angular 20 LTS
npm install @angular/[email protected] # plus the matching @angular/* packages
Then confirm what’s installed:
npm ls @angular/upgrade @angular/core
On npm today, latest is 22.3.2, v21-lts is 21.2.27 and v20-lts is 20.3.36.
What the patch changes
The fix moves template capture from the directive’s controller into its compile() phase, which runs before any linking or controller code. It then clones the captured fragment fresh for each link. Capture is skipped when a transclusion directive (like ng-transclude) is present, or when the host has no compilable child nodes. Content written dynamically is then projected directly, without going through $compile().
In normal hybrid apps this shouldn’t change behaviour. Still, after upgrading, click through screens where AngularJS directives share an element with a downgraded component, especially ones that use transclusion.
Fix 2: workarounds if you can’t upgrade today
The advisory lists two workarounds:
Move the directive off the host element. Put the content-writing directive on an inner child element instead:
<!-- before: vulnerable pattern -->
<user-badge comment-text></user-badge>
<!-- after: directive on a child element -->
<user-badge><span comment-text></span></user-badge>
Pass data as an Angular input instead of writing to the DOM. This is the cleaner approach, and it’s where your migration is heading anyway:
<user-badge [text]="userText"></user-badge>
import { Component, input } from '@angular/core';
@Component({
selector: 'user-badge',
template: `<span class="badge">{{ text() }}</span>`,
})
export class UserBadge {
text = input('');
}
Angular’s own interpolation escapes the value, and nothing passes through AngularJS $compile().
Also, don’t change a downgraded component’s host contents from an ancestor’s controller or preLink hook.
How to find risky code quickly
Search your AngularJS code for downgraded components and for directives that write to $element:
grep -rn "downgradeComponent" src/
grep -rnE "\\\$element\.(text|html|append|prepend)\(|\.textContent\s*=" src/
grep -rn "priority:" src/
Then check each downgraded component’s template: does any directive on the same tag, or on an ancestor, write user-controlled data into it?
If you’re on Angular 19 or older
No patch is coming. Your options are the workarounds above, a commercial long-term support vendor, or upgrading to a supported major version. Combine the workarounds with a strict Content Security Policy to limit damage. But note that AngularJS expression evaluation doesn’t need inline scripts, so CSP alone won’t stop this.
Takeaway
Hybrid AngularJS/Angular apps should upgrade @angular/upgrade to 22.3.2, 21.2.27 or 20.3.36 now. Until then, move content-writing directives off downgraded host elements, or pass data through Angular inputs. Pure Angular apps don’t need to do anything for this advisory, but it’s a good reminder to finish that migration.
