3315 Commits

Author SHA1 Message Date
Jaime Burgos 2f96c8020f fix(core): sanitize host bindings on concrete hosts
Compute host binding security contexts against concrete hosts, including host directives, inheritance, dynamic directives, and createComponent hostElement usage.
2026-07-30 08:42:54 -07:00
Alan Agius db0d4a1a39 fix(compiler): restrict possible event handler check to property names longer than 2 characters
Previously, the compiler disallowed translation of any attribute starting with 'on' for security reasons. This incorrectly disallowed translation of the 'on' attribute itself, which is not an event handler.

This commit introduces `isPossibleEventHandler` to verify that the property name has a length greater than 2 in addition to starting with 'on'. This allows attributes like 'on' to be translated while still correctly disallowing actual event handlers like 'onerror', 'onclick', etc.
2026-07-29 08:51:21 -07:00
Hexix23 5dbcd0ee16 fix(compiler): disallow i18n event attributes
Reject translated event-handler attributes so localization cannot bypass Angular event-attribute validation.
2026-07-29 08:51:21 -07:00
SkyZeroZx 8eb7aea08b fix(core): reject dynamic script host elements
The previous fix for GHSA-692r-grfm-v8x7 was incomplete because it rejected script tags only when locating an explicit host element. Dynamic component instantiation can also infer the host element from the component selector.

Move the script-host rejection to the point where ComponentFactory has resolved the host element for either path, so createComponent rejects script hosts consistently.

(cherry picked from commit 135f3755b4)
2026-06-30 17:42:07 -07:00
SkyZeroZx 26831d0cbd fix(core): avoid caching missing locale data
Only cache locale data loaded from the global locale registry when an actual locale entry is found.

This prevents attacker-controlled missing locale identifiers from being retained indefinitely in SSR when locale lookup falls back to a parent locale or the built-in English locale, avoiding unbounded process memory growth in locale-aware pipes and formatters.

(cherry picked from commit ea8277ae37)
2026-06-24 14:36:24 -04:00
Jaime Burgos ca48b4728d fix(core): validate lowercase SVG animation attribute names (#69270)
Normalize SVG animation attributeName lookup to also recognize lowercase attributename before allowing dynamic animation value bindings.

Add runtime and platform-server SSR regression coverage for lowercase attributename retargeting.

(cherry picked from commit d5e689af80)
2026-06-10 09:51:20 -07:00
Alan Agius 1a62130a6b fix(common): use cryptographically secure SHA-256 for transfer cache key generation
Replace the custom 64-bit non-cryptographic combined DJB2 hashing implementation in HttpTransferCache with a robust, pure JavaScript, synchronous SHA-256 algorithm.

Using DJB2 is vulnerable to pre-image and second-preimage attacks due to its small 64-bit keyspace and mathematical simplicity. An attacker could craft colliding request inputs to poison the cache, potentially causing a CDN or the application to serve the wrong cached response to legitimate users.

SHA-256 provides strong cryptographic collision resistance, preventing cache key collision attacks. A custom synchronous implementation is required because the Web Crypto API (`crypto.subtle.digest`) is asynchronous, whereas the transfer cache state lookup and interceptor flow must operate synchronously.

Also, update the unit tests to dynamically verify the custom SHA-256 output against the native Web Crypto API.
2026-06-05 10:38:42 -07:00
SkyZeroZx 566ad05f20 fix(common): skip transfer cache for uncacheable HTTP traffic
Do not store HTTP transfer cache entries when either the request or response uses `Cache-Control: no-store`, `Cache-Control: private`, or `Cache-Control: no-cache`.

Also skip transfer cache when requests use the Fetch API `cache` option with `no-store` or `no-cache`.

Because transfer cache serializes SSR HTTP responses into the rendered HTML, Angular now treats these directives conservatively to avoid exposing sensitive or explicitly uncacheable data through `TransferState`.

(cherry picked from commit 4d150156ca)

(cherry picked from commit 64ce11fcd4)
2026-06-03 11:00:26 -07:00
Matthieu Riegler 768a349e6e fix(core): harden TransferState restoration against DOM clobbering
Reject non-script elements when reading the SSR transfer state payload by id.
This prevents attacker-controlled elements with a clobbered id from spoofing
hydration state.
2026-06-02 14:18:13 +02:00
Alan Agius 6595409248 test(core): update golden symbols and host bindings sanitization spec (#68926)
Synchronizes the golden symbols for router bundling and updates the host bindings sanitization integration test to use a[href] instead of blockquote[cite].

PR Close #68926
2026-05-27 10:28:46 -07:00
Alan Agius b8f1f72765 test(core): remove obsolete blockquote cite host binding tests (#68926)
Removes the obsolete blockquote[cite] sanitization expectations in host_binding_spec.ts.

PR Close #68926
2026-05-27 10:28:46 -07:00
Alan Agius 36200bd81a test(core): update spec files to match 20.3.x limits and actual contexts (#68926)
Updates spec files to replace modern Eager change detection and remove obsolete ins[cite] expectations.

PR Close #68926
2026-05-27 10:28:46 -07:00
Alan Agius 8f35b182b1 fix(compiler): normalize tag names with custom namespaces in DomElementSchemaRegistry (#68926)
Custom XML/XHTML namespaced elements (e.g., <xhtml:a>) fall back to the standard HTML namespace during element creation at compile-time/runtime. However, their property and security context lookups inside the schema registry were incorrectly performed using the full namespaced tag name (e.g., :xhtml:a), which bypassed the default a|href sanitization registry and incorrectly returned SecurityContext.NONE instead of SecurityContext.URL.

This commit introduces tag name normalization inside DomElementSchemaRegistry for custom namespaces (other than the built-in svg and math namespaces). Custom namespaced tag names are now normalized to their simple HTML element counterparts for all registry queries, ensuring that correct property schema validation and dynamic security sanitization rules (such as URL sanitization) are enforced at runtime.

PR Close #68926
2026-05-27 10:28:46 -07:00
Alan Agius 64a89e917a fix(compiler): sanitize dynamic href and xlink:href bindings on SVG a elements (#68926)
Dynamic bindings to `href` and `xlink:href` attributes on SVG `<a>` elements (`<svg:a>`) were previously unmapped in the DOM security schema. As a result, they bypassed sanitization completely, creating a potential XSS vulnerability if bound to untrusted user inputs (e.g., `javascript:` URLs).

This fix mitigates this risk by:

1. Registering `href` and `xlink:href` on `<svg:a>` elements under the `SecurityContext.URL` context in both the compiler and core DOM security schemas.

2. Enabling template compilation to output runtime URL sanitization checks (`ɵɵsanitizeUrl`) on these attributes.

3. Adding regression and verification test cases to ensure dynamic SVG link bindings are safely sanitized at runtime while static values are correctly allowed.

PR Close #68926
2026-05-27 10:28:46 -07:00
leonsenft 09344ea457 test(core): remove obsolete SVG script sanitization translation test (#68926)
Removes the `should throw error on translated SVG script ResourceURL
attributes` integration test from `security_integration_spec.ts`.

This test is now obsolete because SVG `<script>` elements are stripped during
template compilation (implemented in 90494cd909). As a result, they are no
longer present in the compiled template to trigger runtime sanitization,
causing this test (which expected a sanitization error to be thrown) to fail.

PR Close #68926
2026-05-27 10:28:46 -07:00
Alan Agius 6404edfe0a fix(compiler): strip namespaced SVG script elements during template compilation (#68926)
Ensures that namespaced <script> elements (such as :svg:script) are correctly classified as PreparsedElementType.SCRIPT by the template preparser and stripped during compilation to prevent potential XSS vulnerabilities. Consequently, obsolete security schema mappings and runtime sanitization checks for <script> attributes have been removed since these elements are never present in compiled template outputs.

PR Close #68926
2026-05-27 10:28:46 -07:00
Alan Agius dc631efa96 fix(core): support prefix-insensitive DOM schema lookups and compile-time i18n attribute validation (#68926)
Updates `DomElementSchemaRegistry` to strip `:svg:` and `:math:` namespace prefixes
from tag names before querying `SECURITY_SCHEMA` at compile-time. This allows SVG
and MathML attributes to correctly match their security contexts during compilation.

PR Close #68926
2026-05-27 10:28:46 -07:00
Alan Agius 3b66843ed2 refactor(core): align namespaced attribute validation and security schema contexts (#68926)
Refactors the element security schema lookups and runtime attribute validation to
consistently account for SVG and MathML namespaces. This improves the modularity
and accuracy of security context mapping during template compilation and runtime
constant evaluation, eliminating redundant or false-positive lifecycle checks.

PR Close #68926
2026-05-27 10:28:46 -07:00
Alan Agius a9bcffdbc7 fix(core): disallow event attribute bindings in host bindings unconditionally (#68468)
Moves the event attribute validation check outside of `ngDevMode` in the `elementAttributeInternal` instruction to ensure that bindings to event attributes like `on*` are always blocked at runtime.

Previously, this check was only performed when `ngDevMode` was `true`, which could allow attacker-controlled CMS data to be bound to event attributes in production mode, causing browser-executed XSS.

Fixes #68419

PR Close #68468
2026-05-06 14:43:10 -07:00
Alan Agius 97eeb45cfa fix(core): validate security-sensitive attributes in i18n bindings (#68468)
Ensures that security-sensitive attributes (e.g., sandbox, allow) are correctly validated when applied through i18n-* dynamic attribute bindings, preventing potential policy bypasses.

Closes #68418

PR Close #68468
2026-05-06 14:43:09 -07:00
Kristiyan Kostadinov 626bc8bc20 fix(core): sanitize translated form attributes
Fixes that we weren't sanitizing the `form` and `formaction` attributes when they're used together with translations.
2026-03-12 12:30:55 -06:00
Kristiyan Kostadinov 72126f9a08 fix(core): sanitize translated attribute bindings with interpolations
Fixes that we weren't sanitizing attribute bindings with interpolations if they're marked for translation, for example: `<a href="{{evilLink}}" i18n-href></a>`.

Also adds a bit more test coverage for our sanitization.
2026-03-12 12:30:55 -06:00
Doug Parker 7f9de3c118 fix(core): block creation of sensitive URI attributes from ICU messages
Translators are not allowed to write HTML which creates URI attributes. I opted to ban any values going into an attribute at all, to prevent even links to malicious content, rather than just sanitizing URIs.

I also converted this blocklist into an allowlist. Now, we only allowing setting known attributes (while sanitizing URI attributes). This significantly reduces risk of missing a vulnerable attribute and does not require an exhaustive list of all potential attributes.

BREAKING CHANGE: Angular now only applies known attributes from HTML in translated ICU content. Unknown attributes are dropped and not rendered.

(cherry picked from commit 03da204b6d)
2026-02-25 08:22:14 -08:00
Alan Agius c2c2b4aaa8 fix(core): sanitize sensitive attributes on SVG script elements
This commit updates the DOM security schema and sanitization logic to properly recognize and sanitize `href` and `xlink:href` attributes on SVG `<script>` elements.
2026-01-06 15:54:47 -05:00
Alan Agius d1ca8ae043 fix(compiler): prevent XSS via SVG animation attributeName and MathML/SVG URLs
This commit implements a security fix to prevent XSS vulnerabilities where SVG animation elements (`<animate>`, `<set>`, etc.) could be used to modify the `href` or `xlink:href` attributes of other elements to `javascript:` URLs.

The fix introduces a runtime validation step:
- A new [ɵɵValidateAttribute](cci:1://file:///usr/local/google/home/alanagius/git/angular/packages/core/src/sanitization/sanitization.ts:276:0-288:1) instruction is used when `attributeName` is bound on SVG animation elements.
- If executed, a `RuntimeError` is thrown, preventing the binding.
- The compiler now identifies `attributeName` on SVG animation elements as security-sensitive and injects this validation.

Additionally, the DOM security schema has been updated to include a comprehensive list of MathML and SVG elements that accept `href` or `xlink:href` attributes, ensuring they are correctly treated as `SecurityContext.URL` and sanitized. This prevents malicious URLs from being bound to these attributes.

http://b/463880509
2025-12-01 10:29:30 +01:00
Jessica Janiuk 820bb3991c Revert "refactor(core): let the profiler handle asymmetric events leniently"
This reverts commit da9911f2b4.

(cherry picked from commit 88dfd96ec9)
2025-11-17 18:10:40 +00:00
Jessica Janiuk 2dccdcd6bc Revert "fix(core): notify profiler events in case of errors"
This reverts commit af1ba52587.

(cherry picked from commit adc2a57be0)
2025-11-17 18:10:40 +00:00
JoostK a966ff18d4 refactor(core): let the profiler handle asymmetric events leniently
Although the prior commit has made more profiler events guaranteed symmetric
through the use of finally-blocks, there continue to be some situations
that could potentially result in asymmetric events, e.g. application
bootstrap doesn't guarantee symmetric events. This commit makes the profiler
lenient to these situations by unrolling the stack past the asymmetric event
data, eventually reaching the expected start event.

(cherry picked from commit da9911f2b4)
2025-11-17 17:40:09 +00:00
JoostK 52cf65892a fix(core): notify profiler events in case of errors
Profiler events are expected to be symmetric, yet in the case of errors this symmetry may break
if events aren't always kept in sync with their corresponding start event. This commit moves
various end events to be run from a finally-block, allowing them to notify the profiler even
when an error has occurred.

Fixes #62947

(cherry picked from commit af1ba52587)
2025-11-17 17:40:09 +00:00
tsc036 41466a7bbf refactor(core): move profile_types.ts to primtives
move profile_types.ts so the types can be used in Wiz code

(cherry picked from commit cf47ce2db9)
2025-11-06 22:22:37 +00:00
SkyZeroZx 1dcecdf823 refactor(platform-browser): remove unused Platform ID dependency from DomRendererFactory2
Eliminates the unnecessary injection and usage of Platform ID in the renderer factory logic, along with related test scaffolding cleanup

(cherry picked from commit 5343001835)
2025-11-06 20:00:49 +00:00
Alan Agius ee578d3e86 build: format md files
Format all md files
2025-11-06 10:10:22 -08:00
Jessica Janiuk dcdd1bcdbb fix(core): skip leave animations on view swaps
We accounted for skipping leave animations during moves, but not swaps.
This accounts for the swap cases and updates how we deal with swaps and
moves. Now we always queue animations and then essentially dequeue them
if we attach them back in the same render pass.

fixes: #64818
fixes: #64730
2025-11-06 09:46:52 -08:00
Matt Lewis ca3fd7847f fix(core): Clear lView from IcuIteratorState when stack is empty to prevent memory leak
If a component template contains an icu expression it is being retained until the next change detection cycle for that template. This results in a net retention of only ever a single copy of the given lView but that creates an opportunity for compounding leaks.

Change the icu i18n_icu_container_visitor to free the IcuIteratorState retained lView when the stack is empty so that garbage collection can occur when the view is discarded.

(cherry picked from commit 59e648913c)
2025-10-27 19:42:21 +01:00
Jessica Janiuk 2fad4d4ab6 fix(core): prevent duplicate nodes from being retained with fast animate.leave` calls (#64592)
We were clearing duplicate nodes when `animate.enter` fired fast, but not when solely `animate.leave` is fired and rapid toggles occur. This ensures that the `cancelLeavingNodes` function is called in all cases instead of just enter animations.

fixes: #64581

PR Close #64592
2025-10-22 19:07:35 +00:00
Jessica Janiuk 139b622957 refactor(core): clarify comments on enter animation queuing (#64550)
This just updates the comments and adds some tests to verify some of the queuing behavior for enter animations.

PR Close #64550
2025-10-21 15:17:14 +00:00
Jessica Janiuk 911d6822cb fix(core): update animation scheduling (#64441)
In some rare cases, it seems the animation queue disappears despite being afterEveryRender. This updates the animation scheduler to be afterNextRender instead and only schedules it when we need to.

fixes: #64423

PR Close #64441
2025-10-16 17:35:51 +00:00
Angular Robot 60eba9b0a4 build: update cross-repo angular dependencies (#64447)
See associated pull request for more information.

PR Close #64447
2025-10-15 21:09:30 +00:00
Jessica Janiuk f15cfa4cc4 fix(core): fixes regression in animate.leave function bindings (#64413)
When adding and removing items in a `@for` loop, the `animate.leave` event binding instruction was not updated to use the same logic as the class function when the animation queue was added. We were not returning the correct signature for the `animate.leave` function, which caused the animation to not trigger correctly. This updates the event binding instruction to use the same logic as the class function when adding the animation to the queue.

fixes: #64336

PR Close #64413
2025-10-14 13:46:39 -07:00
Andrew Kushnir a2773b5ed1 ci: update symbol golden file for @defer test case (#64396)
This commit updates the golden file, which got affected by this change: https://github.com/angular/angular/commit/eb80c3075f546c43f0ed2636bc6323d4b9d0a898

PR Close #64396
2025-10-13 16:49:27 -07:00
Joey Perrott f23df716a8 build: update symbol extractor tests to stabalize the order of the symbols listed (#64389)
Update to ensure that the symbols in the list of extracted symbols is consistent even when multiple bundle files are extracted from.

PR Close #64389
2025-10-13 11:12:56 -07:00
Kristiyan Kostadinov 2342de8fac refactor(compiler): expose member decorator identifiers (#63957) (#64317)
Adds the member decorators to the map of exposed compiler symbols.

PR Close #63957

PR Close #64317
2025-10-09 11:57:57 -07:00
Angular Robot 950a05c8e1 build: update cross-repo angular dependencies (#64308)
See associated pull request for more information.

PR Close #64308
2025-10-09 05:28:32 -07:00
Jessica Janiuk 3b959105be fix(core): prevent early exit from leave animations when multiple transitions are present (#64225)
Our code ensuring host binding composition for animations was causing the early exit and removal of
elements when multiple transitions were present on the same element. This commit fixes the issue by
ensuring that we properly keep track of all the promise resolvers on the LView and then only
call them once we've properly waited for the longest animation to finish.

fixes: #64209

PR Close #64225
2025-10-06 15:34:28 -04:00
Jessica Janiuk 08b8b13185 refactor(core): fix animations host binding tests (#64225)
These tests were not properly validating against the host binding changes due to the fact that the styles were on the wrong components in some of the host binding cases.

PR Close #64225
2025-10-06 15:34:27 -04:00
Angular Robot 3fe6416ae3 build: update cross-repo angular dependencies (#64213)
See associated pull request for more information.

PR Close #64213
2025-10-02 14:21:28 -07:00
Jessica Janiuk 6fed986b7a fix(core): Fixes animations in conjunction with content projection (#63776)
Content Projected nodes are not destroyed and recreated, like every other
situation. Enter and Leave animations were ephemeral and are
expected to run once, and then be cleared. This means that for content projection
cases, the animations would only ever work the first time they were shown / hid.

In order to resolve this, we move to an animation queue that re-runs the animation
functions stored in the LView. In most cases, this animation will run once on creation.
For content projection, the enter and leave animations will fire more than once. Animations
are stored on the LView, but indexed and scheduled by whichever RNode needs to be animated.
So we only run animations for an affected RNode, rather than potentially all in the LView.

This also moves the queue to afterRender, which is safer than right after template
execution in refreshView.

fixes: #63418
fixes: #64065
fixes: #63901

PR Close #63776
2025-10-02 16:56:01 +00:00
kirjs a453b1de08 Revert "fix(core): Fixes animations in conjunction with content projection (#63776)" (#64189)
This reverts commit 1cb16fddb5.

PR Close #64189
2025-10-01 22:42:41 +00:00
Jessica Janiuk 0e928fbc4a fix(core): Fixes animations in conjunction with content projection (#63776)
Content Projected nodes are not destroyed and recreated, like every other
situation. Enter and Leave animations were ephemeral and are
expected to run once, and then be cleared. This means that for content projection
cases, the animations would only ever work the first time they were shown / hid.

In order to resolve this, we move to an animation queue that re-runs the animation
functions stored in the LView. In most cases, this animation will run once on creation.
For content projection, the enter and leave animations will fire more than once. Animations
are stored on the LView, but indexed and scheduled by whichever RNode needs to be animated.
So we only run animations for an affected RNode, rather than potentially all in the LView.

This also moves the queue to afterRender, which is safer than right after template
execution in refreshView.

fixes: #63418
fixes: #64065
fixes: #63901

PR Close #63776
2025-10-01 09:07:38 -04:00
Angular Robot 7d720d52ec build: update cross-repo angular dependencies (#64077)
See associated pull request for more information.

PR Close #64077
2025-09-25 15:38:02 -04:00