@valbuild/server 0.153.5 → 0.153.6

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.
Files changed (26) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/browser/dist/valbuild-server-browser.cjs.dev.js +2 -2
  3. package/browser/dist/valbuild-server-browser.cjs.prod.js +2 -2
  4. package/browser/dist/valbuild-server-browser.esm.js +2 -2
  5. package/dist/{ValRouter-2ff58de9.cjs.dev.js → ValRouter-480ecf99.cjs.dev.js} +42 -4
  6. package/dist/{ValRouter-60ee2fa5.cjs.prod.js → ValRouter-b12133a1.cjs.prod.js} +42 -4
  7. package/dist/{ValRouter-072c3dee.esm.js → ValRouter-f4f5348d.esm.js} +42 -4
  8. package/dist/{ValRouterCore-4e3757ac.cjs.dev.js → ValRouterCore-3d7d2581.cjs.prod.js} +264 -14
  9. package/dist/{ValRouterCore-257f140c.esm.js → ValRouterCore-c418ffb7.esm.js} +259 -15
  10. package/dist/{ValRouterCore-d658dc75.cjs.prod.js → ValRouterCore-cbf1de67.cjs.dev.js} +264 -14
  11. package/dist/{inTabFetch-7f2c9455.cjs.prod.js → inTabFetch-5ef58dda.cjs.prod.js} +1 -1
  12. package/dist/{inTabFetch-09f7ae69.cjs.dev.js → inTabFetch-99450193.cjs.dev.js} +1 -1
  13. package/dist/{inTabFetch-0157c4a1.esm.js → inTabFetch-cb415a9d.esm.js} +1 -1
  14. package/dist/{publishKit-26231426.cjs.prod.js → publishKit-482747e2.cjs.prod.js} +2 -2
  15. package/dist/{publishKit-89923030.esm.js → publishKit-c2bcff27.esm.js} +3 -3
  16. package/dist/{publishKit-5227c288.cjs.dev.js → publishKit-f98d8cd1.cjs.dev.js} +2 -2
  17. package/dist/valbuild-server.cjs.dev.js +2 -2
  18. package/dist/valbuild-server.cjs.prod.js +2 -2
  19. package/dist/valbuild-server.esm.js +4 -4
  20. package/internal/browser/dist/valbuild-server-internal-browser.cjs.dev.js +2 -2
  21. package/internal/browser/dist/valbuild-server-internal-browser.cjs.prod.js +2 -2
  22. package/internal/browser/dist/valbuild-server-internal-browser.esm.js +2 -2
  23. package/internal/dist/valbuild-server-internal.cjs.dev.js +2 -2
  24. package/internal/dist/valbuild-server-internal.cjs.prod.js +2 -2
  25. package/internal/dist/valbuild-server-internal.esm.js +2 -2
  26. package/package.json +5 -5
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @valbuild/server
2
2
 
3
+ ## 0.153.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1057](https://github.com/valbuild/val/pull/1057) [`79b4452`](https://github.com/valbuild/val/commit/79b4452441ae2a9442f1217cca372f2d7cebd5a4) Thanks [@freekh](https://github.com/freekh)! - Security fixes. Update if you run Val's dev server, or have deployed a site without `VAL_API_KEY` and `VAL_SECRET`.
8
+
9
+ - **`/api/val/files` serves media only.** It answered any path in the project, without a sign-in: `/api/val/files/.env` returned the file. It now serves files under `/public`, and their drafts, and nothing else.
10
+ - **An upload cannot be written outside Val's patch store.** A file's path and a patch's id are checked before anything is written or read, so a path with `..` in it is refused.
11
+ - **In local filesystem mode, the API answers only your own Studio.** A request from another site's page is refused, and so is one addressed to a host name that is not `localhost` or an IP address. If you develop on another name (`my-app.test`, a tunnel that passes its own `Host`), list it in the `VAL_ALLOWED_HOSTS` environment variable, comma separated.
12
+ - **A deployed site without credentials no longer serves the API.** Without `VAL_API_KEY` and `VAL_SECRET` an app runs in local filesystem mode, which has no sign-in. With `NODE_ENV=production` it now refuses, and says what to set.
13
+ - **`redirect_to` stays on your site.** `/api/val/logout`, `/enable`, `/disable` and `/authorize` redirected to any URL they were given. They now accept a path, or a URL on the same site.
14
+ - **Draft mode is turned on after sign-in**, not when the sign-in starts, so a visitor who is not signed in can no longer switch it on.
15
+ - `image-size`, `simple-git` and `zod` are updated past their published advisories.
16
+
17
+ - Updated dependencies [[`a561665`](https://github.com/valbuild/val/commit/a5616659c202eaa5ad61e1a035c9b9ca2a007e9a), [`00b13fe`](https://github.com/valbuild/val/commit/00b13fe0ed9adc2ce22b3e9827e9fa5b10d5bfdf), [`79b4452`](https://github.com/valbuild/val/commit/79b4452441ae2a9442f1217cca372f2d7cebd5a4), [`3944e3e`](https://github.com/valbuild/val/commit/3944e3e3c33678bca2a0aa46fcc0f4adbf8c2ba5), [`a8a1056`](https://github.com/valbuild/val/commit/a8a105620849ff73b91aff1492c39548926a7a7f), [`2c98fcc`](https://github.com/valbuild/val/commit/2c98fcc776f15c979dae74a1a86ca91cad70e7de), [`0dd664f`](https://github.com/valbuild/val/commit/0dd664f7bde9bfb552ecd643b2345998c69d5914)]:
18
+ - @valbuild/ui@0.153.6
19
+ - @valbuild/shared@0.153.6
20
+
3
21
  ## 0.153.5
4
22
 
5
23
  ### Patch Changes
@@ -2,9 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var inTabFetch = require('../../dist/inTabFetch-09f7ae69.cjs.dev.js');
5
+ var inTabFetch = require('../../dist/inTabFetch-99450193.cjs.dev.js');
6
6
  require('@valbuild/core');
7
- require('../../dist/ValRouterCore-4e3757ac.cjs.dev.js');
7
+ require('../../dist/ValRouterCore-cbf1de67.cjs.dev.js');
8
8
  require('zod');
9
9
  require('@valbuild/shared/internal');
10
10
  require('zod-validation-error');
@@ -2,9 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var inTabFetch = require('../../dist/inTabFetch-7f2c9455.cjs.prod.js');
5
+ var inTabFetch = require('../../dist/inTabFetch-5ef58dda.cjs.prod.js');
6
6
  require('@valbuild/core');
7
- require('../../dist/ValRouterCore-d658dc75.cjs.prod.js');
7
+ require('../../dist/ValRouterCore-3d7d2581.cjs.prod.js');
8
8
  require('zod');
9
9
  require('@valbuild/shared/internal');
10
10
  require('zod-validation-error');
@@ -1,6 +1,6 @@
1
- export { c as createInTabValFetch } from '../../dist/inTabFetch-0157c4a1.esm.js';
1
+ export { c as createInTabValFetch } from '../../dist/inTabFetch-cb415a9d.esm.js';
2
2
  import '@valbuild/core';
3
- import '../../dist/ValRouterCore-257f140c.esm.js';
3
+ import '../../dist/ValRouterCore-c418ffb7.esm.js';
4
4
  import 'zod';
5
5
  import '@valbuild/shared/internal';
6
6
  import 'zod-validation-error';
@@ -2,7 +2,7 @@
2
2
 
3
3
  var core = require('@valbuild/core');
4
4
  var server = require('@valbuild/ui/server');
5
- var ValRouterCore = require('./ValRouterCore-4e3757ac.cjs.dev.js');
5
+ var ValRouterCore = require('./ValRouterCore-cbf1de67.cjs.dev.js');
6
6
  var path = require('path');
7
7
  var ts = require('typescript');
8
8
  var z = require('zod');
@@ -2205,7 +2205,7 @@ function createFsSketchpadStore(rootDir, now = () => new Date()) {
2205
2205
  * as a bundler does.
2206
2206
  */
2207
2207
  function loadTypeScriptKit() {
2208
- return Promise.resolve().then(function () { return require('./publishKit-5227c288.cjs.dev.js'); });
2208
+ return Promise.resolve().then(function () { return require('./publishKit-f98d8cd1.cjs.dev.js'); });
2209
2209
  }
2210
2210
 
2211
2211
  /** Serializes a schema, or gives up quietly — serialization errors are reported elsewhere. */
@@ -2963,6 +2963,21 @@ class ValOpsFS extends ValRouterCore.ValOps {
2963
2963
  //
2964
2964
  // Staging is what makes that state unreachable rather than tolerated. See
2965
2965
  // `uploadsDir`.
2966
+ // Both are joined onto the patches directory below. See `safeFilePath`.
2967
+ if (!ValRouterCore.isSafePatchId(patchId)) {
2968
+ return {
2969
+ error: {
2970
+ message: "Not a valid patch id."
2971
+ }
2972
+ };
2973
+ }
2974
+ if (!ValRouterCore.isMediaFilePath(filePath)) {
2975
+ return {
2976
+ error: {
2977
+ message: `Cannot store a file at '${filePath}'. ${ValRouterCore.MEDIA_FILE_PATH_ACCEPTS}`
2978
+ }
2979
+ };
2980
+ }
2966
2981
  const patchesDir = this.getPatchesDir();
2967
2982
  const patchFilePath = stagedPatchBinaryFile(patchesDir, patchId, filePath);
2968
2983
  const metadataFilePath = stagedPatchBinaryFileMetadata(patchesDir, patchId, filePath);
@@ -3070,6 +3085,9 @@ class ValOpsFS extends ValRouterCore.ValOps {
3070
3085
  async getBase64EncodedBinaryFileFromPatch(filePath, patchId) {
3071
3086
  // Straight from the id. This used to read and parse every patch on disk to
3072
3087
  // work out which directory the file was under, on every single image request.
3088
+ if (!ValRouterCore.isSafePatchId(patchId) || !ValRouterCore.isMediaFilePath(filePath)) {
3089
+ return null;
3090
+ }
3073
3091
  const patchesDir = this.getPatchesDir();
3074
3092
  const absPath = this.wherePatchFileIs(patchBinaryFile(patchesDir, patchId, filePath), stagedPatchBinaryFile(patchesDir, patchId, filePath));
3075
3093
  if (absPath === null) {
@@ -3267,6 +3285,16 @@ class ValOpsFS extends ValRouterCore.ValOps {
3267
3285
  }] of localFileDescriptors) {
3268
3286
  const filePath = ref;
3269
3287
  const absPath = path__default["default"].join(this.rootDir, ...filePath.split("/"));
3288
+ // A publish writes uploaded files under /public and nowhere else.
3289
+ // `createPatch` refuses any other path, so this is for a patch that was
3290
+ // already on disk, or put there by hand.
3291
+ if (!ValRouterCore.isPublicFilePath(filePath) || !ValRouterCore.isSafePatchId(patchId)) {
3292
+ errors[absPath] = {
3293
+ message: `Not written: '${filePath}' is not under /public.`,
3294
+ filePath
3295
+ };
3296
+ continue;
3297
+ }
3270
3298
  try {
3271
3299
  this.host.copyFile(patchBinaryFile(this.getPatchesDir(), patchId, filePath), absPath);
3272
3300
  updatedFiles.push(absPath);
@@ -3317,6 +3345,9 @@ class ValOpsFS extends ValRouterCore.ValOps {
3317
3345
  async openBinaryFile(filePath, fromPatch) {
3318
3346
  let absPath;
3319
3347
  if (fromPatch) {
3348
+ if (!ValRouterCore.isSafePatchId(fromPatch.patchId) || !ValRouterCore.isMediaFilePath(filePath)) {
3349
+ return null;
3350
+ }
3320
3351
  const patchesDir = this.getPatchesDir();
3321
3352
  absPath = this.wherePatchFileIs(patchBinaryFile(patchesDir, fromPatch.patchId, filePath), stagedPatchBinaryFile(patchesDir, fromPatch.patchId, filePath));
3322
3353
  } else {
@@ -4989,7 +5020,7 @@ async function stagedModuleSources(files) {
4989
5020
  parseValFile,
4990
5021
  analyzeValModule,
4991
5022
  evaluateModuleSource
4992
- } = await Promise.resolve().then(function () { return require('./publishKit-5227c288.cjs.dev.js'); });
5023
+ } = await Promise.resolve().then(function () { return require('./publishKit-f98d8cd1.cjs.dev.js'); });
4993
5024
  const sources = {};
4994
5025
  for (const {
4995
5026
  path,
@@ -14328,7 +14359,7 @@ commitPrepared,
14328
14359
  publishOverride) {
14329
14360
  var _opts$versions;
14330
14361
  const valServerConfig = await initHandlerOptions(route, opts, config);
14331
- return ValRouterCore.ValServer(valModules, {
14362
+ const server = ValRouterCore.ValServer(valModules, {
14332
14363
  formatter,
14333
14364
  commitPrepared,
14334
14365
  publishOverride,
@@ -14340,6 +14371,13 @@ publishOverride) {
14340
14371
  } : {}),
14341
14372
  ...valServerConfig
14342
14373
  }, callbacks, nodePlatform);
14374
+ // fs mode has no sign-in, so which requests it answers is decided here.
14375
+ ValRouterCore.setRequestGuard(server, {
14376
+ mode: valServerConfig.mode,
14377
+ production: process.env.NODE_ENV === "production",
14378
+ allowedHosts: ValRouterCore.parseAllowedHosts(process.env.VAL_ALLOWED_HOSTS)
14379
+ });
14380
+ return server;
14343
14381
  }
14344
14382
 
14345
14383
  /**
@@ -2,7 +2,7 @@
2
2
 
3
3
  var core = require('@valbuild/core');
4
4
  var server = require('@valbuild/ui/server');
5
- var ValRouterCore = require('./ValRouterCore-d658dc75.cjs.prod.js');
5
+ var ValRouterCore = require('./ValRouterCore-3d7d2581.cjs.prod.js');
6
6
  var path = require('path');
7
7
  var ts = require('typescript');
8
8
  var z = require('zod');
@@ -2205,7 +2205,7 @@ function createFsSketchpadStore(rootDir, now = () => new Date()) {
2205
2205
  * as a bundler does.
2206
2206
  */
2207
2207
  function loadTypeScriptKit() {
2208
- return Promise.resolve().then(function () { return require('./publishKit-26231426.cjs.prod.js'); });
2208
+ return Promise.resolve().then(function () { return require('./publishKit-482747e2.cjs.prod.js'); });
2209
2209
  }
2210
2210
 
2211
2211
  /** Serializes a schema, or gives up quietly — serialization errors are reported elsewhere. */
@@ -2963,6 +2963,21 @@ class ValOpsFS extends ValRouterCore.ValOps {
2963
2963
  //
2964
2964
  // Staging is what makes that state unreachable rather than tolerated. See
2965
2965
  // `uploadsDir`.
2966
+ // Both are joined onto the patches directory below. See `safeFilePath`.
2967
+ if (!ValRouterCore.isSafePatchId(patchId)) {
2968
+ return {
2969
+ error: {
2970
+ message: "Not a valid patch id."
2971
+ }
2972
+ };
2973
+ }
2974
+ if (!ValRouterCore.isMediaFilePath(filePath)) {
2975
+ return {
2976
+ error: {
2977
+ message: `Cannot store a file at '${filePath}'. ${ValRouterCore.MEDIA_FILE_PATH_ACCEPTS}`
2978
+ }
2979
+ };
2980
+ }
2966
2981
  const patchesDir = this.getPatchesDir();
2967
2982
  const patchFilePath = stagedPatchBinaryFile(patchesDir, patchId, filePath);
2968
2983
  const metadataFilePath = stagedPatchBinaryFileMetadata(patchesDir, patchId, filePath);
@@ -3070,6 +3085,9 @@ class ValOpsFS extends ValRouterCore.ValOps {
3070
3085
  async getBase64EncodedBinaryFileFromPatch(filePath, patchId) {
3071
3086
  // Straight from the id. This used to read and parse every patch on disk to
3072
3087
  // work out which directory the file was under, on every single image request.
3088
+ if (!ValRouterCore.isSafePatchId(patchId) || !ValRouterCore.isMediaFilePath(filePath)) {
3089
+ return null;
3090
+ }
3073
3091
  const patchesDir = this.getPatchesDir();
3074
3092
  const absPath = this.wherePatchFileIs(patchBinaryFile(patchesDir, patchId, filePath), stagedPatchBinaryFile(patchesDir, patchId, filePath));
3075
3093
  if (absPath === null) {
@@ -3267,6 +3285,16 @@ class ValOpsFS extends ValRouterCore.ValOps {
3267
3285
  }] of localFileDescriptors) {
3268
3286
  const filePath = ref;
3269
3287
  const absPath = path__default["default"].join(this.rootDir, ...filePath.split("/"));
3288
+ // A publish writes uploaded files under /public and nowhere else.
3289
+ // `createPatch` refuses any other path, so this is for a patch that was
3290
+ // already on disk, or put there by hand.
3291
+ if (!ValRouterCore.isPublicFilePath(filePath) || !ValRouterCore.isSafePatchId(patchId)) {
3292
+ errors[absPath] = {
3293
+ message: `Not written: '${filePath}' is not under /public.`,
3294
+ filePath
3295
+ };
3296
+ continue;
3297
+ }
3270
3298
  try {
3271
3299
  this.host.copyFile(patchBinaryFile(this.getPatchesDir(), patchId, filePath), absPath);
3272
3300
  updatedFiles.push(absPath);
@@ -3317,6 +3345,9 @@ class ValOpsFS extends ValRouterCore.ValOps {
3317
3345
  async openBinaryFile(filePath, fromPatch) {
3318
3346
  let absPath;
3319
3347
  if (fromPatch) {
3348
+ if (!ValRouterCore.isSafePatchId(fromPatch.patchId) || !ValRouterCore.isMediaFilePath(filePath)) {
3349
+ return null;
3350
+ }
3320
3351
  const patchesDir = this.getPatchesDir();
3321
3352
  absPath = this.wherePatchFileIs(patchBinaryFile(patchesDir, fromPatch.patchId, filePath), stagedPatchBinaryFile(patchesDir, fromPatch.patchId, filePath));
3322
3353
  } else {
@@ -4989,7 +5020,7 @@ async function stagedModuleSources(files) {
4989
5020
  parseValFile,
4990
5021
  analyzeValModule,
4991
5022
  evaluateModuleSource
4992
- } = await Promise.resolve().then(function () { return require('./publishKit-26231426.cjs.prod.js'); });
5023
+ } = await Promise.resolve().then(function () { return require('./publishKit-482747e2.cjs.prod.js'); });
4993
5024
  const sources = {};
4994
5025
  for (const {
4995
5026
  path,
@@ -14328,7 +14359,7 @@ commitPrepared,
14328
14359
  publishOverride) {
14329
14360
  var _opts$versions;
14330
14361
  const valServerConfig = await initHandlerOptions(route, opts, config);
14331
- return ValRouterCore.ValServer(valModules, {
14362
+ const server = ValRouterCore.ValServer(valModules, {
14332
14363
  formatter,
14333
14364
  commitPrepared,
14334
14365
  publishOverride,
@@ -14340,6 +14371,13 @@ publishOverride) {
14340
14371
  } : {}),
14341
14372
  ...valServerConfig
14342
14373
  }, callbacks, nodePlatform);
14374
+ // fs mode has no sign-in, so which requests it answers is decided here.
14375
+ ValRouterCore.setRequestGuard(server, {
14376
+ mode: valServerConfig.mode,
14377
+ production: "production" === "production",
14378
+ allowedHosts: ValRouterCore.parseAllowedHosts(process.env.VAL_ALLOWED_HOSTS)
14379
+ });
14380
+ return server;
14343
14381
  }
14344
14382
 
14345
14383
  /**
@@ -1,6 +1,6 @@
1
1
  import { Internal, deserializeSchema, DEFAULT_CONTENT_HOST, DEFAULT_VAL_REMOTE_HOST } from '@valbuild/core';
2
2
  import { createUIRequestHandler } from '@valbuild/ui/server';
3
- import { r as resolveExistingJsonPath, s as summaryOf, m as matchesFilter, h as byUpdatedAt, n as newSketchpad, i as isSketchpadId, j as applySketchpadChange, k as ValOps, V as VAL_CLIENT_HEADERS, l as bufferFromDataUrl, o as getFieldsForType, u as uploadRemoteFile, d as getFileExt, p as guessMimeTypeFromPath, q as createMetadataFromBuffer, D as DEFAULT_ANALYTICS_INGEST_URL, e as ValOpsMemory, t as sessionAuth, w as isHttpOps, x as isHlsMasterPlaylist, y as sumHlsSegmentDurations, z as parseHlsMasterVariants, A as largestHlsVariant, B as fallbackRefOf, C as mapHlsUris, E as movedRemoteHost, F as needsHostCheck, G as rewriteRefHost, H as fallbackRemoteHost, J as checkRemoteFiles, K as ValServer, L as createValRequestHandler } from './ValRouterCore-257f140c.esm.js';
3
+ import { r as resolveExistingJsonPath, s as summaryOf, m as matchesFilter, h as byUpdatedAt, n as newSketchpad, i as isSketchpadId, j as applySketchpadChange, k as ValOps, V as VAL_CLIENT_HEADERS, l as isSafePatchId, o as isMediaFilePath, M as MEDIA_FILE_PATH_ACCEPTS, p as bufferFromDataUrl, q as getFieldsForType, u as uploadRemoteFile, d as getFileExt, t as isPublicFilePath, w as guessMimeTypeFromPath, x as createMetadataFromBuffer, D as DEFAULT_ANALYTICS_INGEST_URL, e as ValOpsMemory, y as sessionAuth, z as isHttpOps, A as isHlsMasterPlaylist, B as sumHlsSegmentDurations, C as parseHlsMasterVariants, E as largestHlsVariant, F as fallbackRefOf, G as mapHlsUris, H as movedRemoteHost, J as needsHostCheck, K as rewriteRefHost, L as fallbackRemoteHost, N as checkRemoteFiles, O as ValServer, P as setRequestGuard, Q as parseAllowedHosts, R as createValRequestHandler } from './ValRouterCore-c418ffb7.esm.js';
4
4
  import path from 'path';
5
5
  import ts from 'typescript';
6
6
  import { z } from 'zod';
@@ -2171,7 +2171,7 @@ function createFsSketchpadStore(rootDir, now = () => new Date()) {
2171
2171
  * as a bundler does.
2172
2172
  */
2173
2173
  function loadTypeScriptKit() {
2174
- return import('./publishKit-89923030.esm.js');
2174
+ return import('./publishKit-c2bcff27.esm.js');
2175
2175
  }
2176
2176
 
2177
2177
  /** Serializes a schema, or gives up quietly — serialization errors are reported elsewhere. */
@@ -2929,6 +2929,21 @@ class ValOpsFS extends ValOps {
2929
2929
  //
2930
2930
  // Staging is what makes that state unreachable rather than tolerated. See
2931
2931
  // `uploadsDir`.
2932
+ // Both are joined onto the patches directory below. See `safeFilePath`.
2933
+ if (!isSafePatchId(patchId)) {
2934
+ return {
2935
+ error: {
2936
+ message: "Not a valid patch id."
2937
+ }
2938
+ };
2939
+ }
2940
+ if (!isMediaFilePath(filePath)) {
2941
+ return {
2942
+ error: {
2943
+ message: `Cannot store a file at '${filePath}'. ${MEDIA_FILE_PATH_ACCEPTS}`
2944
+ }
2945
+ };
2946
+ }
2932
2947
  const patchesDir = this.getPatchesDir();
2933
2948
  const patchFilePath = stagedPatchBinaryFile(patchesDir, patchId, filePath);
2934
2949
  const metadataFilePath = stagedPatchBinaryFileMetadata(patchesDir, patchId, filePath);
@@ -3036,6 +3051,9 @@ class ValOpsFS extends ValOps {
3036
3051
  async getBase64EncodedBinaryFileFromPatch(filePath, patchId) {
3037
3052
  // Straight from the id. This used to read and parse every patch on disk to
3038
3053
  // work out which directory the file was under, on every single image request.
3054
+ if (!isSafePatchId(patchId) || !isMediaFilePath(filePath)) {
3055
+ return null;
3056
+ }
3039
3057
  const patchesDir = this.getPatchesDir();
3040
3058
  const absPath = this.wherePatchFileIs(patchBinaryFile(patchesDir, patchId, filePath), stagedPatchBinaryFile(patchesDir, patchId, filePath));
3041
3059
  if (absPath === null) {
@@ -3233,6 +3251,16 @@ class ValOpsFS extends ValOps {
3233
3251
  }] of localFileDescriptors) {
3234
3252
  const filePath = ref;
3235
3253
  const absPath = path.join(this.rootDir, ...filePath.split("/"));
3254
+ // A publish writes uploaded files under /public and nowhere else.
3255
+ // `createPatch` refuses any other path, so this is for a patch that was
3256
+ // already on disk, or put there by hand.
3257
+ if (!isPublicFilePath(filePath) || !isSafePatchId(patchId)) {
3258
+ errors[absPath] = {
3259
+ message: `Not written: '${filePath}' is not under /public.`,
3260
+ filePath
3261
+ };
3262
+ continue;
3263
+ }
3236
3264
  try {
3237
3265
  this.host.copyFile(patchBinaryFile(this.getPatchesDir(), patchId, filePath), absPath);
3238
3266
  updatedFiles.push(absPath);
@@ -3283,6 +3311,9 @@ class ValOpsFS extends ValOps {
3283
3311
  async openBinaryFile(filePath, fromPatch) {
3284
3312
  let absPath;
3285
3313
  if (fromPatch) {
3314
+ if (!isSafePatchId(fromPatch.patchId) || !isMediaFilePath(filePath)) {
3315
+ return null;
3316
+ }
3286
3317
  const patchesDir = this.getPatchesDir();
3287
3318
  absPath = this.wherePatchFileIs(patchBinaryFile(patchesDir, fromPatch.patchId, filePath), stagedPatchBinaryFile(patchesDir, fromPatch.patchId, filePath));
3288
3319
  } else {
@@ -4955,7 +4986,7 @@ async function stagedModuleSources(files) {
4955
4986
  parseValFile,
4956
4987
  analyzeValModule,
4957
4988
  evaluateModuleSource
4958
- } = await import('./publishKit-89923030.esm.js');
4989
+ } = await import('./publishKit-c2bcff27.esm.js');
4959
4990
  const sources = {};
4960
4991
  for (const {
4961
4992
  path,
@@ -14294,7 +14325,7 @@ commitPrepared,
14294
14325
  publishOverride) {
14295
14326
  var _opts$versions;
14296
14327
  const valServerConfig = await initHandlerOptions(route, opts, config);
14297
- return ValServer(valModules, {
14328
+ const server = ValServer(valModules, {
14298
14329
  formatter,
14299
14330
  commitPrepared,
14300
14331
  publishOverride,
@@ -14306,6 +14337,13 @@ publishOverride) {
14306
14337
  } : {}),
14307
14338
  ...valServerConfig
14308
14339
  }, callbacks, nodePlatform);
14340
+ // fs mode has no sign-in, so which requests it answers is decided here.
14341
+ setRequestGuard(server, {
14342
+ mode: valServerConfig.mode,
14343
+ production: process.env.NODE_ENV === "production",
14344
+ allowedHosts: parseAllowedHosts(process.env.VAL_ALLOWED_HOSTS)
14345
+ });
14346
+ return server;
14309
14347
  }
14310
14348
 
14311
14349
  /**