@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
|
@@ -761,6 +761,66 @@ function parseRangeHeader(header, size) {
|
|
|
761
761
|
};
|
|
762
762
|
}
|
|
763
763
|
|
|
764
|
+
/**
|
|
765
|
+
* Which paths a request may name, where the path ends up joined onto a
|
|
766
|
+
* directory on disk or handed to the content service as a file to read.
|
|
767
|
+
*
|
|
768
|
+
* A media file's path arrives from the client three ways: in the URL of
|
|
769
|
+
* `/files`, in the body of `/upload/patches`, and as the `filePath` of a
|
|
770
|
+
* patch's `file` op. None of them was checked. `/files` answered any path
|
|
771
|
+
* under the project root (`.env`, the source), and an upload's `filePath` was
|
|
772
|
+
* joined onto the staging directory as it was, so `../../../../src/x` wrote
|
|
773
|
+
* outside it. In fs mode there is no session to stop either.
|
|
774
|
+
*
|
|
775
|
+
* So the rule is on the PATH, and it is the one media already follows: a local
|
|
776
|
+
* file lives under `/public` (`MediaDir` in core), and a remote one is named by
|
|
777
|
+
* its ref, which is a URL and never starts with a slash.
|
|
778
|
+
*/
|
|
779
|
+
|
|
780
|
+
/** No segment that climbs or stays put, and nothing a path API reads as a separator. */
|
|
781
|
+
function hasOnlyPlainSegments(filePath) {
|
|
782
|
+
if (filePath.includes("\\") || filePath.includes("\0")) {
|
|
783
|
+
return false;
|
|
784
|
+
}
|
|
785
|
+
return filePath.split("/").every(segment => segment !== ".." && segment !== ".");
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
/**
|
|
789
|
+
* A local media path: `/public/...`, with nothing in it that leaves `/public`.
|
|
790
|
+
*
|
|
791
|
+
* What `/files` serves when it is asked for a published file, and where a
|
|
792
|
+
* publish may write an uploaded one.
|
|
793
|
+
*/
|
|
794
|
+
function isPublicFilePath(filePath) {
|
|
795
|
+
return filePath.startsWith("/public/") && hasOnlyPlainSegments(filePath);
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
/**
|
|
799
|
+
* What a `file` op or an upload may name: a local media path, or a remote ref.
|
|
800
|
+
*
|
|
801
|
+
* A remote ref is stored in the patch directory under its own text, so it is
|
|
802
|
+
* held to the same segments rule. It cannot start with a slash, which is what
|
|
803
|
+
* keeps `/etc/x` and `/src/x` from passing as one.
|
|
804
|
+
*/
|
|
805
|
+
function isMediaFilePath(filePath) {
|
|
806
|
+
if (filePath.startsWith("/")) {
|
|
807
|
+
return isPublicFilePath(filePath);
|
|
808
|
+
}
|
|
809
|
+
return filePath.length > 0 && hasOnlyPlainSegments(filePath);
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
/**
|
|
813
|
+
* A patch id as a directory name: one segment, and not a climbing one.
|
|
814
|
+
*
|
|
815
|
+
* Patch ids are UUIDs here and whatever the content service mints there, so
|
|
816
|
+
* this does not say what an id IS, only what it cannot be while it is used as
|
|
817
|
+
* the name of a directory under `.val/patches`.
|
|
818
|
+
*/
|
|
819
|
+
function isSafePatchId(patchId) {
|
|
820
|
+
return patchId.length > 0 && patchId !== "." && patchId !== ".." && !/[/\\\0]/.test(patchId);
|
|
821
|
+
}
|
|
822
|
+
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.";
|
|
823
|
+
|
|
764
824
|
/**
|
|
765
825
|
* The little of HLS (RFC 8216) the server has to read: the variants of a
|
|
766
826
|
* master playlist, the segment durations of a media playlist, and every URI a
|
|
@@ -5209,6 +5269,27 @@ class ValOps {
|
|
|
5209
5269
|
|
|
5210
5270
|
// #region createPatch
|
|
5211
5271
|
async createPatch(path, patch, patchId, parentRef, sessionId, authorId) {
|
|
5272
|
+
// The id names a directory and each `file` op names a file in it, and
|
|
5273
|
+
// later a file a publish writes. Checked here, the one door every patch
|
|
5274
|
+
// comes through (the Studio, MCP), rather than at each of them.
|
|
5275
|
+
if (!isSafePatchId(patchId)) {
|
|
5276
|
+
return fp.result.err({
|
|
5277
|
+
errorType: "other",
|
|
5278
|
+
error: {
|
|
5279
|
+
message: "This change's id is not a valid patch id."
|
|
5280
|
+
}
|
|
5281
|
+
});
|
|
5282
|
+
}
|
|
5283
|
+
for (const op of patch) {
|
|
5284
|
+
if (op.op === "file" && !isMediaFilePath(op.filePath)) {
|
|
5285
|
+
return fp.result.err({
|
|
5286
|
+
errorType: "other",
|
|
5287
|
+
error: {
|
|
5288
|
+
message: `This change names a file at '${op.filePath}', which is not somewhere Val stores files. ${MEDIA_FILE_PATH_ACCEPTS}`
|
|
5289
|
+
}
|
|
5290
|
+
});
|
|
5291
|
+
}
|
|
5292
|
+
}
|
|
5212
5293
|
const saveRes = await this.saveSourceFilePatch(path, patch, patchId, parentRef, authorId, sessionId);
|
|
5213
5294
|
if (fp.result.isErr(saveRes)) {
|
|
5214
5295
|
if (saveRes.error.errorType === "plan-refused") {
|
|
@@ -6301,7 +6382,7 @@ var packageJson = {
|
|
|
6301
6382
|
],
|
|
6302
6383
|
exports: true
|
|
6303
6384
|
},
|
|
6304
|
-
version: "0.153.
|
|
6385
|
+
version: "0.153.6",
|
|
6305
6386
|
scripts: {
|
|
6306
6387
|
typecheck: "tsc --noEmit",
|
|
6307
6388
|
test: "jest",
|
|
@@ -6317,11 +6398,11 @@ var packageJson = {
|
|
|
6317
6398
|
"@valbuild/shared": "workspace:*",
|
|
6318
6399
|
"@valbuild/ui": "workspace:*",
|
|
6319
6400
|
chokidar: "^5.0.0",
|
|
6320
|
-
"image-size": "^2.0.
|
|
6401
|
+
"image-size": "^2.0.3",
|
|
6321
6402
|
minimatch: "^10.2.6",
|
|
6322
6403
|
sucrase: "^3.35.1",
|
|
6323
6404
|
typescript: "^6.0.3",
|
|
6324
|
-
zod: "^4.
|
|
6405
|
+
zod: "^4.6.6",
|
|
6325
6406
|
"zod-validation-error": "^5.0.0"
|
|
6326
6407
|
},
|
|
6327
6408
|
engines: {
|
|
@@ -7245,7 +7326,8 @@ const ValServer = (valModules, options, callbacks, platform) => {
|
|
|
7245
7326
|
const token = crypto.randomUUID();
|
|
7246
7327
|
const redirectUrl = new URL(redirectTo);
|
|
7247
7328
|
const appAuthorizeUrl = getAuthorizeUrl(`${redirectUrl.origin}${options.route}`, token);
|
|
7248
|
-
|
|
7329
|
+
// Draft mode is NOT turned on here: nobody has signed in yet, and this
|
|
7330
|
+
// is reachable by anyone. `/callback` turns it on, once they have.
|
|
7249
7331
|
return {
|
|
7250
7332
|
cookies: {
|
|
7251
7333
|
[internal.VAL_ENABLE_COOKIE_NAME]: ENABLE_COOKIE_VALUE,
|
|
@@ -8422,6 +8504,9 @@ const ValServer = (valModules, options, callbacks, platform) => {
|
|
|
8422
8504
|
...data,
|
|
8423
8505
|
exp // this is the client side exp
|
|
8424
8506
|
}, valSecret);
|
|
8507
|
+
// Signed in: now draft mode, which `/authorize` used to turn on for
|
|
8508
|
+
// whoever asked.
|
|
8509
|
+
await callbacks.onEnable(true);
|
|
8425
8510
|
return {
|
|
8426
8511
|
status: 302,
|
|
8427
8512
|
cookies: {
|
|
@@ -8953,7 +9038,7 @@ const ValServer = (valModules, options, callbacks, platform) => {
|
|
|
8953
9038
|
}
|
|
8954
9039
|
const pathParts = req.path.split("/");
|
|
8955
9040
|
const patchId = pathParts[1];
|
|
8956
|
-
const isValidPatchId = patchId.length === 36;
|
|
9041
|
+
const isValidPatchId = patchId.length === 36 && isSafePatchId(patchId);
|
|
8957
9042
|
const isValidEndpoint = pathParts[0] === "" && isValidPatchId && pathParts[2] === "files";
|
|
8958
9043
|
if (!isValidEndpoint) {
|
|
8959
9044
|
return {
|
|
@@ -10236,11 +10321,19 @@ const ValServer = (valModules, options, callbacks, platform) => {
|
|
|
10236
10321
|
contextWindow: typeof model.contextWindow === "number" ? model.contextWindow : null
|
|
10237
10322
|
}];
|
|
10238
10323
|
}) : undefined;
|
|
10324
|
+
// The model a chat starts on until the editor picks one. The
|
|
10325
|
+
// content server decides it, so it can change for every project
|
|
10326
|
+
// without a Val upgrade; this only carries it, shape-checked.
|
|
10327
|
+
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" ? {
|
|
10328
|
+
provider: json.defaultModel.provider,
|
|
10329
|
+
model: json.defaultModel.model
|
|
10330
|
+
} : null;
|
|
10239
10331
|
return {
|
|
10240
10332
|
status: 200,
|
|
10241
10333
|
json: {
|
|
10242
10334
|
nonce: json.nonce,
|
|
10243
10335
|
wsUrl,
|
|
10336
|
+
defaultModel,
|
|
10244
10337
|
// Explicit, because the distinction matters and truthiness
|
|
10245
10338
|
// is a bad way to express it: an empty array means "no
|
|
10246
10339
|
// reachable provider", which the client must be able to tell
|
|
@@ -11100,6 +11193,19 @@ const ValServer = (valModules, options, callbacks, platform) => {
|
|
|
11100
11193
|
// nothing fetches it backend-to-backend. Neither half of the argument
|
|
11101
11194
|
// above transfers. See architecture/media.md, "Why /files has no auth,
|
|
11102
11195
|
// and /history/files does".
|
|
11196
|
+
// Media and nothing else. This route has no auth (above), so what it
|
|
11197
|
+
// serves is decided by the path: a file under /public, which the site
|
|
11198
|
+
// serves anyway, or a draft of one. Without this it answered any path
|
|
11199
|
+
// in the project -- `.env`, the source -- and in http mode asked the
|
|
11200
|
+
// content service for it with the project's api key.
|
|
11201
|
+
if (!isPublicFilePath(filePath)) {
|
|
11202
|
+
return {
|
|
11203
|
+
status: 404,
|
|
11204
|
+
json: {
|
|
11205
|
+
message: "File not found"
|
|
11206
|
+
}
|
|
11207
|
+
};
|
|
11208
|
+
}
|
|
11103
11209
|
const remote = query.remote === "true";
|
|
11104
11210
|
const patchId = query.patch_id;
|
|
11105
11211
|
if (!patchId && isHttpOps(serverOps) && remote) {
|
|
@@ -12660,8 +12766,9 @@ class ValOpsMemory extends ValOps {
|
|
|
12660
12766
|
|
|
12661
12767
|
/**
|
|
12662
12768
|
* What `redirect_to` may be on Val's routes (`/enable`, `/disable`,
|
|
12663
|
-
* `/authorize`, `/draft/enable`, ...):
|
|
12664
|
-
*
|
|
12769
|
+
* `/authorize`, `/draft/enable`, ...): a path on the site that was asked,
|
|
12770
|
+
* which is made absolute against the request's own origin, or an absolute
|
|
12771
|
+
* URL on that same site.
|
|
12665
12772
|
*
|
|
12666
12773
|
* A path used to go through as it was, and two things downstream need an
|
|
12667
12774
|
* absolute URL: `/authorize` reads the origin off it to build the callback,
|
|
@@ -12674,8 +12781,13 @@ class ValOpsMemory extends ValOps {
|
|
|
12674
12781
|
* it always was (`/logout` reads it as absent).
|
|
12675
12782
|
*/
|
|
12676
12783
|
|
|
12677
|
-
const REDIRECT_TO_ACCEPTS = "redirect_to must be
|
|
12678
|
-
|
|
12784
|
+
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).";
|
|
12785
|
+
|
|
12786
|
+
/**
|
|
12787
|
+
* `siteHosts` are the other names the request knows this site by (`Host`,
|
|
12788
|
+
* `X-Forwarded-Host`), for a server behind a proxy whose own URL is internal.
|
|
12789
|
+
*/
|
|
12790
|
+
function resolveRedirectTo(value, requestOrigin, siteHosts = []) {
|
|
12679
12791
|
if (value.startsWith("/") && !value.startsWith("//")) {
|
|
12680
12792
|
// A path stays on this origin. `/\host/x` also starts with one slash,
|
|
12681
12793
|
// and a URL parser reads the backslash as a second one: another host,
|
|
@@ -12689,13 +12801,22 @@ function resolveRedirectTo(value, requestOrigin) {
|
|
|
12689
12801
|
message: REDIRECT_TO_ACCEPTS
|
|
12690
12802
|
};
|
|
12691
12803
|
}
|
|
12692
|
-
|
|
12804
|
+
// An absolute URL, on this site only. Any URL used to pass, which made
|
|
12805
|
+
// `/logout` and `/enable` redirect wherever a link said, and `/authorize`
|
|
12806
|
+
// send the sign-in's code to that host: it reads the callback's origin off
|
|
12807
|
+
// this. http(s) only: `javascript:` parses as a URL too.
|
|
12808
|
+
const url = parsed(value);
|
|
12809
|
+
if (url === null || url.protocol !== "https:" && url.protocol !== "http:") {
|
|
12693
12810
|
return {
|
|
12694
|
-
ok:
|
|
12695
|
-
|
|
12811
|
+
ok: false,
|
|
12812
|
+
message: REDIRECT_TO_ACCEPTS
|
|
12696
12813
|
};
|
|
12697
12814
|
}
|
|
12698
|
-
|
|
12815
|
+
const hosts = [new URL(requestOrigin).host, ...siteHosts].filter(host => typeof host === "string" && host !== "").map(host => host.toLowerCase());
|
|
12816
|
+
return hosts.includes(url.host.toLowerCase()) ? {
|
|
12817
|
+
ok: true,
|
|
12818
|
+
href: value
|
|
12819
|
+
} : {
|
|
12699
12820
|
ok: false,
|
|
12700
12821
|
message: REDIRECT_TO_ACCEPTS
|
|
12701
12822
|
};
|
|
@@ -12713,6 +12834,130 @@ function parsed(value, base) {
|
|
|
12713
12834
|
}
|
|
12714
12835
|
}
|
|
12715
12836
|
|
|
12837
|
+
/**
|
|
12838
|
+
* Which requests Val's API answers in fs mode, where there is no session.
|
|
12839
|
+
*
|
|
12840
|
+
* fs mode reads and writes a working tree and asks nobody who they are: it is
|
|
12841
|
+
* a developer's own machine. That holds only while the request really comes
|
|
12842
|
+
* from that developer's Studio, and three kinds do not:
|
|
12843
|
+
*
|
|
12844
|
+
* - **A deployed site.** fs is the mode an app falls into when it has no
|
|
12845
|
+
* `VAL_API_KEY` and `VAL_SECRET`, so a site deployed without them served
|
|
12846
|
+
* this API, unauthenticated, to the internet.
|
|
12847
|
+
* - **Another site's page**, in the developer's browser. A `text/plain` POST
|
|
12848
|
+
* needs no preflight, and the router reads its body as JSON, so any page
|
|
12849
|
+
* open in another tab could write to the working tree.
|
|
12850
|
+
* - **A name that resolves to 127.0.0.1** (DNS rebinding), which makes such a
|
|
12851
|
+
* page same-origin with the dev server as far as the browser can tell.
|
|
12852
|
+
*
|
|
12853
|
+
* The MCP endpoint has refused all three since it was written
|
|
12854
|
+
* (`refuseUnsafeRequest` in `@valbuild/mcp`); this is the same rule for the
|
|
12855
|
+
* API the Studio uses. Nothing here needs Node: `ValRouterCore` runs in a
|
|
12856
|
+
* browser tab too, where no server is registered and nothing is refused.
|
|
12857
|
+
*/
|
|
12858
|
+
|
|
12859
|
+
const guards = new WeakMap();
|
|
12860
|
+
|
|
12861
|
+
/** Say how `server`'s requests are to be checked. Without it, none are. */
|
|
12862
|
+
function setRequestGuard(server, guard) {
|
|
12863
|
+
guards.set(server, guard);
|
|
12864
|
+
}
|
|
12865
|
+
|
|
12866
|
+
/** `VAL_ALLOWED_HOSTS`: comma separated host names, without a port. */
|
|
12867
|
+
function parseAllowedHosts(value) {
|
|
12868
|
+
return (value ?? "").split(",").map(host => host.trim().toLowerCase()).filter(host => host !== "");
|
|
12869
|
+
}
|
|
12870
|
+
|
|
12871
|
+
/** The refusal, or `null` when the request may go on to its route. */
|
|
12872
|
+
function refuseUnsafeRequest(server, req, apiPath) {
|
|
12873
|
+
var _req$method;
|
|
12874
|
+
const guard = guards.get(server);
|
|
12875
|
+
if (guard === undefined || guard.mode !== "fs") {
|
|
12876
|
+
return null;
|
|
12877
|
+
}
|
|
12878
|
+
// Beacons are not refused: in fs mode one is checked and dropped, nothing
|
|
12879
|
+
// is written or forwarded, and a deployed site with analytics on would fill
|
|
12880
|
+
// every visitor's console with errors.
|
|
12881
|
+
if (apiPath === "/analytics") {
|
|
12882
|
+
return null;
|
|
12883
|
+
}
|
|
12884
|
+
if (guard.production) {
|
|
12885
|
+
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.");
|
|
12886
|
+
}
|
|
12887
|
+
const host = hostOf(req);
|
|
12888
|
+
const forwardedHost = firstOf(req.headers.get("x-forwarded-host"));
|
|
12889
|
+
const origin = req.headers.get("origin");
|
|
12890
|
+
if (origin !== null) {
|
|
12891
|
+
// `null` is the opaque origin (a sandboxed frame, a `file:` page). It
|
|
12892
|
+
// cannot be compared with anything, so it is refused.
|
|
12893
|
+
const originHost = origin === "null" ? null : hostOfUrl(origin);
|
|
12894
|
+
if (originHost === null || originHost !== host && originHost !== forwardedHost) {
|
|
12895
|
+
return refusal(`Val refused a request from another site (${origin}). In local filesystem mode the API only answers the Studio on its own address.`);
|
|
12896
|
+
}
|
|
12897
|
+
}
|
|
12898
|
+
// A request with no `Origin` can still come from another site: an `<img>`,
|
|
12899
|
+
// a script. Following a link here is not refused: sign-in comes back as
|
|
12900
|
+
// one. A link is a GET; a form posted from another site navigates too.
|
|
12901
|
+
const followedLink = ((_req$method = req.method) === null || _req$method === void 0 ? void 0 : _req$method.toUpperCase()) === "GET" && req.headers.get("sec-fetch-mode") === "navigate";
|
|
12902
|
+
if (req.headers.get("sec-fetch-site") === "cross-site" && !followedLink) {
|
|
12903
|
+
return refusal("Val refused a request from another site. In local filesystem mode the API only answers the Studio on its own address.");
|
|
12904
|
+
}
|
|
12905
|
+
const hostname = host === null ? null : hostnameOf(host);
|
|
12906
|
+
if (hostname === null || !isLocalName(hostname, guard.allowedHosts)) {
|
|
12907
|
+
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.`);
|
|
12908
|
+
}
|
|
12909
|
+
return null;
|
|
12910
|
+
}
|
|
12911
|
+
function refusal(message) {
|
|
12912
|
+
return {
|
|
12913
|
+
status: 403,
|
|
12914
|
+
json: {
|
|
12915
|
+
message
|
|
12916
|
+
}
|
|
12917
|
+
};
|
|
12918
|
+
}
|
|
12919
|
+
function firstOf(header) {
|
|
12920
|
+
var _header$split$;
|
|
12921
|
+
const first = header === null || header === void 0 || (_header$split$ = header.split(",")[0]) === null || _header$split$ === void 0 ? void 0 : _header$split$.trim().toLowerCase();
|
|
12922
|
+
return first ? first : null;
|
|
12923
|
+
}
|
|
12924
|
+
function hostOf(req) {
|
|
12925
|
+
const header = firstOf(req.headers.get("host"));
|
|
12926
|
+
if (header !== null) {
|
|
12927
|
+
return header;
|
|
12928
|
+
}
|
|
12929
|
+
// No Host header: the URL the framework built the request from.
|
|
12930
|
+
return hostOfUrl(req.url);
|
|
12931
|
+
}
|
|
12932
|
+
function hostOfUrl(url) {
|
|
12933
|
+
try {
|
|
12934
|
+
return new URL(url).host.toLowerCase();
|
|
12935
|
+
} catch {
|
|
12936
|
+
return null;
|
|
12937
|
+
}
|
|
12938
|
+
}
|
|
12939
|
+
|
|
12940
|
+
/** A host without its port. An IPv6 literal keeps its brackets. */
|
|
12941
|
+
function hostnameOf(host) {
|
|
12942
|
+
if (host.startsWith("[")) {
|
|
12943
|
+
const end = host.indexOf("]");
|
|
12944
|
+
return end === -1 ? host : host.slice(0, end + 1);
|
|
12945
|
+
}
|
|
12946
|
+
const colon = host.indexOf(":");
|
|
12947
|
+
return colon === -1 ? host : host.slice(0, colon);
|
|
12948
|
+
}
|
|
12949
|
+
|
|
12950
|
+
/**
|
|
12951
|
+
* localhost, an IP address, or a name the developer listed.
|
|
12952
|
+
*
|
|
12953
|
+
* An IP address is allowed because it cannot be rebound: a page that reaches
|
|
12954
|
+
* this server by address is on another origin, and the `Origin` check above
|
|
12955
|
+
* has already refused it. A phone on the same network uses one.
|
|
12956
|
+
*/
|
|
12957
|
+
function isLocalName(hostname, allowedHosts) {
|
|
12958
|
+
return hostname === "localhost" || hostname.endsWith(".localhost") || /^\d{1,3}(\.\d{1,3}){3}$/.test(hostname) || hostname.startsWith("[") && hostname.endsWith("]") || allowedHosts.includes(hostname);
|
|
12959
|
+
}
|
|
12960
|
+
|
|
12716
12961
|
/**
|
|
12717
12962
|
* Val's API as a web-standard handler: a `Request` in, a converted result out.
|
|
12718
12963
|
*
|
|
@@ -12796,6 +13041,10 @@ function createValRequestHandler(route, valServerPromise, convert, serveStatic)
|
|
|
12796
13041
|
internal.Api;
|
|
12797
13042
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12798
13043
|
const anyValServer = valServer;
|
|
13044
|
+
const refused = refuseUnsafeRequest(valServer, req, reqApiRoutePath);
|
|
13045
|
+
if (refused !== null) {
|
|
13046
|
+
return refused;
|
|
13047
|
+
}
|
|
12799
13048
|
const method = (_req$method = req.method) === null || _req$method === void 0 ? void 0 : _req$method.toUpperCase();
|
|
12800
13049
|
let route = null;
|
|
12801
13050
|
let path = undefined;
|
|
@@ -12921,7 +13170,10 @@ function createValRequestHandler(route, valServerPromise, convert, serveStatic)
|
|
|
12921
13170
|
}
|
|
12922
13171
|
// `redirect_to` is a URL or a path on this site: see `resolveRedirectTo`.
|
|
12923
13172
|
if ("redirect_to" in query && typeof query.redirect_to === "string" && query.redirect_to !== "") {
|
|
12924
|
-
|
|
13173
|
+
var _req$headers$get;
|
|
13174
|
+
// Behind a proxy `url` can be an internal address: the site's own
|
|
13175
|
+
// name is then in `Host` or `X-Forwarded-Host`.
|
|
13176
|
+
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()]);
|
|
12925
13177
|
if (!resolved.ok) {
|
|
12926
13178
|
return {
|
|
12927
13179
|
status: 400,
|
|
@@ -13118,6 +13370,7 @@ exports.DEFAULT_ANALYTICS_INGEST_URL = DEFAULT_ANALYTICS_INGEST_URL;
|
|
|
13118
13370
|
exports.HEAD_BUDGET_BYTES = HEAD_BUDGET_BYTES;
|
|
13119
13371
|
exports.HEAD_VERSIONS_PER_MODULE = HEAD_VERSIONS_PER_MODULE;
|
|
13120
13372
|
exports.InMemoryPatchStore = InMemoryPatchStore;
|
|
13373
|
+
exports.MEDIA_FILE_PATH_ACCEPTS = MEDIA_FILE_PATH_ACCEPTS;
|
|
13121
13374
|
exports.VAL_CLIENT_HEADERS = VAL_CLIENT_HEADERS;
|
|
13122
13375
|
exports.ValHead = ValHead;
|
|
13123
13376
|
exports.ValOps = ValOps;
|
|
@@ -13144,6 +13397,9 @@ exports.guessMimeTypeFromPath = guessMimeTypeFromPath;
|
|
|
13144
13397
|
exports.headWork = headWork;
|
|
13145
13398
|
exports.isHlsMasterPlaylist = isHlsMasterPlaylist;
|
|
13146
13399
|
exports.isHttpOps = isHttpOps;
|
|
13400
|
+
exports.isMediaFilePath = isMediaFilePath;
|
|
13401
|
+
exports.isPublicFilePath = isPublicFilePath;
|
|
13402
|
+
exports.isSafePatchId = isSafePatchId;
|
|
13147
13403
|
exports.isSketchpadId = isSketchpadId;
|
|
13148
13404
|
exports.largestHlsVariant = largestHlsVariant;
|
|
13149
13405
|
exports.mapHlsUris = mapHlsUris;
|
|
@@ -13151,11 +13407,13 @@ exports.matchesFilter = matchesFilter;
|
|
|
13151
13407
|
exports.movedRemoteHost = movedRemoteHost;
|
|
13152
13408
|
exports.needsHostCheck = needsHostCheck;
|
|
13153
13409
|
exports.newSketchpad = newSketchpad;
|
|
13410
|
+
exports.parseAllowedHosts = parseAllowedHosts;
|
|
13154
13411
|
exports.parseHlsMasterVariants = parseHlsMasterVariants;
|
|
13155
13412
|
exports.posixPath = posixPath;
|
|
13156
13413
|
exports.resolveExistingJsonPath = resolveExistingJsonPath;
|
|
13157
13414
|
exports.rewriteRefHost = rewriteRefHost;
|
|
13158
13415
|
exports.sessionAuth = sessionAuth;
|
|
13416
|
+
exports.setRequestGuard = setRequestGuard;
|
|
13159
13417
|
exports.sumHlsSegmentDurations = sumHlsSegmentDurations;
|
|
13160
13418
|
exports.summaryOf = summaryOf;
|
|
13161
13419
|
exports.uploadRemoteFile = uploadRemoteFile;
|