13205 Commits

Author SHA1 Message Date
Alan Agius f3a5bfb949 fix(platform-server): prevent SSRF bypasses via protocol-relative and backslash URLs
The `parseUrl` function in `ServerPlatformLocation` uses `new URL(urlStr, origin)` to parse incoming request URLs during SSR. Per the WHATWG URL specification, protocol-relative URLs (`//evil.com`) and backslash-prefixed URLs (`/\evil.com`) can override the hostname component of the base URL.

This vulnerability typically manifests in SSR setups (e.g., Express) where `req.url` is passed directly to `renderApplication` or `renderModule`:

```typescript
// Example usage in an Express server handling: http://localhost:4000//evil.com
app.get('*', async (req, res) => {
  const html = await renderApplication(bootstrap, {
    document: template,
    url: req.url, // req.url is "//evil.com"
  });
  res.send(html);
});
```
2026-04-15 19:41:20 +03:00
Kristiyan Kostadinov 5be912eb55 fix(compiler): disallow translations of iframe src
Fixes that the compiler was allowing translations of `src` attributes in iframes which can be a security issue.
2026-03-12 12:44:18 -06: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 05fe6686a9 fix(http): prevent XSRF token leakage to protocol-relative URLs
The XSRF interceptor previously failed to detect protocol-relative URLs (starting with `//`) as absolute URLs. This allowed requests to such URLs to include the XSRF token, potentially leaking it to external domains.

This change updates the interceptor to correctly identify protocol-relative URLs as absolute and exclude them from receiving the XSRF token.
2025-11-25 13:57:28 -05: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
Joey Perrott 6fea9c88cc build: migrate examples to use rules_js (#61652)
Migrate examples to use ng_project and ts_project for building

PR Close #61652
2025-05-26 11:01: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
Matthieu Riegler 24bab55f0c fix(compiler): lexer support for template literals in object literals (#61601)
This commit fixes a shortcoming of the lexer with template literals

fixes #61572

PR Close #61601
2025-05-26 10:24:17 +00:00
Joey Perrott 12e2302a04 build: update common's locales to use rules_js (#61630)
Use ts_project to build the common locales

PR Close #61630
2025-05-26 10:18:48 +00:00
Jonathan Meier 6957808bbb refactor(compiler-cli): remove hardcoded config for unused standalone imports rule enablement (#61622)
The hardcoded config was introduced because suppressing the diagnostic
via `extendedDiagnostics` in the TS config was unreliable in google3.
This has since been fixed and the workaround is no longer needed.

PR Close #61622
2025-05-26 09:20:27 +00:00
Alan Agius e818a009a1 build: exclude esbuild metadata files from distributable packages (#61636)
Prevents esbuild generated metadata files from being included in build artifacts. This reduces package size and avoids shipping unnecessary internal build data.

PR Close #61636
2025-05-26 08:57:43 +00:00
Andrew Scott 9701047b9f test(common): Add circular deps test to 19.2.x (#61651)
adds circular deps test for http client to 19.2.x branch

PR Close #61651
2025-05-23 11:48:32 -07:00
Andrew Scott 2c876b4fc5 fix(common): avoid injecting ApplicationRef in FetchBackend (#61649)
fixes a circular dependency caused by injecting applicationRef

fixes #61644

PR Close #61649
2025-05-23 10:04:10 -07: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
Andrew Scott e38cc41cc4 release: cut the zone.js-0.15.1 release (#61632)
PR Close #61632
2025-05-22 14:53:18 -07:00
Joey Perrott d4d4be80a5 build: migrate localize package to use rules_js (#61615)
Use ts_project to build localize package

PR Close #61615
2025-05-22 13:45:27 -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
arturovt b15bddfa04 fix(service-worker): do not register service worker if app is destroyed before it is ready to register (#61101)
In this commit, we check whether the application is destroyed before calling `serviceWorker.register(...)`. We should not register the worker because other resources will not be available.

PR Close #61101
2025-05-22 10:02:40 -07:00
Andrew Scott 5f1bd07296 fix(zone.js): classes that extend Error should retain cause property (#61599)
ZoneAwareError previously did not copy the cause property over to the
`this` object when an error extends the native error class.

PR Close #61599
2025-05-21 20:43:10 -07:00
Joey Perrott 6f6e91d52d build: add comment explaining path maps (#61584)
Add a commend explaning why the path mappings are in place.

PR Close #61584
2025-05-21 17:27:19 +00: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 fc2483e7e9 refactor(compiler): avoid duplication between FactoryTarget type (#61571)
Avoids duplication of the `FactoryTarget` enums. This is necessary
now because we are exposing the previously deeply-imported JIT facade
now via the exports; and the typing integration tests surface a type
conflict due to the different duplicated enums.

PR Close #61571
2025-05-21 16:04:42 +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
Paul Gschwendtner 8e54b5773f build: move private testing helpers outside platform-browser/testing (#61571)
These helpers are often imported by various tests throughout the
repository, but the helpers aren't exported/exposed from the public
entry-point; even though they confusingly reside in there.

This commit fixes this, and moves the helpers into
`packages/private/testing`. This is a preparation for the `ts_project`
migration where we don't want to leverage deep imports between packages.

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
arturovt 126efc9972 fix(common): cancel reader when app is destroyed (#61528)
Streams left in a pending state (due to `break` without cancel) may continue consuming or holding onto data behind the scenes. Calling `reader.cancel()` allows the browser or the underlying system to release any network or memory resources associated with the stream.

PR Close #61528
2025-05-21 15:07:19 +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
Joey Perrott 72b80f9a87 build: migrate router to use rules_js (#61544)
Use ts_project and ng_project for building router

PR Close #61544
2025-05-21 09:55:22 +00:00
Joey Perrott 1007079aee build: update compiler-cli to not be stamped when used for the compiler in ng_project (#61539)
The compiler-cli package needs to be unstamped and will the resulting generated code will be stamped as expected.

PR Close #61539
2025-05-21 09:14:35 +00:00
Joey Perrott eac42293cf build: migrate forms to rules_js (#61539)
Migrate forms to use ng_project and ts_project

PR Close #61539
2025-05-21 09:14:35 +00:00
Andrew Scott 107180260f fix(compiler-cli): Always retain prior results for all files (#61487)
This change ensures that prior results for all files are retained even when
a request is made such that we only need a shim for a single file. Prior
to this change, any prior results that were not part of the request were discarded.

PR Close #61487
2025-05-21 08:56:54 +00:00
Joey Perrott d65cfde3fa build: migrate angular-in-memory-web-api to use rules_js (#61524)
Use ts_project and ng_project for building angular-in-memory-web-api

PR Close #61524
2025-05-20 16:53:21 +00:00
arturovt efda872453 fix(common): prevent reading chunks if app is destroyed (#61354)
Prevents processing response chunks after the application has been destroyed.

PR Close #61354
2025-05-20 15:09:45 +00:00
Joey Perrott c43fd3a39c build: migrate common to use rules_js based toolchain (#61434)
Migrate packages/common to use ts_project and ng_project.

PR Close #61434
2025-05-20 15:08:43 +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
Joey Perrott 71989056d8 build: use an unstamped version of compiler-cli for running the angular compiler in ng_project (#61479)
Use an unstamped version of the compiler when it runs in `ng_project` as it will get stamped appropriately
whenever the generated code gets stamped after its usage."

PR Close #61479
2025-05-20 08:46:35 +00:00
Joey Perrott 7f26df1608 build: migrate animations to use rules_js based toolchain (#61479)
Migrate animations to use `ts_project` and `ng_project`

PR Close #61479
2025-05-20 08:46:35 +00:00
Joey Perrott 40534d7de1 build: migrate benchpress to use rules_js (#61486)
Use ts_project to build targets in benchpress package

PR Close #61486
2025-05-20 08:44:55 +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
arturovt 9aedd30983 refactor(animations): mark non-default new expressions as pure (#61452)
Adds `__PURE__` annotations to non-default `new` expressions to enable tree-shaking, even if they are not referenced. These variables are not dropped when Angular is imported from a module that has `sideEffects` set to `true`.

PR Close #61452
2025-05-19 08:26:57 +00:00