5417 Commits

Author SHA1 Message Date
Alan Agius c5b6d735a0 refactor(core): prevent runtime error when root element is null during tag check
This ensures that when rootElement is undefined no error occures.
2026-05-27 10:26:12 -07:00
Alan Agius e8d35f9693 Revert "revert: revert all changes until fdc1b48f32e52da7684583811a6a3090f6418d5e"
This reverts commit 4747fe207d.
2026-05-27 10:26:12 -07:00
Alan Agius 4747fe207d revert: revert all changes until fdc1b48f32
This reverts all changes from fdc1b48f32 to the previous branch tip (d31f84116c) due to repository force-push restrictions.
2026-05-27 10:53:37 +00:00
Alan Agius d31f84116c fix(core): wrap i18n dynamic element property updates in active index states
Ensure that the elementPropertyInternal call in i18n_apply.ts is wrapped within a setSelectedIndex(nodeIndex) try/finally block. This coordinates input/property reflection lookups with the correct element node at runtime, preventing ICU and renderer element dynamic update errors.

Additionally, apply a safe guard to locateHostElement to check for defined targets during dynamic targetless testing contexts, and update the integration payload tracking sizes golden file.
2026-05-27 08:12:57 +00:00
Alan Agius e2caa08ef2 test(core): update core packaging golden symbols to match security schema refactor
Update the golden symbols files for animations-standalone, defer, forms_reactive, forms_template_driven, and hydration tests.

These symbol list updates align with the newly backported security schema refactor, where a generic RESOURCE_MAP was introduced and individual resource tag collections were combined.
2026-05-27 07:58:39 +00:00
Alan Agius 7dab3e376c test(core): update router golden symbols to match security schema refactor
Update golden file and schema tests
2026-05-27 07:32:55 +00:00
Alan Agius ce6acbf5c1 test(compiler-cli): align ngtsc sanitization expectations with modern DOM schema
Removes the legacy profile property/attribute from the directives hostBindings specs to align with modern DOM security schema changes. Also cleans up minor redundant formatting lines in the compiler and core targets.
2026-05-27 07:21:48 +00:00
Alan Agius de74480496 test(core): update golden symbols and host bindings sanitization spec
Synchronizes the golden symbols for router bundling and updates the host bindings sanitization integration test to use a[href] instead of blockquote[cite].
2026-05-27 07:21:19 +00:00
Alan Agius c6bb0692e2 fix(core): reject script element as a dynamic component host
To enhance application security and prevent accidental or malicious script execution, this change ensures that dynamically mounting a component via createComponent directly onto a <script> element throws a runtime error in development mode. SVG <script> elements are also rejected. The error message is designed to be fully tree-shakable under production builds where ngDevMode is disabled.
2026-05-27 07:21:12 +00:00
Alan Agius 5e399a24da test(core): remove obsolete blockquote cite host binding tests
Removes the obsolete blockquote[cite] sanitization expectations in host_binding_spec.ts.
2026-05-27 07:21:10 +00:00
Alan Agius dc3a544a74 test(core): update spec files to match 20.3.x limits and actual contexts
Updates spec files to replace modern Eager change detection and remove obsolete ins[cite] expectations.
2026-05-27 07:21:09 +00:00
Alan Agius 51714f3753 refactor(core): resolve merge conflicts in sanitization.ts
Resolves missing definitions and JIT compiler errors in sanitization.ts.
2026-05-27 07:21:05 +00:00
Alan Agius 620230dac4 fix(core): synchronize core sanitization schema with compiler
Synchronizes the core's copy of the DOM security schema with the compiler-side schema definitions, and removes the write_source_file target.
2026-05-27 07:21:00 +00:00
Alan Agius 3bfa4ee03b fixup! fix(core): normalize tag names in runtime i18n attribute security context lookup 2026-05-27 07:20:48 +00:00
Alan Agius 7b74351310 fix(core): normalize tag names in runtime i18n attribute security context lookup
Normalize namespaced tag names (e.g., :xhtml:a to a) inside i18nResolveSanitizer before looking up their security context. This ensures custom namespaced tag attributes undergo correct translation sanitization at runtime.
2026-05-27 07:20:46 +00:00
Alan Agius 932e0728db fix(compiler): normalize tag names with custom namespaces in DomElementSchemaRegistry
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.
2026-05-27 07:20:44 +00:00
Alan Agius 2e3d0371ab fix(compiler): sanitize dynamic href and xlink:href bindings on SVG a elements
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.
2026-05-27 07:20:42 +00:00
leonsenft bdda6866a8 test(core): remove obsolete SVG script sanitization translation test
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.
2026-05-27 07:20:39 +00:00
Alan Agius fe1207e8c5 fix(compiler): strip namespaced SVG script elements during template compilation
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.
2026-05-27 07:20:37 +00:00
Alan Agius 3632fa4b69 fix(core): support prefix-insensitive DOM schema lookups and compile-time i18n attribute validation
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.
2026-05-27 07:20:34 +00:00
Alan Agius 8a814aed96 refactor(core): align namespaced attribute validation and security schema contexts
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.
2026-05-27 07:19:58 +00:00
Alan Agius 83a640516f fix(core): disallow event attribute bindings in host bindings unconditionally (#68469)
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 #68469
2026-05-07 15:25:14 -07:00
Alan Agius 24a0103a98 fix(core): validate security-sensitive attributes in i18n bindings (#68469)
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 #68469
2026-05-07 15:25:14 -07:00
Kristiyan Kostadinov 621c7071ad 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:44:18 -06:00
Kristiyan Kostadinov b89b0a83a4 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:44:18 -06:00
Doug Parker 747548721d 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:43 -08:00
Alan Agius 26cdc53d9c 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:15 -05:00
Alan Agius 7c42e2ebeb 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:28:38 +01:00
Alan Agius 70d0639bc1 fix(core): introduce BootstrapContext for improved server bootstrapping (#63639)
* fix(core): introduce `BootstrapContext` for improved server bootstrapping

This commit introduces a number of changes to the server bootstrapping process to make it more robust and less error-prone, especially for concurrent requests.

Previously, the server rendering process relied on a module-level global platform injector. This could lead to issues in server-side rendering environments where multiple requests are processed concurrently, as they could inadvertently share or overwrite the global injector state.

The new approach introduces a `BootstrapContext` that is passed to the `bootstrapApplication` function. This context provides a platform reference that is scoped to the individual request, ensuring that each server-side render has an isolated platform injector. This prevents state leakage between concurrent requests and makes the overall process more reliable.

BREAKING CHANGE:
The server-side bootstrapping process has been changed to eliminate the reliance on a global platform injector.

Before:
```ts
const bootstrap = () => bootstrapApplication(AppComponent, config);
```

After:
```ts
const bootstrap = (context: BootstrapContext) =>
  bootstrapApplication(AppComponent, config, context);
```

A schematic is provided to automatically update `main.server.ts` files to pass the `BootstrapContext` to the `bootstrapApplication` call.

In addition, `getPlatform()` and `destroyPlatform()` will now return `null` and be a no-op respectively when running in a server environment.
2025-09-09 10:56:38 -07:00
Kristiyan Kostadinov 73d3e001d2 build: fix failing test (#61683)
Fixes a failing test in the unused imports migration.

PR Close #61683
2025-05-26 11:57:31 +00:00
Kristiyan Kostadinov 9e1cd49662 fix(migrations): preserve comments when removing unused imports (#61674)
Updates the unused imports schematic to preserve comments inside the array. THis is necessary for some internal use cases.

PR Close #61674
2025-05-26 10:26:21 +00:00
Joey Perrott a6d5479cc7 build: migrate platform-server to rules_js (#61619)
Migrate platform-server to use ts_project and ng_project.

PR Close #61619
2025-05-22 15:34:07 -07:00
Joey Perrott 2a26944974 build: migrate platform-browser and platform-browser-dynamic package to use rules_js (#61624)
Use ts_project and ng_project to build platform-browser and platform-browser-dynamic package

PR Close #61624
2025-05-22 15:32:58 -07:00
Matthieu Riegler 2ae69f77e7 refactor: ensure tsurge migrations have clear ownership of files (#61612)
This is a patch port of #61421

PR Close #61612
2025-05-22 11:43:48 -07:00
Paul Gschwendtner c101a3aa7d refactor: clean-up deduplication workaround from migrations (#61421) (#61612)
Since the duplication root-cause was solved by the previous commit, we
can revert/drop the logic that was added back then to overcome this
problem with Tsurge.

PR Close #61421

PR Close #61612
2025-05-22 11:43:48 -07:00
Paul Gschwendtner 1a811c9f9d refactor: ensure tsurge migrations have clear ownership of files (#61421) (#61612)
Currently there can be cases, exlusively in 3P, where multiple tsconfig
projects have overlap of source files. This is the default setup of new
CLI applications as well.

When this is the case, Tsurge will treat each tsconfig as an isolated
compilation unit (given the concepts and mental model to support
scalable batching). This is wrong though, and the same `.ts` source file
can appear in two migration invocations; resulting in duplicate
replacements or analysis (depending on the migration).

We've worked around this problem in the past by deduplicating
replacements, or migrating to an ID-based approach with natural
deduplication. This worked, but it's just working around the root cause.

This commit attempts to fix the root cause by adjusting Tsurge to ensure
that no source file ever appears in two compilation units. This is
naively achieved by not adding a source file to a migration unit, if it
was part of a previous one. This is expected to be fine given the nature
of Tsurge migrations that are built to operate on isolated pieces
anyway— so it shouldn't be problematic if e.g. `app.component.ts` ends
up being part of the test tsconfig compilation unit (we avoid this order
though by visiting build targets first).

PR Close #61421

PR Close #61612
2025-05-22 11:43:48 -07:00
Joey Perrott 3a8bbe990e build: migrate language service to use rules_js (#61578)
Migrate language service to build using ts_project

PR Close #61578
2025-05-21 17:06:33 +00:00
Paul Gschwendtner 3fcd10912d build: migrate all ng_module in packages/core/test (#61571)
Migrates all `ng_module` to `ng_project` in `packages/core/test/`.

PR Close #61571
2025-05-21 16:04:42 +00:00
Paul Gschwendtner 2ccce30f9e build: migrate all ts_library in packages/core/test (#61571)
This commit migrates all `ts_library` in `package/core/test` to
`ts_project`, and fixes deep module, or relative imports inside.

PR Close #61571
2025-05-21 16:04:42 +00:00
arturovt 2b1b14f4d3 fix(core): cleanup rxResource abort listener (#58306)
The observable terminates immediately when `error` is called, and no further emissions or completion notifications occur. Thus, we have to remove the `abort` listener in both the `error` and `complete` notifications.

PR Close #58306
2025-05-21 15:17:24 +00:00
Kristiyan Kostadinov 44bb328eae fix(compiler): avoid conflicts between HMR code and local symbols (#61550)
Currently we construct the HMR replacement URL inline by calling into the native `URL` constructor. This can cause conflicts with user code that defines a symbol called `URL`.

These changes resolve the issue by moving the URL construction into a separate function. This has a secondary benefit of making the generated code easier to follow and allowing us to update the URL without changing the compiled code.

Fixes #61517.

PR Close #61550
2025-05-21 12:25:27 +00:00
arturovt 8f9b05eaaa fix(core): cleanup testability subscriptions (#61261)
This commit prevents leaking memory when the application is destroyed and subscriptions are still alive.

PR Close #61261
2025-05-21 12:06:24 +00:00
Matthieu Riegler c0c69a5abc fix(core): unregister onDestroy in toSignal. (#61514)
We cleanup if the observable completes before the onDestroy fires.

fixes #61511

PR Close #61514
2025-05-20 14:43:32 +00:00
Paul Gschwendtner bd2b454faf refactor(migrations): gracefully proceed if reference cannot be resolved (#61426)
A runtime error can surface when TypeScript internally fails to resolve
a reference that is named similar to an input, but no `.d.ts` is
available for it.

See example error:
https://github.com/microsoft/TypeScript/issues/61473#issuecomment-2746537781.

PR Close #61426
2025-05-19 11:04:54 +00:00
Pawel Kozlowski c856f43b5f refactor(core): move the data store operation out of instructions (#61425)
The view data store operation is not an instruction and shouldn't be
located in the instructions folder.

PR Close #61425
2025-05-19 08:24:47 +00:00
Pawel Kozlowski 1a3351c4f5 refactor(core): move i18n logic into its dedicated package (#61425)
Move the i18n-related logic out of the instructions folder into
the i18n-dedicated folder / package.

PR Close #61425
2025-05-19 08:24:47 +00:00
Paul Gschwendtner 185b7801ee build: migrate packages/core/schematics to ts_project (#61420)
Migrates `packages/core/schematics` to `ts_project`. As part of this,
this commit cleans up some of the mixed module types and tsconfigs in
the folder. A single tsconfig (and it's test variant) are now used.

For the shipped schematics, we explicitly use the `.cjs` extension, so
that the bundles are properly recognized as CommonJS; even if they are
part of the `type: module` `@angular/core` package.

The `package.json` with `type: commonjs` is removed from
`packages/core/schematics` as it's no longer needed given the explicit
extension & caused issues as schematics are compiled with ESM but are
only later bundled for shipping & some tests as ESM.

PR Close #61420
2025-05-16 15:53:27 +00:00
Paul Gschwendtner e056fa13df build: migrate more targets of @angular/core to ts_project (#61420)
Migrates more targets of `@angular/core` to `ts_project`. Remaining are:

 - tests
 - schematics

PR Close #61420
2025-05-16 15:53:27 +00:00
Andrew Scott 94f5a4b4d6 fix(core): Testing should not throw when Zone does not patch test FW APIs (#61376)
This prevents `core/testing` from throwing an error if ZoneJS is present
but does not patch the test FW APIs such that `fakeAsync` works
automatically. For example, there is currently no patching of the vitest
APIs, so if you try to use Vitest with Zone on the page, it will throw.

PR Close #61376
2025-05-16 07:53:41 +00:00
arturovt eb53bda470 fix(core): enable stashing only when withEventReplay() is invoked (#61352)
Patch version of https://github.com/angular/angular/pull/61077.

PR Close #61352
2025-05-15 10:10:04 -07:00