-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(@angular/build): support Vite
allowedHosts
option for developme…
…nt server Vite version 6.0.9+, which is now used by the Angular CLI, contains a potentially breaking change for some development setups. Examples of such setups include those that use reverse proxies or custom host names during development. The change within a patch release was made by Vite to address a security vulnerability. For projects that directly access the development server via `localhost`, no changes should be needed. However, some development setups may now need to adjust the newly introduced `allowedHosts` development server option. This option can include an array of host names that are allowed to communicate with the development server. The option sets the corresponding Vite option within the Angular CLI. For more information on the option and its specific behavior, please see the Vite documentation located here: https://vite.dev/config/server-options.html#server-allowedhosts The following is an example of the configuration option allowing `example.com`: ``` "serve": { "builder": "@angular/build:dev-server", "options": { "allowedHosts": ["example.com"] }, ``` Additional details on the vulnerability can be found here: GHSA-vg6x-rcgg-rjx6
- Loading branch information
Showing
8 changed files
with
162 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
packages/angular/build/src/builders/dev-server/tests/options/allowed-hosts_spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.dev/license | ||
*/ | ||
|
||
import { executeDevServer } from '../../index'; | ||
import { executeOnceAndGet } from '../execute-fetch'; | ||
import { describeServeBuilder } from '../jasmine-helpers'; | ||
import { BASE_OPTIONS, DEV_SERVER_BUILDER_INFO } from '../setup'; | ||
|
||
const FETCH_HEADERS = Object.freeze({ Host: 'example.com' }); | ||
|
||
describeServeBuilder(executeDevServer, DEV_SERVER_BUILDER_INFO, (harness, setupTarget) => { | ||
describe('option: "allowedHosts"', () => { | ||
beforeEach(async () => { | ||
setupTarget(harness); | ||
|
||
// Application code is not needed for these tests | ||
await harness.writeFile('src/main.ts', ''); | ||
}); | ||
|
||
it('does not allow an invalid host when option is not present', async () => { | ||
harness.useTarget('serve', { | ||
...BASE_OPTIONS, | ||
}); | ||
|
||
const { result, response } = await executeOnceAndGet(harness, '/', { | ||
request: { headers: FETCH_HEADERS }, | ||
}); | ||
|
||
expect(result?.success).toBeTrue(); | ||
expect(response?.statusCode).toBe(403); | ||
}); | ||
|
||
it('does not allow an invalid host when option is an empty array', async () => { | ||
harness.useTarget('serve', { | ||
...BASE_OPTIONS, | ||
allowedHosts: [], | ||
}); | ||
|
||
const { result, response } = await executeOnceAndGet(harness, '/', { | ||
request: { headers: FETCH_HEADERS }, | ||
}); | ||
|
||
expect(result?.success).toBeTrue(); | ||
expect(response?.statusCode).toBe(403); | ||
}); | ||
|
||
it('allows a host when specified in the option', async () => { | ||
harness.useTarget('serve', { | ||
...BASE_OPTIONS, | ||
allowedHosts: ['example.com'], | ||
}); | ||
|
||
const { result, content } = await executeOnceAndGet(harness, '/', { | ||
request: { headers: FETCH_HEADERS }, | ||
}); | ||
|
||
expect(result?.success).toBeTrue(); | ||
expect(content).toContain('<title>'); | ||
}); | ||
|
||
it('allows a host when option is true', async () => { | ||
harness.useTarget('serve', { | ||
...BASE_OPTIONS, | ||
allowedHosts: true, | ||
}); | ||
|
||
const { result, content } = await executeOnceAndGet(harness, '/', { | ||
request: { headers: FETCH_HEADERS }, | ||
}); | ||
|
||
expect(result?.success).toBeTrue(); | ||
expect(content).toContain('<title>'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters