Skip to content

Commit ec307b0

Browse files
matthewpastrobot-houston
authored andcommitted
[ci] format
1 parent 6ee63bf commit ec307b0

4 files changed

Lines changed: 22 additions & 12 deletions

File tree

packages/astro/src/core/app/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,12 @@ export class App {
153153
static validateForwardedHost(
154154
forwardedHost: string,
155155
allowedDomains?: Partial<RemotePattern>[],
156-
protocol?: string
156+
protocol?: string,
157157
): boolean {
158158
if (!allowedDomains || allowedDomains.length === 0) {
159159
return false;
160160
}
161-
161+
162162
try {
163163
const testUrl = new URL(`${protocol || 'https'}://${forwardedHost}`);
164164
return allowedDomains.some((pattern) => {
@@ -278,13 +278,13 @@ export class App {
278278
// we fall back to the protocol of the request
279279
protocol = url.protocol;
280280
}
281-
281+
282282
// Validate X-Forwarded-Host against allowedDomains if configured
283283
if (forwardedHost && !this.matchesAllowedDomains(forwardedHost, protocol)) {
284284
// If not allowed, ignore the X-Forwarded-Host header
285285
forwardedHost = null;
286286
}
287-
287+
288288
let host = forwardedHost;
289289
if (!host) {
290290
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Host

packages/astro/src/core/app/node.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ export class NodeApp extends App {
7373
*/
7474
static createRequest(
7575
req: NodeRequest,
76-
{ skipBody = false, allowedDomains = [] }: { skipBody?: boolean; allowedDomains?: Partial<RemotePattern>[] } = {},
76+
{
77+
skipBody = false,
78+
allowedDomains = [],
79+
}: { skipBody?: boolean; allowedDomains?: Partial<RemotePattern>[] } = {},
7780
): Request {
7881
const controller = new AbortController();
7982

@@ -98,13 +101,20 @@ export class NodeApp extends App {
98101
// @example "example.com,www2.example.com" => "example.com"
99102
let forwardedHostname = getFirstForwardedValue(req.headers['x-forwarded-host']);
100103
const providedHostname = req.headers.host ?? req.headers[':authority'];
101-
104+
102105
// Validate X-Forwarded-Host against allowedDomains if configured
103-
if (forwardedHostname && !App.validateForwardedHost(forwardedHostname, allowedDomains, forwardedProtocol ?? providedProtocol)) {
106+
if (
107+
forwardedHostname &&
108+
!App.validateForwardedHost(
109+
forwardedHostname,
110+
allowedDomains,
111+
forwardedProtocol ?? providedProtocol,
112+
)
113+
) {
104114
// If not allowed, ignore the X-Forwarded-Host header
105115
forwardedHostname = undefined;
106116
}
107-
117+
108118
const hostname = forwardedHostname ?? providedHostname;
109119

110120
// @example "443,8080,80" => "443"

packages/integrations/node/src/serve-app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function createAppHandler(app: NodeApp, options: Options): RequestHandler
3737
let request: Request;
3838
try {
3939
request = NodeApp.createRequest(req, {
40-
allowedDomains: app.getAllowedDomains()
40+
allowedDomains: app.getAllowedDomains(),
4141
});
4242
} catch (err) {
4343
logger.error(`Could not render ${req.url}`);

packages/integrations/node/test/url.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ describe('URL', () => {
8080
'X-Forwarded-Proto': 'https',
8181
'X-Forwarded-Host': 'abc.xyz',
8282
'X-Forwarded-Port': '444',
83-
'Host': 'localhost:3000',
83+
Host: 'localhost:3000',
8484
},
8585
url: '/',
8686
});
@@ -120,7 +120,7 @@ describe('URL', () => {
120120
headers: {
121121
'X-Forwarded-Proto': 'https',
122122
'X-Forwarded-Host': 'malicious.example.com',
123-
'Host': 'legitimate.example.com',
123+
Host: 'legitimate.example.com',
124124
},
125125
url: '/',
126126
});
@@ -141,7 +141,7 @@ describe('URL', () => {
141141
headers: {
142142
'X-Forwarded-Proto': 'https',
143143
'X-Forwarded-Host': 'abc.xyz:8080',
144-
'Host': 'localhost:3000',
144+
Host: 'localhost:3000',
145145
},
146146
url: '/',
147147
});

0 commit comments

Comments
 (0)