You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Escape APP_ID for ViewEncapsulation.Emulated #63251
Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
No
Description
APP_ID is not escaped despite being included in a CSS selector, meaning if it includes special syntax known to CSS it can confuse the selector.
For example, providing:
{provide: APP_ID,useValue: 'foo:bar',}
Generates the following DOM:
<h1_ngcontent-foo:bar-c2846697727="" class="foo">Hello from Angular!</h1>
Which is actually ok, : is valid in this context. But the CSS is not:
.foo[_ngcontent-foo:bar-c2846697727] {/* ... */}
This is invalid because : triggers a pseudo-class in the middle of an attribute selector. Ideally, we should escape this with CSS.escape, though a similar problem exists with the attribute name itself. For example, foo bar triggers
InvalidCharacterError: Failed to execute 'setAttribute' on 'Element': '_nghost-foo bar-c2846697727' is not a valid attribute name.
I'm not sure you really can escape a space from an attribute name, so we might just have to ban that (and any other invalid characters such as >) altogether.
Please provide a link to a minimal reproduction of the bug
CSS.escape is also unsafe to use because of the non-browser environments where the render also runs.
What alternative do we have ?
Should we maybe throw an error in devmode so a more "complex" check doesn't impact prod builds ? Or Is APP_ID the kind of token that are often set depending on envs ?
Activity
refactor(platform-browser): escape appID in Emulated DOM renderer.
JeanMeche commentedon Aug 19, 2025
CSS.escapeis also unsafe to use because of the non-browser environments where the render also runs.What alternative do we have ?
Should we maybe throw an error in devmode so a more "complex" check doesn't impact prod builds ? Or Is APP_ID the kind of token that are often set depending on envs ?
alan-agius4 commentedon Aug 20, 2025
Indeed, CSS.escape and CSS.unescape cannot be used in this context. We could probably just allow alphanumeric characters,
_and-.The APP_ID token is used when having multiple applications running on the same page so that CSS is not leaked between an application and another.
refactor(platform-browser): escape appID in Emulated DOM renderer.
refactor(platform-browser): Sanitize appID in Emulated DOM renderer.
refactor(platform-browser): Sanitize appID in Emulated DOM renderer.
JeanMeche commentedon Sep 19, 2025
#63252
angular-automatic-lock-bot commentedon Oct 20, 2025
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.