@solidjs/web 2.0.0-rc.15 → 2.0.0-rc.16
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/README.md +1 -1
- package/dist/server.dev.js +358 -479
- package/dist/server.js +343 -387
- package/dist/server.observe.js +343 -387
- package/dist/web.dev.js +57 -54
- package/dist/web.js +47 -49
- package/dist/web.observe.js +57 -54
- package/frames/dist/client.dev.js +610 -621
- package/frames/dist/client.js +540 -566
- package/frames/dist/client.observe.js +571 -573
- package/frames/dist/regions.js +43 -2
- package/frames/dist/server.dev.js +514 -423
- package/frames/dist/server.js +514 -370
- package/frames/dist/server.observe.js +514 -370
- package/frames/dist/wire.js +371 -6
- package/package.json +11 -11
- package/serialization/dist/decode.js +9 -7
- package/serialization/dist/serialization.js +9 -7
- package/serialization/types/serializer-decode.d.ts +2 -2
- package/server-functions/dist/client.dev.js +3 -1
- package/server-functions/dist/client.js +1 -1
- package/server-functions/dist/client.observe.js +3 -1
- package/server-functions/dist/rich-args.js +33 -1
- package/server-functions/dist/server.dev.js +127 -18
- package/server-functions/dist/server.js +127 -18
- package/server-functions/dist/server.observe.js +127 -18
- package/skills/server-components/SKILL.md +74 -185
- package/types/client.d.ts +15 -5
- package/types/frames/assets-tier.d.ts +2 -2
- package/types/frames/client.d.ts +8 -3
- package/types/frames/frame-client.d.ts +121 -157
- package/types/frames/frame-morph.d.ts +28 -0
- package/types/frames/frame-sink.d.ts +13 -9
- package/types/frames/frame-transport.d.ts +30 -1
- package/types/frames/regions-tier.d.ts +15 -0
- package/types/frames/serializer-decode.d.ts +2 -2
- package/types/frames/server.d.ts +0 -52
- package/types/frames/wire-tier.d.ts +54 -1
- package/types/index.d.ts +2 -2
- package/types/jsx.d.ts +11 -5
- package/types/observe.d.ts +14 -7
- package/types/render.d.ts +3 -1
- package/types/response.d.ts +5 -4
- package/types/serializer-decode.d.ts +2 -2
- package/types/server-functions/argument-codec.d.ts +21 -0
- package/types/server-functions/client.d.ts +14 -5
- package/types/server-functions/server.d.ts +6 -2
- package/types/server-functions/shared.d.ts +19 -0
- package/types/server-observe.d.ts +3 -2
- package/types/server.d.ts +57 -76
- package/frames/dist/bind.dev.js +0 -326
- package/frames/dist/bind.js +0 -295
- package/types/frames/bind-tier.d.ts +0 -60
|
@@ -56,11 +56,9 @@ function parseTraceparent(value) {
|
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
function randomHex(bytes) {
|
|
59
|
-
const buffer = new Uint8Array(bytes);
|
|
60
|
-
crypto.getRandomValues(buffer);
|
|
61
59
|
let out = "";
|
|
62
|
-
for (let i = 0; i <
|
|
63
|
-
return out;
|
|
60
|
+
for (let i = 0; i < bytes; i += 4) out += (Math.random() * 0x100000000 >>> 0).toString(16).padStart(8, "0");
|
|
61
|
+
return out.length === bytes * 2 ? out : out.slice(0, bytes * 2);
|
|
64
62
|
}
|
|
65
63
|
function randomTraceId() {
|
|
66
64
|
let id = randomHex(16);
|
|
@@ -853,6 +851,10 @@ function createEventChunk(data, id) {
|
|
|
853
851
|
return CHUNK_ENCODER.encode(event + "\n");
|
|
854
852
|
}
|
|
855
853
|
const EVENT_STREAM_HEARTBEAT = /* @__PURE__ */new TextEncoder().encode(":\n\n");
|
|
854
|
+
function isEventStream(source) {
|
|
855
|
+
const contentType = source.headers.get("content-type");
|
|
856
|
+
return !!contentType && contentType.startsWith("text/event-stream");
|
|
857
|
+
}
|
|
856
858
|
function positionDigest(value) {
|
|
857
859
|
if (value === undefined || !isJSONSafe(value)) return undefined;
|
|
858
860
|
const text = JSON.stringify(value);
|
|
@@ -915,7 +917,7 @@ async function deserializeStream(source, codecOptions, wire) {
|
|
|
915
917
|
if (!source.body) {
|
|
916
918
|
throw new Error("missing body");
|
|
917
919
|
}
|
|
918
|
-
const reader = new ChunkReader(source.body);
|
|
920
|
+
const reader = wire && isEventStream(source) ? wire.open(source.body) : new ChunkReader(source.body);
|
|
919
921
|
try {
|
|
920
922
|
const result = await reader.next();
|
|
921
923
|
if (!result.done) {
|
|
@@ -934,10 +936,18 @@ async function deserializeStream(source, codecOptions, wire) {
|
|
|
934
936
|
}
|
|
935
937
|
const connection = wire && wire.connection;
|
|
936
938
|
let endConnection;
|
|
937
|
-
if (connection) ;
|
|
939
|
+
if (connection) connection.ended = new Promise(resolve => endConnection = resolve);
|
|
938
940
|
const end = error => {
|
|
939
941
|
const sweep = () => deserializeChunk.abort(error);
|
|
940
|
-
if (connection)
|
|
942
|
+
if (connection) {
|
|
943
|
+
const close = () => deserializeChunk.close();
|
|
944
|
+
endConnection({
|
|
945
|
+
open: deserializeChunk.open(),
|
|
946
|
+
error,
|
|
947
|
+
sweep,
|
|
948
|
+
close
|
|
949
|
+
});
|
|
950
|
+
} else sweep();
|
|
941
951
|
};
|
|
942
952
|
reader.drain(interpretChunk).then(() => end(new Error("Server function stream ended unexpectedly.")), error => end(error));
|
|
943
953
|
return interpretChunk(result.value);
|
|
@@ -947,9 +957,6 @@ async function deserializeStream(source, codecOptions, wire) {
|
|
|
947
957
|
throw error;
|
|
948
958
|
}
|
|
949
959
|
}
|
|
950
|
-
async function deserializeString(text, codecOptions) {
|
|
951
|
-
return await deserializeStream(new Response(text), codecOptions);
|
|
952
|
-
}
|
|
953
960
|
async function decodeResponse(response, codecOptions) {
|
|
954
961
|
if (!response.body) return undefined;
|
|
955
962
|
return await extractBody(response.clone(), codecOptions === undefined ? codecConfig.codec : codecOptions);
|
|
@@ -1268,6 +1275,57 @@ async function decodeFlashCookie(cookieHeader) {
|
|
|
1268
1275
|
}
|
|
1269
1276
|
}
|
|
1270
1277
|
|
|
1278
|
+
const RESPONSE_TAG = "seroval-plugins/web/Response";
|
|
1279
|
+
const REQUEST_TAG = "seroval-plugins/web/Request";
|
|
1280
|
+
const REFUSED_TAGS = [RESPONSE_TAG, REQUEST_TAG];
|
|
1281
|
+
const RESOLVED_PLUGINS = Symbol.for("solid.codec.resolvedPlugins");
|
|
1282
|
+
const REFUSED_ARGUMENT = Symbol("solid.serverFunction.refusedArgument");
|
|
1283
|
+
function refusedArgumentError(name = "Response or Request") {
|
|
1284
|
+
const error = new TypeError(`Server function arguments cannot carry Response or Request values (got a ${name}). ` + "Pass the data it holds — its body, headers or url — instead.");
|
|
1285
|
+
error[REFUSED_ARGUMENT] = true;
|
|
1286
|
+
return error;
|
|
1287
|
+
}
|
|
1288
|
+
function refusedArgument(error) {
|
|
1289
|
+
for (let depth = 0; depth < 4 && error !== null && typeof error === "object"; depth++) {
|
|
1290
|
+
if (error[REFUSED_ARGUMENT] === true) return error;
|
|
1291
|
+
error = error.cause;
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
const refused = plugin => REFUSED_TAGS.includes(plugin.tag);
|
|
1295
|
+
const reachesRefused = plugin => refused(plugin) || !!plugin.extends && plugin.extends.some(reachesRefused);
|
|
1296
|
+
function filterPlugins(plugins, out, seen) {
|
|
1297
|
+
for (const plugin of plugins) {
|
|
1298
|
+
if (seen.has(plugin)) continue;
|
|
1299
|
+
seen.add(plugin);
|
|
1300
|
+
if (refused(plugin)) continue;
|
|
1301
|
+
const severs = !!plugin.extends && plugin.extends.some(reachesRefused);
|
|
1302
|
+
out.push(severs ? {
|
|
1303
|
+
...plugin,
|
|
1304
|
+
extends: undefined
|
|
1305
|
+
} : plugin);
|
|
1306
|
+
if (plugin.extends) filterPlugins(plugin.extends, out, seen);
|
|
1307
|
+
}
|
|
1308
|
+
return out;
|
|
1309
|
+
}
|
|
1310
|
+
let defaultArgumentPlugins;
|
|
1311
|
+
const customArgumentPlugins = new WeakMap();
|
|
1312
|
+
function argumentDecodeCodec(codec, defaults) {
|
|
1313
|
+
const custom = codec && codec.plugins;
|
|
1314
|
+
let plugins = custom ? customArgumentPlugins.get(custom) : defaultArgumentPlugins;
|
|
1315
|
+
if (!plugins) {
|
|
1316
|
+
plugins = filterPlugins(custom ? [...custom, ...defaults] : defaults, [], new Set());
|
|
1317
|
+
if (custom) customArgumentPlugins.set(custom, plugins);else defaultArgumentPlugins = plugins;
|
|
1318
|
+
}
|
|
1319
|
+
return {
|
|
1320
|
+
...codec,
|
|
1321
|
+
[RESOLVED_PLUGINS]: plugins
|
|
1322
|
+
};
|
|
1323
|
+
}
|
|
1324
|
+
function namesRefusedType(payload) {
|
|
1325
|
+
for (const tag of REFUSED_TAGS) if (payload.includes(`"c":"${tag}"`)) return true;
|
|
1326
|
+
return false;
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1271
1329
|
const config = {
|
|
1272
1330
|
provideEvent: undefined,
|
|
1273
1331
|
wrapInvocation: undefined,
|
|
@@ -1833,14 +1891,49 @@ function unknownFormatError(tag) {
|
|
|
1833
1891
|
error[FORMAT_SKEW] = true;
|
|
1834
1892
|
return error;
|
|
1835
1893
|
}
|
|
1836
|
-
async function
|
|
1894
|
+
async function decodeArguments(decode, payload) {
|
|
1895
|
+
if (payload === null) return await decode(undefined);
|
|
1896
|
+
const refuseNamed = () => {
|
|
1897
|
+
const text = typeof payload === "string" ? payload : new TextDecoder().decode(payload);
|
|
1898
|
+
if (namesRefusedType(text)) throw refusedArgumentError();
|
|
1899
|
+
};
|
|
1900
|
+
const connection = {};
|
|
1901
|
+
let value;
|
|
1902
|
+
try {
|
|
1903
|
+
value = await decode({
|
|
1904
|
+
connection
|
|
1905
|
+
});
|
|
1906
|
+
} catch (error) {
|
|
1907
|
+
if (connection.ended) connection.ended.then(end => end.sweep());
|
|
1908
|
+
refuseNamed();
|
|
1909
|
+
throw error;
|
|
1910
|
+
}
|
|
1911
|
+
if (connection.ended) {
|
|
1912
|
+
const {
|
|
1913
|
+
open,
|
|
1914
|
+
sweep
|
|
1915
|
+
} = await connection.ended;
|
|
1916
|
+
sweep();
|
|
1917
|
+
if (open) refuseNamed();
|
|
1918
|
+
}
|
|
1919
|
+
return value;
|
|
1920
|
+
}
|
|
1921
|
+
let decodeModule;
|
|
1922
|
+
async function loadArgumentCodec(codec) {
|
|
1923
|
+
decodeModule = await import('@solidjs/web/serialization/decode');
|
|
1924
|
+
return argumentDecodeCodec(codec, decodeModule.DEFAULT_WEB_PLUGINS);
|
|
1925
|
+
}
|
|
1926
|
+
const argumentCodecFor = codec => decodeModule ? argumentDecodeCodec(codec, decodeModule.DEFAULT_WEB_PLUGINS) : loadArgumentCodec(codec);
|
|
1927
|
+
async function parseArguments(request, url, scripted, codec, buffered) {
|
|
1837
1928
|
const parsed = [];
|
|
1838
1929
|
const bodyFormat = request.method === "POST" ? request.headers.get(BODY_FORMAT_HEADER) : null;
|
|
1839
1930
|
const args = url.searchParams.get("args");
|
|
1840
1931
|
if (args && (!scripted || request.method === "GET" || bodyFormat !== BodyFormat.Serialized)) {
|
|
1841
1932
|
let result;
|
|
1842
1933
|
if (args.startsWith(";0x")) {
|
|
1843
|
-
|
|
1934
|
+
let argumentCodec = argumentCodecFor(codec);
|
|
1935
|
+
if (argumentCodec instanceof Promise) argumentCodec = await argumentCodec;
|
|
1936
|
+
result = await decodeArguments(wire => deserializeStream(new Response(args), argumentCodec, wire), args);
|
|
1844
1937
|
} else {
|
|
1845
1938
|
result = JSON.parse(args);
|
|
1846
1939
|
assertDecodeDepth(result);
|
|
@@ -1860,7 +1953,14 @@ async function parseArguments(request, url, scripted, codec) {
|
|
|
1860
1953
|
throw unknownFormatError(bodyFormat);
|
|
1861
1954
|
}
|
|
1862
1955
|
const body = request.clone();
|
|
1863
|
-
|
|
1956
|
+
let decoded;
|
|
1957
|
+
if (bodyFormat === BodyFormat.Serialized) {
|
|
1958
|
+
let argumentCodec = argumentCodecFor(codec);
|
|
1959
|
+
if (argumentCodec instanceof Promise) argumentCodec = await argumentCodec;
|
|
1960
|
+
decoded = await decodeArguments(wire => extractBody(body, argumentCodec, wire), buffered);
|
|
1961
|
+
} else {
|
|
1962
|
+
decoded = await extractBody(body, codec);
|
|
1963
|
+
}
|
|
1864
1964
|
if (bodyFormat === BodyFormat.Serialized || bodyFormat === BodyFormat.Json) {
|
|
1865
1965
|
if (bodyFormat === BodyFormat.Json) assertDecodeDepth(decoded);
|
|
1866
1966
|
if (!Array.isArray(decoded)) {
|
|
@@ -2852,6 +2952,7 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
2852
2952
|
});
|
|
2853
2953
|
return finish(protectsRequest ? withCSRFVary(response) : response);
|
|
2854
2954
|
}
|
|
2955
|
+
let argumentBytes = null;
|
|
2855
2956
|
if (method === "POST" && request.body !== null && bodySizeLimit !== Infinity) {
|
|
2856
2957
|
const raw = request.headers.get("content-length");
|
|
2857
2958
|
const declared = raw !== null && /^\d+$/.test(raw) ? Number(raw) : NaN;
|
|
@@ -2877,6 +2978,7 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
2877
2978
|
return finish(protectsRequest ? withCSRFVary(response) : response);
|
|
2878
2979
|
}
|
|
2879
2980
|
request = withBufferedBody(request, buffered);
|
|
2981
|
+
argumentBytes = buffered;
|
|
2880
2982
|
}
|
|
2881
2983
|
let event;
|
|
2882
2984
|
try {
|
|
@@ -2933,10 +3035,10 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
2933
3035
|
const collectsFlight = flightHooks.length > 0;
|
|
2934
3036
|
let parsed;
|
|
2935
3037
|
try {
|
|
2936
|
-
parsed = await parseArguments(request, url, scripted, codec);
|
|
3038
|
+
parsed = await parseArguments(request, url, scripted, codec, argumentBytes);
|
|
2937
3039
|
} catch (error) {
|
|
2938
|
-
const
|
|
2939
|
-
const response = new Response(DEV ?
|
|
3040
|
+
const named = error !== null && typeof error === "object" && error[FORMAT_SKEW] === true ? error : refusedArgument(error);
|
|
3041
|
+
const response = new Response(DEV ? named ? named.message : "Malformed server function arguments" : null, {
|
|
2940
3042
|
status: 400
|
|
2941
3043
|
});
|
|
2942
3044
|
return refuseCommitted(response);
|
|
@@ -2990,7 +3092,7 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
2990
3092
|
response,
|
|
2991
3093
|
value
|
|
2992
3094
|
} = result;
|
|
2993
|
-
if (!scripted && !handleNoJS && response && response.body) {
|
|
3095
|
+
if (!scripted && !handleNoJS && response && response.body && isJSONSafe(value)) {
|
|
2994
3096
|
return response;
|
|
2995
3097
|
}
|
|
2996
3098
|
if (response && response.headers) {
|
|
@@ -3179,11 +3281,15 @@ function ownResponse(response) {
|
|
|
3179
3281
|
function finalizeTransportResponse(response, method) {
|
|
3180
3282
|
const stripBody = method === "HEAD" && response.body !== null;
|
|
3181
3283
|
const defaultsCache = !response.headers.has("Cache-Control") && response.status !== 304;
|
|
3182
|
-
|
|
3284
|
+
const defaultsSniff = !response.headers.has("X-Content-Type-Options");
|
|
3285
|
+
if (stripBody || defaultsCache || defaultsSniff) {
|
|
3183
3286
|
try {
|
|
3184
3287
|
if (defaultsCache) {
|
|
3185
3288
|
response.headers.set("Cache-Control", "no-store");
|
|
3186
3289
|
}
|
|
3290
|
+
if (defaultsSniff) {
|
|
3291
|
+
response.headers.set("X-Content-Type-Options", "nosniff");
|
|
3292
|
+
}
|
|
3187
3293
|
if (!stripBody) return response;
|
|
3188
3294
|
response.body.cancel().catch(() => {});
|
|
3189
3295
|
return new Response(null, {
|
|
@@ -3194,6 +3300,9 @@ function finalizeTransportResponse(response, method) {
|
|
|
3194
3300
|
} catch {
|
|
3195
3301
|
const headers = new Headers(response.headers);
|
|
3196
3302
|
if (defaultsCache && !headers.has("Cache-Control")) headers.set("Cache-Control", "no-store");
|
|
3303
|
+
if (defaultsSniff && !headers.has("X-Content-Type-Options")) {
|
|
3304
|
+
headers.set("X-Content-Type-Options", "nosniff");
|
|
3305
|
+
}
|
|
3197
3306
|
if (stripBody) response.body.cancel().catch(() => {});
|
|
3198
3307
|
return new Response(stripBody ? null : response.body, {
|
|
3199
3308
|
status: response.status,
|
|
@@ -50,11 +50,9 @@ function parseTraceparent(value) {
|
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
52
|
function randomHex(bytes) {
|
|
53
|
-
const buffer = new Uint8Array(bytes);
|
|
54
|
-
crypto.getRandomValues(buffer);
|
|
55
53
|
let out = "";
|
|
56
|
-
for (let i = 0; i <
|
|
57
|
-
return out;
|
|
54
|
+
for (let i = 0; i < bytes; i += 4) out += (Math.random() * 0x100000000 >>> 0).toString(16).padStart(8, "0");
|
|
55
|
+
return out.length === bytes * 2 ? out : out.slice(0, bytes * 2);
|
|
58
56
|
}
|
|
59
57
|
function randomTraceId() {
|
|
60
58
|
let id = randomHex(16);
|
|
@@ -802,6 +800,10 @@ function createEventChunk(data, id) {
|
|
|
802
800
|
return CHUNK_ENCODER.encode(event + "\n");
|
|
803
801
|
}
|
|
804
802
|
const EVENT_STREAM_HEARTBEAT = /* @__PURE__ */new TextEncoder().encode(":\n\n");
|
|
803
|
+
function isEventStream(source) {
|
|
804
|
+
const contentType = source.headers.get("content-type");
|
|
805
|
+
return !!contentType && contentType.startsWith("text/event-stream");
|
|
806
|
+
}
|
|
805
807
|
function positionDigest(value) {
|
|
806
808
|
if (value === undefined || !isJSONSafe(value)) return undefined;
|
|
807
809
|
const text = JSON.stringify(value);
|
|
@@ -864,7 +866,7 @@ async function deserializeStream(source, codecOptions, wire) {
|
|
|
864
866
|
if (!source.body) {
|
|
865
867
|
throw new Error("missing body");
|
|
866
868
|
}
|
|
867
|
-
const reader = new ChunkReader(source.body);
|
|
869
|
+
const reader = wire && isEventStream(source) ? wire.open(source.body) : new ChunkReader(source.body);
|
|
868
870
|
try {
|
|
869
871
|
const result = await reader.next();
|
|
870
872
|
if (!result.done) {
|
|
@@ -883,10 +885,18 @@ async function deserializeStream(source, codecOptions, wire) {
|
|
|
883
885
|
}
|
|
884
886
|
const connection = wire && wire.connection;
|
|
885
887
|
let endConnection;
|
|
886
|
-
if (connection) ;
|
|
888
|
+
if (connection) connection.ended = new Promise(resolve => endConnection = resolve);
|
|
887
889
|
const end = error => {
|
|
888
890
|
const sweep = () => deserializeChunk.abort(error);
|
|
889
|
-
if (connection)
|
|
891
|
+
if (connection) {
|
|
892
|
+
const close = () => deserializeChunk.close();
|
|
893
|
+
endConnection({
|
|
894
|
+
open: deserializeChunk.open(),
|
|
895
|
+
error,
|
|
896
|
+
sweep,
|
|
897
|
+
close
|
|
898
|
+
});
|
|
899
|
+
} else sweep();
|
|
890
900
|
};
|
|
891
901
|
reader.drain(interpretChunk).then(() => end(new Error("Server function stream ended unexpectedly.")), error => end(error));
|
|
892
902
|
return interpretChunk(result.value);
|
|
@@ -896,9 +906,6 @@ async function deserializeStream(source, codecOptions, wire) {
|
|
|
896
906
|
throw error;
|
|
897
907
|
}
|
|
898
908
|
}
|
|
899
|
-
async function deserializeString(text, codecOptions) {
|
|
900
|
-
return await deserializeStream(new Response(text), codecOptions);
|
|
901
|
-
}
|
|
902
909
|
async function decodeResponse(response, codecOptions) {
|
|
903
910
|
if (!response.body) return undefined;
|
|
904
911
|
return await extractBody(response.clone(), codecOptions === undefined ? codecConfig.codec : codecOptions);
|
|
@@ -1186,6 +1193,57 @@ async function decodeFlashCookie(cookieHeader) {
|
|
|
1186
1193
|
}
|
|
1187
1194
|
}
|
|
1188
1195
|
|
|
1196
|
+
const RESPONSE_TAG = "seroval-plugins/web/Response";
|
|
1197
|
+
const REQUEST_TAG = "seroval-plugins/web/Request";
|
|
1198
|
+
const REFUSED_TAGS = [RESPONSE_TAG, REQUEST_TAG];
|
|
1199
|
+
const RESOLVED_PLUGINS = Symbol.for("solid.codec.resolvedPlugins");
|
|
1200
|
+
const REFUSED_ARGUMENT = Symbol("solid.serverFunction.refusedArgument");
|
|
1201
|
+
function refusedArgumentError(name = "Response or Request") {
|
|
1202
|
+
const error = new TypeError(`Server function arguments cannot carry Response or Request values (got a ${name}). ` + "Pass the data it holds — its body, headers or url — instead.");
|
|
1203
|
+
error[REFUSED_ARGUMENT] = true;
|
|
1204
|
+
return error;
|
|
1205
|
+
}
|
|
1206
|
+
function refusedArgument(error) {
|
|
1207
|
+
for (let depth = 0; depth < 4 && error !== null && typeof error === "object"; depth++) {
|
|
1208
|
+
if (error[REFUSED_ARGUMENT] === true) return error;
|
|
1209
|
+
error = error.cause;
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
const refused = plugin => REFUSED_TAGS.includes(plugin.tag);
|
|
1213
|
+
const reachesRefused = plugin => refused(plugin) || !!plugin.extends && plugin.extends.some(reachesRefused);
|
|
1214
|
+
function filterPlugins(plugins, out, seen) {
|
|
1215
|
+
for (const plugin of plugins) {
|
|
1216
|
+
if (seen.has(plugin)) continue;
|
|
1217
|
+
seen.add(plugin);
|
|
1218
|
+
if (refused(plugin)) continue;
|
|
1219
|
+
const severs = !!plugin.extends && plugin.extends.some(reachesRefused);
|
|
1220
|
+
out.push(severs ? {
|
|
1221
|
+
...plugin,
|
|
1222
|
+
extends: undefined
|
|
1223
|
+
} : plugin);
|
|
1224
|
+
if (plugin.extends) filterPlugins(plugin.extends, out, seen);
|
|
1225
|
+
}
|
|
1226
|
+
return out;
|
|
1227
|
+
}
|
|
1228
|
+
let defaultArgumentPlugins;
|
|
1229
|
+
const customArgumentPlugins = new WeakMap();
|
|
1230
|
+
function argumentDecodeCodec(codec, defaults) {
|
|
1231
|
+
const custom = codec && codec.plugins;
|
|
1232
|
+
let plugins = custom ? customArgumentPlugins.get(custom) : defaultArgumentPlugins;
|
|
1233
|
+
if (!plugins) {
|
|
1234
|
+
plugins = filterPlugins(custom ? [...custom, ...defaults] : defaults, [], new Set());
|
|
1235
|
+
if (custom) customArgumentPlugins.set(custom, plugins);else defaultArgumentPlugins = plugins;
|
|
1236
|
+
}
|
|
1237
|
+
return {
|
|
1238
|
+
...codec,
|
|
1239
|
+
[RESOLVED_PLUGINS]: plugins
|
|
1240
|
+
};
|
|
1241
|
+
}
|
|
1242
|
+
function namesRefusedType(payload) {
|
|
1243
|
+
for (const tag of REFUSED_TAGS) if (payload.includes(`"c":"${tag}"`)) return true;
|
|
1244
|
+
return false;
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1189
1247
|
const config = {
|
|
1190
1248
|
provideEvent: undefined,
|
|
1191
1249
|
wrapInvocation: undefined,
|
|
@@ -1751,14 +1809,49 @@ function unknownFormatError(tag) {
|
|
|
1751
1809
|
error[FORMAT_SKEW] = true;
|
|
1752
1810
|
return error;
|
|
1753
1811
|
}
|
|
1754
|
-
async function
|
|
1812
|
+
async function decodeArguments(decode, payload) {
|
|
1813
|
+
if (payload === null) return await decode(undefined);
|
|
1814
|
+
const refuseNamed = () => {
|
|
1815
|
+
const text = typeof payload === "string" ? payload : new TextDecoder().decode(payload);
|
|
1816
|
+
if (namesRefusedType(text)) throw refusedArgumentError();
|
|
1817
|
+
};
|
|
1818
|
+
const connection = {};
|
|
1819
|
+
let value;
|
|
1820
|
+
try {
|
|
1821
|
+
value = await decode({
|
|
1822
|
+
connection
|
|
1823
|
+
});
|
|
1824
|
+
} catch (error) {
|
|
1825
|
+
if (connection.ended) connection.ended.then(end => end.sweep());
|
|
1826
|
+
refuseNamed();
|
|
1827
|
+
throw error;
|
|
1828
|
+
}
|
|
1829
|
+
if (connection.ended) {
|
|
1830
|
+
const {
|
|
1831
|
+
open,
|
|
1832
|
+
sweep
|
|
1833
|
+
} = await connection.ended;
|
|
1834
|
+
sweep();
|
|
1835
|
+
if (open) refuseNamed();
|
|
1836
|
+
}
|
|
1837
|
+
return value;
|
|
1838
|
+
}
|
|
1839
|
+
let decodeModule;
|
|
1840
|
+
async function loadArgumentCodec(codec) {
|
|
1841
|
+
decodeModule = await import('@solidjs/web/serialization/decode');
|
|
1842
|
+
return argumentDecodeCodec(codec, decodeModule.DEFAULT_WEB_PLUGINS);
|
|
1843
|
+
}
|
|
1844
|
+
const argumentCodecFor = codec => decodeModule ? argumentDecodeCodec(codec, decodeModule.DEFAULT_WEB_PLUGINS) : loadArgumentCodec(codec);
|
|
1845
|
+
async function parseArguments(request, url, scripted, codec, buffered) {
|
|
1755
1846
|
const parsed = [];
|
|
1756
1847
|
const bodyFormat = request.method === "POST" ? request.headers.get(BODY_FORMAT_HEADER) : null;
|
|
1757
1848
|
const args = url.searchParams.get("args");
|
|
1758
1849
|
if (args && (!scripted || request.method === "GET" || bodyFormat !== BodyFormat.Serialized)) {
|
|
1759
1850
|
let result;
|
|
1760
1851
|
if (args.startsWith(";0x")) {
|
|
1761
|
-
|
|
1852
|
+
let argumentCodec = argumentCodecFor(codec);
|
|
1853
|
+
if (argumentCodec instanceof Promise) argumentCodec = await argumentCodec;
|
|
1854
|
+
result = await decodeArguments(wire => deserializeStream(new Response(args), argumentCodec, wire), args);
|
|
1762
1855
|
} else {
|
|
1763
1856
|
result = JSON.parse(args);
|
|
1764
1857
|
assertDecodeDepth(result);
|
|
@@ -1778,7 +1871,14 @@ async function parseArguments(request, url, scripted, codec) {
|
|
|
1778
1871
|
throw unknownFormatError(bodyFormat);
|
|
1779
1872
|
}
|
|
1780
1873
|
const body = request.clone();
|
|
1781
|
-
|
|
1874
|
+
let decoded;
|
|
1875
|
+
if (bodyFormat === BodyFormat.Serialized) {
|
|
1876
|
+
let argumentCodec = argumentCodecFor(codec);
|
|
1877
|
+
if (argumentCodec instanceof Promise) argumentCodec = await argumentCodec;
|
|
1878
|
+
decoded = await decodeArguments(wire => extractBody(body, argumentCodec, wire), buffered);
|
|
1879
|
+
} else {
|
|
1880
|
+
decoded = await extractBody(body, codec);
|
|
1881
|
+
}
|
|
1782
1882
|
if (bodyFormat === BodyFormat.Serialized || bodyFormat === BodyFormat.Json) {
|
|
1783
1883
|
if (bodyFormat === BodyFormat.Json) assertDecodeDepth(decoded);
|
|
1784
1884
|
if (!Array.isArray(decoded)) {
|
|
@@ -2759,6 +2859,7 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
2759
2859
|
});
|
|
2760
2860
|
return finish(protectsRequest ? withCSRFVary(response) : response);
|
|
2761
2861
|
}
|
|
2862
|
+
let argumentBytes = null;
|
|
2762
2863
|
if (method === "POST" && request.body !== null && bodySizeLimit !== Infinity) {
|
|
2763
2864
|
const raw = request.headers.get("content-length");
|
|
2764
2865
|
const declared = raw !== null && /^\d+$/.test(raw) ? Number(raw) : NaN;
|
|
@@ -2784,6 +2885,7 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
2784
2885
|
return finish(protectsRequest ? withCSRFVary(response) : response);
|
|
2785
2886
|
}
|
|
2786
2887
|
request = withBufferedBody(request, buffered);
|
|
2888
|
+
argumentBytes = buffered;
|
|
2787
2889
|
}
|
|
2788
2890
|
let event;
|
|
2789
2891
|
try {
|
|
@@ -2840,10 +2942,10 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
2840
2942
|
const collectsFlight = flightHooks.length > 0;
|
|
2841
2943
|
let parsed;
|
|
2842
2944
|
try {
|
|
2843
|
-
parsed = await parseArguments(request, url, scripted, codec);
|
|
2945
|
+
parsed = await parseArguments(request, url, scripted, codec, argumentBytes);
|
|
2844
2946
|
} catch (error) {
|
|
2845
|
-
const
|
|
2846
|
-
const response = new Response(DEV ?
|
|
2947
|
+
const named = error !== null && typeof error === "object" && error[FORMAT_SKEW] === true ? error : refusedArgument(error);
|
|
2948
|
+
const response = new Response(DEV ? named ? named.message : "Malformed server function arguments" : null, {
|
|
2847
2949
|
status: 400
|
|
2848
2950
|
});
|
|
2849
2951
|
return refuseCommitted(response);
|
|
@@ -2897,7 +2999,7 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
2897
2999
|
response,
|
|
2898
3000
|
value
|
|
2899
3001
|
} = result;
|
|
2900
|
-
if (!scripted && !handleNoJS && response && response.body) {
|
|
3002
|
+
if (!scripted && !handleNoJS && response && response.body && isJSONSafe(value)) {
|
|
2901
3003
|
return response;
|
|
2902
3004
|
}
|
|
2903
3005
|
if (response && response.headers) {
|
|
@@ -3086,11 +3188,15 @@ function ownResponse(response) {
|
|
|
3086
3188
|
function finalizeTransportResponse(response, method) {
|
|
3087
3189
|
const stripBody = method === "HEAD" && response.body !== null;
|
|
3088
3190
|
const defaultsCache = !response.headers.has("Cache-Control") && response.status !== 304;
|
|
3089
|
-
|
|
3191
|
+
const defaultsSniff = !response.headers.has("X-Content-Type-Options");
|
|
3192
|
+
if (stripBody || defaultsCache || defaultsSniff) {
|
|
3090
3193
|
try {
|
|
3091
3194
|
if (defaultsCache) {
|
|
3092
3195
|
response.headers.set("Cache-Control", "no-store");
|
|
3093
3196
|
}
|
|
3197
|
+
if (defaultsSniff) {
|
|
3198
|
+
response.headers.set("X-Content-Type-Options", "nosniff");
|
|
3199
|
+
}
|
|
3094
3200
|
if (!stripBody) return response;
|
|
3095
3201
|
response.body.cancel().catch(() => {});
|
|
3096
3202
|
return new Response(null, {
|
|
@@ -3101,6 +3207,9 @@ function finalizeTransportResponse(response, method) {
|
|
|
3101
3207
|
} catch {
|
|
3102
3208
|
const headers = new Headers(response.headers);
|
|
3103
3209
|
if (defaultsCache && !headers.has("Cache-Control")) headers.set("Cache-Control", "no-store");
|
|
3210
|
+
if (defaultsSniff && !headers.has("X-Content-Type-Options")) {
|
|
3211
|
+
headers.set("X-Content-Type-Options", "nosniff");
|
|
3212
|
+
}
|
|
3104
3213
|
if (stripBody) response.body.cancel().catch(() => {});
|
|
3105
3214
|
return new Response(stripBody ? null : response.body, {
|
|
3106
3215
|
status: response.status,
|