GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(upgrade): only compile the template contents of a downgraded component by SkyZeroZx · Pull Request #71442 · angular/angular

Conversation

@SkyZeroZx

@SkyZeroZx SkyZeroZx commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Previously, a downgraded component compiled whatever its element contained when the component was created. By then, AngularJS could already have linked or written content into the element, for example through ng-transclude or ng-bind on it, and that content was compiled again.

The contents are now copied when the directive's controller is instantiated, before anything on the element is linked, and that copy is what gets compiled. If there is nothing to copy, whatever AngularJS put into the element is projected as it is, so content added by ng-transclude keeps the scope it was linked with.

Fixes #71441

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@angular-robot angular-robot Bot added the area: upgrade Issues related to AngularJS → Angular upgrade APIs label Oct 20, 2026
@ngbot ngbot Bot added this to the Backlog milestone Oct 20, 2026
@SkyZeroZx
SkyZeroZx marked this pull request as ready for review October 20, 2026 14:49
@pullapprove
pullapprove Bot requested a review from kirjs October 20, 2026 14:50
@SkyZeroZx
fix(upgrade): only compile the template contents of a downgraded comp…
6e1df9b
…onent

Previously, a downgraded component compiled whatever its element contained when the component was created. By then, AngularJS could already have linked or written content into the element, for example through `ng-transclude` or `ng-bind` on it, and that content was compiled again.

The contents are now copied when the directive's controller is instantiated, before anything on the element is linked, and that copy is what gets compiled. If there is nothing to copy, whatever AngularJS put into the element is projected as it is, so content added by `ng-transclude` keeps the scope it was linked with.

Fixes angular#71441
@SkyZeroZx
SkyZeroZx force-pushed the fix/upgrade-projected-content-compile branch from 1ed0ef7 to 6e1df9b Compare October 22, 2026 02:07
JeanMeche
JeanMeche reviewed Oct 23, 2026
View reviewed changes
Comment thread packages/upgrade/src/common/src/downgrade_component_adapter.ts

compileContents(): Node[][] {
compileContents(template: Node[]): Node[][] {
if (!template.length) {

@JeanMeche JeanMeche Oct 23, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AGENT: Using !template.length as a proxy to decide whether content was provided by ng-transclude is fragile and breaks in several common scenarios:

  1. Multi-line template formatting / whitespace:
    In real-world templates, tags are rarely collapsed into <ng2 ng-transclude></ng2>. If formatted across lines:

    <app-card ng-transclude>
    </app-card>

    element[0].childNodes contains a whitespace Text node ("\n "). As a result, template.length === 1, !template.length evaluates to false, and the else branch runs: this.element.empty!() completely wipes out the transcluded DOM nodes that ng-transclude just inserted, compiling and projecting the whitespace instead.

  2. ng-transclude with fallback/default content:
    If <ng2 ng-transclude> defines default fallback content that gets replaced when the caller provides transcluded nodes, template captures the fallback nodes during controller(). Because template.length > 0, the caller's transcluded content is deleted and replaced with the fallback.

  3. ng-bind with placeholder text:
    For <ng2 ng-bind="user.name">Loading...</ng2>, template captures "Loading...". When compileContents runs, template.length === 1 means this.element.contents!() (which now holds "Alice" from ng-bind) is wiped out, and "Loading..." is projected instead.

Instead of guessing transclusion based on !template.length, should we explicitly inspect attrs (e.g. checking attrs.hasOwnProperty('ngTransclude') or attrs['ngTransclude'] != null)?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@SkyZeroZx SkyZeroZx Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we explicitly inspect attrs

Doing some research with help of an agent (Astra) I found the following:

For ng-transclude it would do the same. ngTransclude empties its element when it compiles, before any controller runs, so the copy is always empty there, even with whitespace or fallback content. I tested both and the content is projected fine.

The ng-bind placeholder gives Loading... with both checks. On main Alice only showed because the value was compiled, which is the bug.

The difference is an empty element filled by another directive, e.g. <ng2 ng-bind="user.name"></ng2> with downgradeModule(). Today and with this PR it shows Alice, with the attrs check it shows nothing. So I'd keep the current check, it doesn't depend on a specific directive.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/upgrade/src/common/src/downgrade_component.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@SkyZeroZx
fixup! fix(upgrade): only compile the template contents of a downgrad…
ba2b0d1
…ed component
JeanMeche
JeanMeche approved these changes Oct 25, 2026
View reviewed changes
@JeanMeche
JeanMeche removed the request for review from kirjs October 25, 2026 00:05
@JeanMeche

JeanMeche commented Oct 25, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

TGP came back green.

SkyZeroZx reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JeanMeche JeanMeche added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release target: minor This PR is targeted for the next minor release and removed target: patch This PR is targeted for the next patch release labels Oct 25, 2026
@SkyZeroZx

SkyZeroZx commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

I think we can consider this a security issue so we can do a backporting it to LTS versions according to the issue #71441 and POC , Because it allows an attacker to compile a string as template data leading to XSS

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mattrbeck
mattrbeck merged commit b2d3ba9 into angular:main Oct 25, 2026
29 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@mattrbeck

mattrbeck commented Oct 25, 2026

Copy link
Copy Markdown
Member

This PR was merged into the repository. The changes were merged into the following branches:

  • main: b2d3ba9
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Oct 25, 2026
[Backport 21.2.X] fix(upgrade): only compile the template contents of a downgraded comp… #71610
Merged
[Backport 20.3.X] fix(upgrade): only compile the template contents of a downgraded comp… #71611
Merged
[Backport 22.2.X] fix(upgrade): only compile the template contents of a downgraded component #71614
Merged
@SkyZeroZx
SkyZeroZx deleted the fix/upgrade-projected-content-compile branch November 15, 2026 16:24
@alan-agius4 alan-agius4 mentioned this pull request Nov 27, 2026
fix(upgrade): capture downgraded component template contents during compile #72235
Open
4 of 14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@JeanMeche JeanMeche JeanMeche approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

action: merge The PR is ready for merge by the caretaker area: upgrade Issues related to AngularJS → Angular upgrade APIs target: minor This PR is targeted for the next minor release

Projects

None yet

Milestone

Backlog

Development

Successfully merging this pull request may close these issues.

downgradeComponent() compiles content that AngularJS directives wrote into its element

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@SkyZeroZx @JeanMeche @mattrbeck
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.