@valbuild/server 0.153.4 → 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.
- package/CHANGELOG.md +28 -0
- package/browser/dist/valbuild-server-browser.cjs.dev.js +2 -2
- package/browser/dist/valbuild-server-browser.cjs.prod.js +2 -2
- package/browser/dist/valbuild-server-browser.esm.js +2 -2
- package/dist/{ValRouter-f63359b5.cjs.dev.js → ValRouter-480ecf99.cjs.dev.js} +42 -4
- package/dist/{ValRouter-4762254d.cjs.prod.js → ValRouter-b12133a1.cjs.prod.js} +42 -4
- package/dist/{ValRouter-93f23c96.esm.js → ValRouter-f4f5348d.esm.js} +42 -4
- package/dist/{ValRouterCore-ec886ca8.cjs.prod.js → ValRouterCore-3d7d2581.cjs.prod.js} +272 -14
- package/dist/{ValRouterCore-5cda39cb.esm.js → ValRouterCore-c418ffb7.esm.js} +267 -15
- package/dist/{ValRouterCore-83280de8.cjs.dev.js → ValRouterCore-cbf1de67.cjs.dev.js} +272 -14
- package/dist/{inTabFetch-3d69484d.cjs.prod.js → inTabFetch-5ef58dda.cjs.prod.js} +1 -1
- package/dist/{inTabFetch-240179b3.cjs.dev.js → inTabFetch-99450193.cjs.dev.js} +1 -1
- package/dist/{inTabFetch-686fe078.esm.js → inTabFetch-cb415a9d.esm.js} +1 -1
- package/dist/{publishKit-e52bf964.cjs.prod.js → publishKit-482747e2.cjs.prod.js} +2 -2
- package/dist/{publishKit-88b48b36.esm.js → publishKit-c2bcff27.esm.js} +3 -3
- package/dist/{publishKit-4d0f2af1.cjs.dev.js → publishKit-f98d8cd1.cjs.dev.js} +2 -2
- package/dist/valbuild-server.cjs.dev.js +2 -2
- package/dist/valbuild-server.cjs.prod.js +2 -2
- package/dist/valbuild-server.esm.js +4 -4
- package/internal/browser/dist/valbuild-server-internal-browser.cjs.dev.js +2 -2
- package/internal/browser/dist/valbuild-server-internal-browser.cjs.prod.js +2 -2
- package/internal/browser/dist/valbuild-server-internal-browser.esm.js +2 -2
- package/internal/dist/valbuild-server-internal.cjs.dev.js +2 -2
- package/internal/dist/valbuild-server-internal.cjs.prod.js +2 -2
- package/internal/dist/valbuild-server-internal.esm.js +2 -2
- package/package.json +6 -6
|
@@ -755,6 +755,66 @@ function parseRangeHeader(header, size) {
|
|
|
755
755
|
};
|
|
756
756
|
}
|
|
757
757
|
|
|
758
|
+
/**
|
|
759
|
+
* Which paths a request may name, where the path ends up joined onto a
|
|
760
|
+
* directory on disk or handed to the content service as a file to read.
|
|
761
|
+
*
|
|
762
|
+
* A media file's path arrives from the client three ways: in the URL of
|
|
763
|
+
* `/files`, in the body of `/upload/patches`, and as the `filePath` of a
|
|
764
|
+
* patch's `file` op. None of them was checked. `/files` answered any path
|
|
765
|
+
* under the project root (`.env`, the source), and an upload's `filePath` was
|
|
766
|
+
* joined onto the staging directory as it was, so `../../../../src/x` wrote
|
|
767
|
+
* outside it. In fs mode there is no session to stop either.
|
|
768
|
+
*
|
|
769
|
+
* So the rule is on the PATH, and it is the one media already follows: a local
|
|
770
|
+
* file lives under `/public` (`MediaDir` in core), and a remote one is named by
|
|
771
|
+
* its ref, which is a URL and never starts with a slash.
|
|
772
|
+
*/
|
|
773
|
+
|
|
774
|
+
/** No segment that climbs or stays put, and nothing a path API reads as a separator. */
|
|
775
|
+
function hasOnlyPlainSegments(filePath) {
|
|
776
|
+
if (filePath.includes("\\") || filePath.includes("\0")) {
|
|
777
|
+
return false;
|
|
778
|
+
}
|
|
779
|
+
return filePath.split("/").every(segment => segment !== ".." && segment !== ".");
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
/**
|
|
783
|
+
* A local media path: `/public/...`, with nothing in it that leaves `/public`.
|
|
784
|
+
*
|
|
785
|
+
* What `/files` serves when it is asked for a published file, and where a
|
|
786
|
+
* publish may write an uploaded one.
|
|
787
|
+
*/
|
|
788
|
+
function isPublicFilePath(filePath) {
|
|
789
|
+
return filePath.startsWith("/public/") && hasOnlyPlainSegments(filePath);
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
/**
|
|
793
|
+
* What a `file` op or an upload may name: a local media path, or a remote ref.
|
|
794
|
+
*
|
|
795
|
+
* A remote ref is stored in the patch directory under its own text, so it is
|
|
796
|
+
* held to the same segments rule. It cannot start with a slash, which is what
|
|
797
|
+
* keeps `/etc/x` and `/src/x` from passing as one.
|
|
798
|
+
*/
|
|
799
|
+
function isMediaFilePath(filePath) {
|
|
800
|
+
if (filePath.startsWith("/")) {
|
|
801
|
+
return isPublicFilePath(filePath);
|
|
802
|
+
}
|
|
803
|
+
return filePath.length > 0 && hasOnlyPlainSegments(filePath);
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
/**
|
|
807
|
+
* A patch id as a directory name: one segment, and not a climbing one.
|
|
808
|
+
*
|
|
809
|
+
* Patch ids are UUIDs here and whatever the content service mints there, so
|
|
810
|
+
* this does not say what an id IS, only what it cannot be while it is used as
|
|
811
|
+
* the name of a directory under `.val/patches`.
|
|
812
|
+
*/
|
|
813
|
+
function isSafePatchId(patchId) {
|
|
814
|
+
return patchId.length > 0 && patchId !== "." && patchId !== ".." && !/[/\\\0]/.test(patchId);
|
|
815
|
+
}
|
|
816
|
+
const MEDIA_FILE_PATH_ACCEPTS = "A file's path must be under /public (/public/val/photo.jpg) or be a remote file's ref, with no '..' in it.";
|
|
817
|
+
|
|
758
818
|
/**
|
|
759
819
|
* The little of HLS (RFC 8216) the server has to read: the variants of a
|
|
760
820
|
* master playlist, the segment durations of a media playlist, and every URI a
|
|
@@ -5203,6 +5263,27 @@ class ValOps {
|
|
|
5203
5263
|
|
|
5204
5264
|
// #region createPatch
|
|
5205
5265
|
async createPatch(path, patch, patchId, parentRef, sessionId, authorId) {
|
|
5266
|
+
// The id names a directory and each `file` op names a file in it, and
|
|
5267
|
+
// later a file a publish writes. Checked here, the one door every patch
|
|
5268
|
+
// comes through (the Studio, MCP), rather than at each of them.
|
|
5269
|
+
if (!isSafePatchId(patchId)) {
|
|
5270
|
+
return result.err({
|
|
5271
|
+
errorType: "other",
|
|
5272
|
+
error: {
|
|
5273
|
+
message: "This change's id is not a valid patch id."
|
|
5274
|
+
}
|
|
5275
|
+
});
|
|
5276
|
+
}
|
|
5277
|
+
for (const op of patch) {
|
|
5278
|
+
if (op.op === "file" && !isMediaFilePath(op.filePath)) {
|
|
5279
|
+
return result.err({
|
|
5280
|
+
errorType: "other",
|
|
5281
|
+
error: {
|
|
5282
|
+
message: `This change names a file at '${op.filePath}', which is not somewhere Val stores files. ${MEDIA_FILE_PATH_ACCEPTS}`
|
|
5283
|
+
}
|
|
5284
|
+
});
|
|
5285
|
+
}
|
|
5286
|
+
}
|
|
5206
5287
|
const saveRes = await this.saveSourceFilePatch(path, patch, patchId, parentRef, authorId, sessionId);
|
|
5207
5288
|
if (result.isErr(saveRes)) {
|
|
5208
5289
|
if (saveRes.error.errorType === "plan-refused") {
|
|
@@ -6295,7 +6376,7 @@ var packageJson = {
|
|
|
6295
6376
|
],
|
|
6296
6377
|
exports: true
|
|
6297
6378
|
},
|
|
6298
|
-
version: "0.153.
|
|
6379
|
+
version: "0.153.6",
|
|
6299
6380
|
scripts: {
|
|
6300
6381
|
typecheck: "tsc --noEmit",
|
|
6301
6382
|
test: "jest",
|
|
@@ -6311,11 +6392,11 @@ var packageJson = {
|
|
|
6311
6392
|
"@valbuild/shared": "workspace:*",
|
|
6312
6393
|
"@valbuild/ui": "workspace:*",
|
|
6313
6394
|
chokidar: "^5.0.0",
|
|
6314
|
-
"image-size": "^2.0.
|
|
6395
|
+
"image-size": "^2.0.3",
|
|
6315
6396
|
minimatch: "^10.2.6",
|
|
6316
6397
|
sucrase: "^3.35.1",
|
|
6317
6398
|
typescript: "^6.0.3",
|
|
6318
|
-
zod: "^4.
|
|
6399
|
+
zod: "^4.6.6",
|
|
6319
6400
|
"zod-validation-error": "^5.0.0"
|
|
6320
6401
|
},
|
|
6321
6402
|
engines: {
|
|
@@ -7239,7 +7320,8 @@ const ValServer = (valModules, options, callbacks, platform) => {
|
|
|
7239
7320
|
const token = crypto.randomUUID();
|
|
7240
7321
|
const redirectUrl = new URL(redirectTo);
|
|
7241
7322
|
const appAuthorizeUrl = getAuthorizeUrl(`${redirectUrl.origin}${options.route}`, token);
|
|
7242
|
-
|
|
7323
|
+
// Draft mode is NOT turned on here: nobody has signed in yet, and this
|
|
7324
|
+
// is reachable by anyone. `/callback` turns it on, once they have.
|
|
7243
7325
|
return {
|
|
7244
7326
|
cookies: {
|
|
7245
7327
|
[VAL_ENABLE_COOKIE_NAME]: ENABLE_COOKIE_VALUE,
|
|
@@ -8416,6 +8498,9 @@ const ValServer = (valModules, options, callbacks, platform) => {
|
|
|
8416
8498
|
...data,
|
|
8417
8499
|
exp // this is the client side exp
|
|
8418
8500
|
}, valSecret);
|
|
8501
|
+
// Signed in: now draft mode, which `/authorize` used to turn on for
|
|
8502
|
+
// whoever asked.
|
|
8503
|
+
await callbacks.onEnable(true);
|
|
8419
8504
|
return {
|
|
8420
8505
|
status: 302,
|
|
8421
8506
|
cookies: {
|
|
@@ -8947,7 +9032,7 @@ const ValServer = (valModules, options, callbacks, platform) => {
|
|
|
8947
9032
|
}
|
|
8948
9033
|
const pathParts = req.path.split("/");
|
|
8949
9034
|
const patchId = pathParts[1];
|
|
8950
|
-
const isValidPatchId = patchId.length === 36;
|
|
9035
|
+
const isValidPatchId = patchId.length === 36 && isSafePatchId(patchId);
|
|
8951
9036
|
const isValidEndpoint = pathParts[0] === "" && isValidPatchId && pathParts[2] === "files";
|
|
8952
9037
|
if (!isValidEndpoint) {
|
|
8953
9038
|
return {
|
|
@@ -10230,11 +10315,19 @@ const ValServer = (valModules, options, callbacks, platform) => {
|
|
|
10230
10315
|
contextWindow: typeof model.contextWindow === "number" ? model.contextWindow : null
|
|
10231
10316
|
}];
|
|
10232
10317
|
}) : undefined;
|
|
10318
|
+
// The model a chat starts on until the editor picks one. The
|
|
10319
|
+
// content server decides it, so it can change for every project
|
|
10320
|
+
// without a Val upgrade; this only carries it, shape-checked.
|
|
10321
|
+
const defaultModel = typeof json.defaultModel === "object" && json.defaultModel !== null && "provider" in json.defaultModel && "model" in json.defaultModel && typeof json.defaultModel.provider === "string" && typeof json.defaultModel.model === "string" ? {
|
|
10322
|
+
provider: json.defaultModel.provider,
|
|
10323
|
+
model: json.defaultModel.model
|
|
10324
|
+
} : null;
|
|
10233
10325
|
return {
|
|
10234
10326
|
status: 200,
|
|
10235
10327
|
json: {
|
|
10236
10328
|
nonce: json.nonce,
|
|
10237
10329
|
wsUrl,
|
|
10330
|
+
defaultModel,
|
|
10238
10331
|
// Explicit, because the distinction matters and truthiness
|
|
10239
10332
|
// is a bad way to express it: an empty array means "no
|
|
10240
10333
|
// reachable provider", which the client must be able to tell
|
|
@@ -11094,6 +11187,19 @@ const ValServer = (valModules, options, callbacks, platform) => {
|
|
|
11094
11187
|
// nothing fetches it backend-to-backend. Neither half of the argument
|
|
11095
11188
|
// above transfers. See architecture/media.md, "Why /files has no auth,
|
|
11096
11189
|
// and /history/files does".
|
|
11190
|
+
// Media and nothing else. This route has no auth (above), so what it
|
|
11191
|
+
// serves is decided by the path: a file under /public, which the site
|
|
11192
|
+
// serves anyway, or a draft of one. Without this it answered any path
|
|
11193
|
+
// in the project -- `.env`, the source -- and in http mode asked the
|
|
11194
|
+
// content service for it with the project's api key.
|
|
11195
|
+
if (!isPublicFilePath(filePath)) {
|
|
11196
|
+
return {
|
|
11197
|
+
status: 404,
|
|
11198
|
+
json: {
|
|
11199
|
+
message: "File not found"
|
|
11200
|
+
}
|
|
11201
|
+
};
|
|
11202
|
+
}
|
|
11097
11203
|
const remote = query.remote === "true";
|
|
11098
11204
|
const patchId = query.patch_id;
|
|
11099
11205
|
if (!patchId && isHttpOps(serverOps) && remote) {
|
|
@@ -12654,8 +12760,9 @@ class ValOpsMemory extends ValOps {
|
|
|
12654
12760
|
|
|
12655
12761
|
/**
|
|
12656
12762
|
* What `redirect_to` may be on Val's routes (`/enable`, `/disable`,
|
|
12657
|
-
* `/authorize`, `/draft/enable`, ...):
|
|
12658
|
-
*
|
|
12763
|
+
* `/authorize`, `/draft/enable`, ...): a path on the site that was asked,
|
|
12764
|
+
* which is made absolute against the request's own origin, or an absolute
|
|
12765
|
+
* URL on that same site.
|
|
12659
12766
|
*
|
|
12660
12767
|
* A path used to go through as it was, and two things downstream need an
|
|
12661
12768
|
* absolute URL: `/authorize` reads the origin off it to build the callback,
|
|
@@ -12668,8 +12775,13 @@ class ValOpsMemory extends ValOps {
|
|
|
12668
12775
|
* it always was (`/logout` reads it as absent).
|
|
12669
12776
|
*/
|
|
12670
12777
|
|
|
12671
|
-
const REDIRECT_TO_ACCEPTS = "redirect_to must be
|
|
12672
|
-
|
|
12778
|
+
const REDIRECT_TO_ACCEPTS = "redirect_to must be a path on this site starting with / (/page), or an absolute URL on this site (https://this-site.example/page).";
|
|
12779
|
+
|
|
12780
|
+
/**
|
|
12781
|
+
* `siteHosts` are the other names the request knows this site by (`Host`,
|
|
12782
|
+
* `X-Forwarded-Host`), for a server behind a proxy whose own URL is internal.
|
|
12783
|
+
*/
|
|
12784
|
+
function resolveRedirectTo(value, requestOrigin, siteHosts = []) {
|
|
12673
12785
|
if (value.startsWith("/") && !value.startsWith("//")) {
|
|
12674
12786
|
// A path stays on this origin. `/\host/x` also starts with one slash,
|
|
12675
12787
|
// and a URL parser reads the backslash as a second one: another host,
|
|
@@ -12683,13 +12795,22 @@ function resolveRedirectTo(value, requestOrigin) {
|
|
|
12683
12795
|
message: REDIRECT_TO_ACCEPTS
|
|
12684
12796
|
};
|
|
12685
12797
|
}
|
|
12686
|
-
|
|
12798
|
+
// An absolute URL, on this site only. Any URL used to pass, which made
|
|
12799
|
+
// `/logout` and `/enable` redirect wherever a link said, and `/authorize`
|
|
12800
|
+
// send the sign-in's code to that host: it reads the callback's origin off
|
|
12801
|
+
// this. http(s) only: `javascript:` parses as a URL too.
|
|
12802
|
+
const url = parsed(value);
|
|
12803
|
+
if (url === null || url.protocol !== "https:" && url.protocol !== "http:") {
|
|
12687
12804
|
return {
|
|
12688
|
-
ok:
|
|
12689
|
-
|
|
12805
|
+
ok: false,
|
|
12806
|
+
message: REDIRECT_TO_ACCEPTS
|
|
12690
12807
|
};
|
|
12691
12808
|
}
|
|
12692
|
-
|
|
12809
|
+
const hosts = [new URL(requestOrigin).host, ...siteHosts].filter(host => typeof host === "string" && host !== "").map(host => host.toLowerCase());
|
|
12810
|
+
return hosts.includes(url.host.toLowerCase()) ? {
|
|
12811
|
+
ok: true,
|
|
12812
|
+
href: value
|
|
12813
|
+
} : {
|
|
12693
12814
|
ok: false,
|
|
12694
12815
|
message: REDIRECT_TO_ACCEPTS
|
|
12695
12816
|
};
|
|
@@ -12707,6 +12828,130 @@ function parsed(value, base) {
|
|
|
12707
12828
|
}
|
|
12708
12829
|
}
|
|
12709
12830
|
|
|
12831
|
+
/**
|
|
12832
|
+
* Which requests Val's API answers in fs mode, where there is no session.
|
|
12833
|
+
*
|
|
12834
|
+
* fs mode reads and writes a working tree and asks nobody who they are: it is
|
|
12835
|
+
* a developer's own machine. That holds only while the request really comes
|
|
12836
|
+
* from that developer's Studio, and three kinds do not:
|
|
12837
|
+
*
|
|
12838
|
+
* - **A deployed site.** fs is the mode an app falls into when it has no
|
|
12839
|
+
* `VAL_API_KEY` and `VAL_SECRET`, so a site deployed without them served
|
|
12840
|
+
* this API, unauthenticated, to the internet.
|
|
12841
|
+
* - **Another site's page**, in the developer's browser. A `text/plain` POST
|
|
12842
|
+
* needs no preflight, and the router reads its body as JSON, so any page
|
|
12843
|
+
* open in another tab could write to the working tree.
|
|
12844
|
+
* - **A name that resolves to 127.0.0.1** (DNS rebinding), which makes such a
|
|
12845
|
+
* page same-origin with the dev server as far as the browser can tell.
|
|
12846
|
+
*
|
|
12847
|
+
* The MCP endpoint has refused all three since it was written
|
|
12848
|
+
* (`refuseUnsafeRequest` in `@valbuild/mcp`); this is the same rule for the
|
|
12849
|
+
* API the Studio uses. Nothing here needs Node: `ValRouterCore` runs in a
|
|
12850
|
+
* browser tab too, where no server is registered and nothing is refused.
|
|
12851
|
+
*/
|
|
12852
|
+
|
|
12853
|
+
const guards = new WeakMap();
|
|
12854
|
+
|
|
12855
|
+
/** Say how `server`'s requests are to be checked. Without it, none are. */
|
|
12856
|
+
function setRequestGuard(server, guard) {
|
|
12857
|
+
guards.set(server, guard);
|
|
12858
|
+
}
|
|
12859
|
+
|
|
12860
|
+
/** `VAL_ALLOWED_HOSTS`: comma separated host names, without a port. */
|
|
12861
|
+
function parseAllowedHosts(value) {
|
|
12862
|
+
return (value ?? "").split(",").map(host => host.trim().toLowerCase()).filter(host => host !== "");
|
|
12863
|
+
}
|
|
12864
|
+
|
|
12865
|
+
/** The refusal, or `null` when the request may go on to its route. */
|
|
12866
|
+
function refuseUnsafeRequest(server, req, apiPath) {
|
|
12867
|
+
var _req$method;
|
|
12868
|
+
const guard = guards.get(server);
|
|
12869
|
+
if (guard === undefined || guard.mode !== "fs") {
|
|
12870
|
+
return null;
|
|
12871
|
+
}
|
|
12872
|
+
// Beacons are not refused: in fs mode one is checked and dropped, nothing
|
|
12873
|
+
// is written or forwarded, and a deployed site with analytics on would fill
|
|
12874
|
+
// every visitor's console with errors.
|
|
12875
|
+
if (apiPath === "/analytics") {
|
|
12876
|
+
return null;
|
|
12877
|
+
}
|
|
12878
|
+
if (guard.production) {
|
|
12879
|
+
return refusal("Val is not set up for a deployed site here: without VAL_API_KEY and VAL_SECRET it runs in local filesystem mode, which has no sign-in and is only served by a development server. Set both (and VAL_PROJECT) on this deployment to use Val on it.");
|
|
12880
|
+
}
|
|
12881
|
+
const host = hostOf(req);
|
|
12882
|
+
const forwardedHost = firstOf(req.headers.get("x-forwarded-host"));
|
|
12883
|
+
const origin = req.headers.get("origin");
|
|
12884
|
+
if (origin !== null) {
|
|
12885
|
+
// `null` is the opaque origin (a sandboxed frame, a `file:` page). It
|
|
12886
|
+
// cannot be compared with anything, so it is refused.
|
|
12887
|
+
const originHost = origin === "null" ? null : hostOfUrl(origin);
|
|
12888
|
+
if (originHost === null || originHost !== host && originHost !== forwardedHost) {
|
|
12889
|
+
return refusal(`Val refused a request from another site (${origin}). In local filesystem mode the API only answers the Studio on its own address.`);
|
|
12890
|
+
}
|
|
12891
|
+
}
|
|
12892
|
+
// A request with no `Origin` can still come from another site: an `<img>`,
|
|
12893
|
+
// a script. Following a link here is not refused: sign-in comes back as
|
|
12894
|
+
// one. A link is a GET; a form posted from another site navigates too.
|
|
12895
|
+
const followedLink = ((_req$method = req.method) === null || _req$method === void 0 ? void 0 : _req$method.toUpperCase()) === "GET" && req.headers.get("sec-fetch-mode") === "navigate";
|
|
12896
|
+
if (req.headers.get("sec-fetch-site") === "cross-site" && !followedLink) {
|
|
12897
|
+
return refusal("Val refused a request from another site. In local filesystem mode the API only answers the Studio on its own address.");
|
|
12898
|
+
}
|
|
12899
|
+
const hostname = host === null ? null : hostnameOf(host);
|
|
12900
|
+
if (hostname === null || !isLocalName(hostname, guard.allowedHosts)) {
|
|
12901
|
+
return refusal(`Val refused a request addressed to ${host ?? "an unknown host"}. In local filesystem mode the API answers on localhost and on IP addresses, because any other name can be made to point at this machine by the site that owns it. If this is the address you develop on, add its host name to the VAL_ALLOWED_HOSTS environment variable (comma separated) and restart the dev server.`);
|
|
12902
|
+
}
|
|
12903
|
+
return null;
|
|
12904
|
+
}
|
|
12905
|
+
function refusal(message) {
|
|
12906
|
+
return {
|
|
12907
|
+
status: 403,
|
|
12908
|
+
json: {
|
|
12909
|
+
message
|
|
12910
|
+
}
|
|
12911
|
+
};
|
|
12912
|
+
}
|
|
12913
|
+
function firstOf(header) {
|
|
12914
|
+
var _header$split$;
|
|
12915
|
+
const first = header === null || header === void 0 || (_header$split$ = header.split(",")[0]) === null || _header$split$ === void 0 ? void 0 : _header$split$.trim().toLowerCase();
|
|
12916
|
+
return first ? first : null;
|
|
12917
|
+
}
|
|
12918
|
+
function hostOf(req) {
|
|
12919
|
+
const header = firstOf(req.headers.get("host"));
|
|
12920
|
+
if (header !== null) {
|
|
12921
|
+
return header;
|
|
12922
|
+
}
|
|
12923
|
+
// No Host header: the URL the framework built the request from.
|
|
12924
|
+
return hostOfUrl(req.url);
|
|
12925
|
+
}
|
|
12926
|
+
function hostOfUrl(url) {
|
|
12927
|
+
try {
|
|
12928
|
+
return new URL(url).host.toLowerCase();
|
|
12929
|
+
} catch {
|
|
12930
|
+
return null;
|
|
12931
|
+
}
|
|
12932
|
+
}
|
|
12933
|
+
|
|
12934
|
+
/** A host without its port. An IPv6 literal keeps its brackets. */
|
|
12935
|
+
function hostnameOf(host) {
|
|
12936
|
+
if (host.startsWith("[")) {
|
|
12937
|
+
const end = host.indexOf("]");
|
|
12938
|
+
return end === -1 ? host : host.slice(0, end + 1);
|
|
12939
|
+
}
|
|
12940
|
+
const colon = host.indexOf(":");
|
|
12941
|
+
return colon === -1 ? host : host.slice(0, colon);
|
|
12942
|
+
}
|
|
12943
|
+
|
|
12944
|
+
/**
|
|
12945
|
+
* localhost, an IP address, or a name the developer listed.
|
|
12946
|
+
*
|
|
12947
|
+
* An IP address is allowed because it cannot be rebound: a page that reaches
|
|
12948
|
+
* this server by address is on another origin, and the `Origin` check above
|
|
12949
|
+
* has already refused it. A phone on the same network uses one.
|
|
12950
|
+
*/
|
|
12951
|
+
function isLocalName(hostname, allowedHosts) {
|
|
12952
|
+
return hostname === "localhost" || hostname.endsWith(".localhost") || /^\d{1,3}(\.\d{1,3}){3}$/.test(hostname) || hostname.startsWith("[") && hostname.endsWith("]") || allowedHosts.includes(hostname);
|
|
12953
|
+
}
|
|
12954
|
+
|
|
12710
12955
|
/**
|
|
12711
12956
|
* Val's API as a web-standard handler: a `Request` in, a converted result out.
|
|
12712
12957
|
*
|
|
@@ -12790,6 +13035,10 @@ function createValRequestHandler(route, valServerPromise, convert, serveStatic)
|
|
|
12790
13035
|
Api;
|
|
12791
13036
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12792
13037
|
const anyValServer = valServer;
|
|
13038
|
+
const refused = refuseUnsafeRequest(valServer, req, reqApiRoutePath);
|
|
13039
|
+
if (refused !== null) {
|
|
13040
|
+
return refused;
|
|
13041
|
+
}
|
|
12793
13042
|
const method = (_req$method = req.method) === null || _req$method === void 0 ? void 0 : _req$method.toUpperCase();
|
|
12794
13043
|
let route = null;
|
|
12795
13044
|
let path = undefined;
|
|
@@ -12915,7 +13164,10 @@ function createValRequestHandler(route, valServerPromise, convert, serveStatic)
|
|
|
12915
13164
|
}
|
|
12916
13165
|
// `redirect_to` is a URL or a path on this site: see `resolveRedirectTo`.
|
|
12917
13166
|
if ("redirect_to" in query && typeof query.redirect_to === "string" && query.redirect_to !== "") {
|
|
12918
|
-
|
|
13167
|
+
var _req$headers$get;
|
|
13168
|
+
// Behind a proxy `url` can be an internal address: the site's own
|
|
13169
|
+
// name is then in `Host` or `X-Forwarded-Host`.
|
|
13170
|
+
const resolved = resolveRedirectTo(query.redirect_to, url.origin, [req.headers.get("host"), (_req$headers$get = req.headers.get("x-forwarded-host")) === null || _req$headers$get === void 0 || (_req$headers$get = _req$headers$get.split(",")[0]) === null || _req$headers$get === void 0 ? void 0 : _req$headers$get.trim()]);
|
|
12919
13171
|
if (!resolved.ok) {
|
|
12920
13172
|
return {
|
|
12921
13173
|
status: 400,
|
|
@@ -13108,4 +13360,4 @@ function getCookies(req, cookiesDef) {
|
|
|
13108
13360
|
return z.object(cookiesDef).safeParse(input);
|
|
13109
13361
|
}
|
|
13110
13362
|
|
|
13111
|
-
export {
|
|
13363
|
+
export { isHlsMasterPlaylist as A, sumHlsSegmentDurations as B, parseHlsMasterVariants as C, DEFAULT_ANALYTICS_INGEST_URL as D, largestHlsVariant as E, fallbackRefOf as F, mapHlsUris as G, movedRemoteHost as H, InMemoryPatchStore as I, needsHostCheck as J, rewriteRefHost as K, fallbackRemoteHost as L, MEDIA_FILE_PATH_ACCEPTS as M, checkRemoteFiles as N, ValServer as O, setRequestGuard as P, parseAllowedHosts as Q, createValRequestHandler as R, bytesToBase64 as S, ValHead as T, headWork as U, VAL_CLIENT_HEADERS as V, HEAD_BUDGET_BYTES as W, HEAD_VERSIONS_PER_MODULE as X, bytesToUtf8 as Y, posixPath as Z, formatPatchSourceError as a, askOncePerHost as b, getSettings as c, getFileExt as d, ValOpsMemory as e, findNestedJsonValuesRecords as f, getNewJsonEntryPaths as g, byUpdatedAt as h, isSketchpadId as i, applySketchpadChange as j, ValOps as k, isSafePatchId as l, matchesFilter as m, newSketchpad as n, isMediaFilePath as o, bufferFromDataUrl as p, getFieldsForType as q, resolveExistingJsonPath as r, summaryOf as s, isPublicFilePath as t, uploadRemoteFile as u, validateJsonValuesEntries as v, guessMimeTypeFromPath as w, createMetadataFromBuffer as x, sessionAuth as y, isHttpOps as z };
|