Skip to content

fix(core): respect @Host boundary in embedded view injector lookup - #71408

Open
JeanMeche wants to merge 1 commit into
angular:mainfrom
JeanMeche:fix-host-embedded-injector
Open

JeanMeche wants to merge 1 commit into
angular:mainfrom
JeanMeche:fix-host-embedded-injector

Conversation

@JeanMeche

Copy link
Copy Markdown
Member

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.dev application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: Fixes #57390

When an embedded view is created with a custom injector (createEmbeddedView(..., { injector }) or *ngTemplateOutlet="...; injector: ..."), the HasEmbeddedViewInjector flag is set on the view and inherited by descendant component views.
When resolving tokens, lookupTokenUsingEmbeddedInjector walks up the view tree without checking InternalInjectFlags.Host. This allows resolutions with @Host() on directives inside child components within the embedded view to bypass the host component boundary and leak into the custom embedded view injector and its parent injector hierarchy (such as finding an ancestor reactive FormGroupDirective providing ControlContainer, causing NG01050/NG01350).

What is the new behavior?

In lookupTokenUsingEmbeddedInjector, stop searching parent nodes once the host element node (hostTElementNode = flags & InternalInjectFlags.Host ? lView[DECLARATION_COMPONENT_VIEW][T_HOST] : null) has been checked when InternalInjectFlags.Host is set.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@angular-robot angular-robot Bot added the area: core Issues related to the framework runtime label Oct 17, 2026
@ngbot ngbot Bot added this to the Backlog milestone Oct 17, 2026
@JeanMeche
JeanMeche force-pushed the fix-host-embedded-injector branch from 47359c1 to 9a87786 Compare October 17, 2026 04:22
When an embedded view is created with a custom injector, the `HasEmbeddedViewInjector` flag is set on the view and inherited by descendant component views.
When resolving tokens, `lookupTokenUsingEmbeddedInjector` walked up the view tree without checking `InternalInjectFlags.Host`, which allowed resolutions with `@Host()` to leak outside the host component into the custom injector and its parent injector hierarchy.

Stop traversing parent nodes in `lookupTokenUsingEmbeddedInjector` once the host element node has been checked when `InternalInjectFlags.Host` is set.

Fixes angular#57390
@JeanMeche
JeanMeche force-pushed the fix-host-embedded-injector branch from 9a87786 to 479d589 Compare October 17, 2026 04:23
@JeanMeche
JeanMeche marked this pull request as ready for review October 17, 2026 04:46
@JeanMeche
JeanMeche requested a review from crisbeto October 17, 2026 04:46

@crisbeto crisbeto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, but we should do a TGP

@JeanMeche JeanMeche added 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 17, 2026
@JeanMeche

Copy link
Copy Markdown
Member Author

Green TGP

@JeanMeche JeanMeche added the action: merge The PR is ready for merge by the caretaker label Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom injector for templates breaks @Host inject flag

2 participants