astro 5.17.1 → 5.17.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  class BuildTimeAstroVersionProvider {
2
2
  // Injected during the build through esbuild define
3
- version = "5.17.1";
3
+ version = "5.17.2";
4
4
  }
5
5
  export {
6
6
  BuildTimeAstroVersionProvider
@@ -164,7 +164,7 @@ ${contentConfig.error.message}`);
164
164
  logger.info("Content config changed");
165
165
  shouldClear = true;
166
166
  }
167
- if (previousAstroVersion && previousAstroVersion !== "5.17.1") {
167
+ if (previousAstroVersion && previousAstroVersion !== "5.17.2") {
168
168
  logger.info("Astro version changed");
169
169
  shouldClear = true;
170
170
  }
@@ -172,8 +172,8 @@ ${contentConfig.error.message}`);
172
172
  logger.info("Clearing content store");
173
173
  this.#store.clearAll();
174
174
  }
175
- if ("5.17.1") {
176
- await this.#store.metaStore().set("astro-version", "5.17.1");
175
+ if ("5.17.2") {
176
+ await this.#store.metaStore().set("astro-version", "5.17.2");
177
177
  }
178
178
  if (currentConfigDigest) {
179
179
  await this.#store.metaStore().set("content-config-digest", currentConfigDigest);
@@ -4,6 +4,7 @@ import { clientAddressSymbol, nodeRequestAbortControllerCleanupSymbol } from "..
4
4
  import { deserializeManifest } from "./common.js";
5
5
  import { createOutgoingHttpHeaders } from "./createOutgoingHttpHeaders.js";
6
6
  import { App } from "./index.js";
7
+ import { validateForwardedHeaders, validateHost } from "./validate-headers.js";
7
8
  import { apply } from "../polyfill.js";
8
9
  class NodeApp extends App {
9
10
  headersMap = void 0;
@@ -50,26 +51,28 @@ class NodeApp extends App {
50
51
  return multiValueHeader?.toString()?.split(",").map((e) => e.trim())?.[0];
51
52
  };
52
53
  const providedProtocol = isEncrypted ? "https" : "http";
53
- const providedHostname = req.headers.host ?? req.headers[":authority"];
54
- const validated = App.validateForwardedHeaders(
54
+ const untrustedHostname = req.headers.host ?? req.headers[":authority"];
55
+ const validated = validateForwardedHeaders(
55
56
  getFirstForwardedValue(req.headers["x-forwarded-proto"]),
56
57
  getFirstForwardedValue(req.headers["x-forwarded-host"]),
57
58
  getFirstForwardedValue(req.headers["x-forwarded-port"]),
58
59
  allowedDomains
59
60
  );
60
61
  const protocol = validated.protocol ?? providedProtocol;
61
- const sanitizedProvidedHostname = App.sanitizeHost(
62
- typeof providedHostname === "string" ? providedHostname : void 0
62
+ const validatedHostname = validateHost(
63
+ typeof untrustedHostname === "string" ? untrustedHostname : void 0,
64
+ protocol,
65
+ allowedDomains
63
66
  );
64
- const hostname = validated.host ?? sanitizedProvidedHostname;
67
+ const hostname = validated.host ?? validatedHostname ?? "localhost";
65
68
  const port = validated.port;
66
69
  let url;
67
70
  try {
68
71
  const hostnamePort = getHostnamePort(hostname, port);
69
72
  url = new URL(`${protocol}://${hostnamePort}${req.url}`);
70
73
  } catch {
71
- const hostnamePort = getHostnamePort(providedHostname, port);
72
- url = new URL(`${providedProtocol}://${hostnamePort}`);
74
+ const hostnamePort = getHostnamePort(hostname, port);
75
+ url = new URL(`${protocol}://${hostnamePort}`);
73
76
  }
74
77
  const options = {
75
78
  method: req.method || "GET",
@@ -0,0 +1,17 @@
1
+ import { type RemotePattern } from '@astrojs/internal-helpers/remote';
2
+ /**
3
+ * Validate a host against allowedDomains.
4
+ * Returns the host only if it matches an allowed pattern, otherwise undefined.
5
+ * This prevents SSRF attacks by ensuring the Host header is trusted.
6
+ */
7
+ export declare function validateHost(host: string | undefined, protocol: string, allowedDomains?: Partial<RemotePattern>[]): string | undefined;
8
+ /**
9
+ * Validate forwarded headers (proto, host, port) against allowedDomains.
10
+ * Returns validated values or undefined for rejected headers.
11
+ * Uses strict defaults: http/https only for proto, rejects port if not in allowedDomains.
12
+ */
13
+ export declare function validateForwardedHeaders(forwardedProtocol?: string, forwardedHost?: string, forwardedPort?: string, allowedDomains?: Partial<RemotePattern>[]): {
14
+ protocol?: string;
15
+ host?: string;
16
+ port?: string;
17
+ };
@@ -0,0 +1,80 @@
1
+ import { matchPattern } from "@astrojs/internal-helpers/remote";
2
+ function sanitizeHost(hostname) {
3
+ if (!hostname) return void 0;
4
+ if (/[/\\]/.test(hostname)) return void 0;
5
+ return hostname;
6
+ }
7
+ function parseHost(host) {
8
+ const parts = host.split(":");
9
+ return {
10
+ hostname: parts[0],
11
+ port: parts[1]
12
+ };
13
+ }
14
+ function matchesAllowedDomains(hostname, protocol, port, allowedDomains) {
15
+ const hostWithPort = port ? `${hostname}:${port}` : hostname;
16
+ const urlString = `${protocol}://${hostWithPort}`;
17
+ if (!URL.canParse(urlString)) {
18
+ return false;
19
+ }
20
+ const testUrl = new URL(urlString);
21
+ return allowedDomains.some((pattern) => matchPattern(testUrl, pattern));
22
+ }
23
+ function validateHost(host, protocol, allowedDomains) {
24
+ if (!host || host.length === 0) return void 0;
25
+ if (!allowedDomains || allowedDomains.length === 0) return void 0;
26
+ const sanitized = sanitizeHost(host);
27
+ if (!sanitized) return void 0;
28
+ const { hostname, port } = parseHost(sanitized);
29
+ if (matchesAllowedDomains(hostname, protocol, port, allowedDomains)) {
30
+ return sanitized;
31
+ }
32
+ return void 0;
33
+ }
34
+ function validateForwardedHeaders(forwardedProtocol, forwardedHost, forwardedPort, allowedDomains) {
35
+ const result = {};
36
+ if (forwardedProtocol) {
37
+ if (allowedDomains && allowedDomains.length > 0) {
38
+ const hasProtocolPatterns = allowedDomains.some((pattern) => pattern.protocol !== void 0);
39
+ if (hasProtocolPatterns) {
40
+ try {
41
+ const testUrl = new URL(`${forwardedProtocol}://example.com`);
42
+ const isAllowed = allowedDomains.some((pattern) => matchPattern(testUrl, pattern));
43
+ if (isAllowed) {
44
+ result.protocol = forwardedProtocol;
45
+ }
46
+ } catch {
47
+ }
48
+ } else if (/^https?$/.test(forwardedProtocol)) {
49
+ result.protocol = forwardedProtocol;
50
+ }
51
+ } else if (/^https?$/.test(forwardedProtocol)) {
52
+ result.protocol = forwardedProtocol;
53
+ }
54
+ }
55
+ if (forwardedPort && allowedDomains && allowedDomains.length > 0) {
56
+ const hasPortPatterns = allowedDomains.some((pattern) => pattern.port !== void 0);
57
+ if (hasPortPatterns) {
58
+ const isAllowed = allowedDomains.some((pattern) => pattern.port === forwardedPort);
59
+ if (isAllowed) {
60
+ result.port = forwardedPort;
61
+ }
62
+ }
63
+ }
64
+ if (forwardedHost && forwardedHost.length > 0 && allowedDomains && allowedDomains.length > 0) {
65
+ const protoForValidation = result.protocol || "https";
66
+ const sanitized = sanitizeHost(forwardedHost);
67
+ if (sanitized) {
68
+ const { hostname, port: portFromHost } = parseHost(sanitized);
69
+ const portForValidation = result.port || portFromHost;
70
+ if (matchesAllowedDomains(hostname, protoForValidation, portForValidation, allowedDomains)) {
71
+ result.host = sanitized;
72
+ }
73
+ }
74
+ }
75
+ return result;
76
+ }
77
+ export {
78
+ validateForwardedHeaders,
79
+ validateHost
80
+ };
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "5.17.1";
1
+ const ASTRO_VERSION = "5.17.2";
2
2
  const REROUTE_DIRECTIVE_HEADER = "X-Astro-Reroute";
3
3
  const REWRITE_DIRECTIVE_HEADER_KEY = "X-Astro-Rewrite";
4
4
  const REWRITE_DIRECTIVE_HEADER_VALUE = "yes";
@@ -22,7 +22,7 @@ async function dev(inlineConfig) {
22
22
  await telemetry.record([]);
23
23
  const restart = await createContainerWithAutomaticRestart({ inlineConfig, fs });
24
24
  const logger = restart.container.logger;
25
- const currentVersion = "5.17.1";
25
+ const currentVersion = "5.17.2";
26
26
  const isPrerelease = currentVersion.includes("-");
27
27
  if (!isPrerelease) {
28
28
  try {
@@ -38,7 +38,7 @@ function serverStart({
38
38
  host,
39
39
  base
40
40
  }) {
41
- const version = "5.17.1";
41
+ const version = "5.17.2";
42
42
  const localPrefix = `${dim("\u2503")} Local `;
43
43
  const networkPrefix = `${dim("\u2503")} Network `;
44
44
  const emptyPrefix = " ".repeat(11);
@@ -275,7 +275,7 @@ function printHelp({
275
275
  message.push(
276
276
  linebreak(),
277
277
  ` ${bgGreen(black(` ${commandName} `))} ${green(
278
- `v${"5.17.1"}`
278
+ `v${"5.17.2"}`
279
279
  )} ${headline}`
280
280
  );
281
281
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "5.17.1",
3
+ "version": "5.17.2",
4
4
  "description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.",
5
5
  "type": "module",
6
6
  "author": "withastro",
@@ -113,7 +113,7 @@
113
113
  "dlv": "^1.1.3",
114
114
  "dset": "^3.1.4",
115
115
  "es-module-lexer": "^1.7.0",
116
- "esbuild": "^0.25.0",
116
+ "esbuild": "^0.27.0",
117
117
  "estree-walker": "^3.0.3",
118
118
  "flattie": "^1.1.1",
119
119
  "fontace": "~0.4.0",
@@ -154,8 +154,8 @@
154
154
  "zod-to-json-schema": "^3.25.1",
155
155
  "zod-to-ts": "^1.2.0",
156
156
  "@astrojs/internal-helpers": "0.7.5",
157
- "@astrojs/telemetry": "3.3.0",
158
- "@astrojs/markdown-remark": "6.3.10"
157
+ "@astrojs/markdown-remark": "6.3.10",
158
+ "@astrojs/telemetry": "3.3.0"
159
159
  },
160
160
  "optionalDependencies": {
161
161
  "sharp": "^0.34.0"