镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ async function initBrowserSync(
target: `localhost:${nodeServerPort}`,
proxyOptions: {
xfwd: true,
changeOrigin: false,
},
proxyRes: [
(proxyRes) => {
Expand All @@ -277,7 +278,7 @@ async function initBrowserSync(
},
],
// proxyOptions is not in the typings
} as ProxyOptions & { proxyOptions: { xfwd: boolean } },
} as ProxyOptions & { proxyOptions: { xfwd: boolean; changeOrigin: boolean } },
host,
port: bsPort,
ui: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { Architect } from '@angular-devkit/architect';
// eslint-disable-next-line import/no-extraneous-dependencies
import * as browserSync from 'browser-sync';
import { get } from 'node:http';
import { createArchitect, host } from '../../../testing/test-utils';

describe('Serve SSR Builder - Works', () => {
Expand Down Expand Up @@ -95,4 +96,32 @@ describe('Serve SSR Builder - Works', () => {
expect(output.success).toBe(true);
expect(output.baseUrl).not.toContain('4200');
});

it('rejects requests with a disallowed Host header', async () => {
const run = await architect.scheduleTarget(target, { port: 0 });
try {
const output = await run.result;
expect(output.success).toBeTrue();

const statusCode = await new Promise<number | undefined>((resolve, reject) => {
const req = get(
{
hostname: 'localhost',
port: output.port,
path: '/',
headers: { host: 'example.com' },
},
(res) => {
res.resume();
resolve(res.statusCode);
},
);
req.on('error', reject);
});

expect(statusCode).toBe(500);
} finally {
await run.stop();
}
});
Comment thread
alan-agius4 marked this conversation as resolved.
});
Loading