@farm.js/core 0.1.36 → 0.1.38
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/dist/{agent-mcp-BVExL8rZ.d.mts → agent-mcp-BwKlpnc7.d.mts} +1 -1
- package/dist/{agent-mcp-luzfXK-P.d.ts → agent-mcp-De1imoMS.d.ts} +1 -1
- package/dist/{agent-mcp-handler-SJAHFSPI.cjs → agent-mcp-handler-MRGP3WJ3.cjs} +5 -5
- package/dist/{agent-mcp-handler-LPJ2CADR.mjs → agent-mcp-handler-OLRMZONF.mjs} +4 -4
- package/dist/agent-runtime.cjs +3 -3
- package/dist/agent-runtime.d.mts +1 -1
- package/dist/agent-runtime.d.ts +1 -1
- package/dist/agent-runtime.mjs +2 -2
- package/dist/api/client.cjs +3 -3
- package/dist/api/client.mjs +2 -2
- package/dist/api/route-manager.cjs +6 -6
- package/dist/api/route-manager.d.mts +3 -3
- package/dist/api/route-manager.d.ts +3 -3
- package/dist/api/route-manager.mjs +5 -5
- package/dist/api/runtime.cjs +4 -4
- package/dist/api/runtime.d.mts +2 -2
- package/dist/api/runtime.d.ts +2 -2
- package/dist/api/runtime.mjs +3 -3
- package/dist/api.cjs +9 -8
- package/dist/api.d.mts +3 -3
- package/dist/api.d.ts +3 -3
- package/dist/api.mjs +8 -7
- package/dist/{app-BukwkFIu.d.mts → app-CFZt-srr.d.mts} +21 -3
- package/dist/{app-Yfa2dsFy.d.ts → app-kT_QXTdx.d.ts} +21 -3
- package/dist/app-markdown.cjs +6 -4
- package/dist/app-markdown.d.mts +3 -3
- package/dist/app-markdown.d.ts +3 -3
- package/dist/app-markdown.mjs +5 -3
- package/dist/{chunk-ADEA7PN3.cjs → chunk-2DD4JMQC.cjs} +113 -22
- package/dist/chunk-2ZYGC6SS.cjs +576 -0
- package/dist/{chunk-JZVADIOD.cjs → chunk-34UCJRQO.cjs} +2 -2
- package/dist/{chunk-D2BB47NB.cjs → chunk-3LOLJTFV.cjs} +6 -6
- package/dist/{chunk-KXWRO25S.cjs → chunk-472NCAZ7.cjs} +3 -3
- package/dist/chunk-4E5QXOCL.cjs +109 -0
- package/dist/{chunk-Z2HLU4IX.cjs → chunk-4GWRFP22.cjs} +23 -2
- package/dist/{chunk-VQLJWDVW.cjs → chunk-4IE345DM.cjs} +37 -19
- package/dist/{chunk-O6WAEAX3.mjs → chunk-5BWWFHR2.mjs} +70 -15
- package/dist/{chunk-JNUWCDTF.cjs → chunk-5D2JIPLH.cjs} +2 -2
- package/dist/{chunk-BO36SELV.cjs → chunk-5OKBARDN.cjs} +2 -2
- package/dist/{chunk-AO6RYU5N.cjs → chunk-5PWXMJOH.cjs} +30 -22
- package/dist/{chunk-AHGECQEW.mjs → chunk-666CKENS.mjs} +1 -1
- package/dist/chunk-6BK3K2GB.mjs +318 -0
- package/dist/{chunk-O6I6VWKK.mjs → chunk-6HB6V3R7.mjs} +1 -1
- package/dist/{chunk-UXFQ3UDA.cjs → chunk-6XWDE2P2.cjs} +61 -4
- package/dist/{chunk-VILIPRS6.mjs → chunk-7FPTZLKH.mjs} +1 -1
- package/dist/{chunk-SC2WYWPF.mjs → chunk-7PEP3BUT.mjs} +3 -3
- package/dist/{chunk-4E5AEDKY.mjs → chunk-A3EAIURZ.mjs} +25 -7
- package/dist/{chunk-YDQZGSDS.mjs → chunk-ARC7I3O2.mjs} +1 -1
- package/dist/{chunk-LSZAVSGY.mjs → chunk-B6G5CKMC.mjs} +101 -10
- package/dist/{chunk-3KZS4SUS.mjs → chunk-BZHXGVMA.mjs} +1 -1
- package/dist/{chunk-KN7K4VQN.mjs → chunk-CNNOLE4O.mjs} +1 -1
- package/dist/{chunk-4GLOOWKE.mjs → chunk-CQMVIOYP.mjs} +1 -1
- package/dist/{chunk-2ELDTQRN.mjs → chunk-CUM5NYL5.mjs} +1 -1
- package/dist/{chunk-HITLGIAO.cjs → chunk-CY2ZQ5C6.cjs} +7 -6
- package/dist/{chunk-PZNL3WEG.mjs → chunk-DMEPTZTI.mjs} +22 -11
- package/dist/{chunk-QORUJDIV.mjs → chunk-DRLKAXDM.mjs} +2 -2
- package/dist/{chunk-DQQOKWYA.cjs → chunk-EIPC3FDA.cjs} +12 -4
- package/dist/{chunk-HOXTWRGB.mjs → chunk-EKF7KDFD.mjs} +5 -2
- package/dist/{chunk-42NHY7HW.cjs → chunk-EKN7NSZO.cjs} +62 -14
- package/dist/{chunk-YKX5BK66.cjs → chunk-EMO6K4YY.cjs} +7 -7
- package/dist/{chunk-6SJ2KJTA.mjs → chunk-EPYU2EBL.mjs} +1 -1
- package/dist/{chunk-D227TIEN.cjs → chunk-FWE7LEQC.cjs} +13 -13
- package/dist/{chunk-PTZ2TVNE.cjs → chunk-H5CLOUZS.cjs} +5 -5
- package/dist/{chunk-DTSROJ5J.mjs → chunk-HD5CF3OE.mjs} +1 -1
- package/dist/{chunk-35GKZR22.mjs → chunk-HXRYZWTA.mjs} +1 -1
- package/dist/{chunk-JG6DJF5A.mjs → chunk-HZFM2LWQ.mjs} +22 -1
- package/dist/{chunk-MKYBIIAQ.mjs → chunk-IBUQWVYA.mjs} +17 -1
- package/dist/{chunk-F2SE2VDO.mjs → chunk-IHQIOZLC.mjs} +1 -1
- package/dist/{chunk-W7LF2J2S.mjs → chunk-INL3THCU.mjs} +1 -1
- package/dist/{chunk-WZ77PUAM.mjs → chunk-IVLZZZEI.mjs} +1 -1
- package/dist/{chunk-ENLZ4R3Y.mjs → chunk-J7K2NZD6.mjs} +7 -6
- package/dist/{chunk-BPOF5U4N.mjs → chunk-JCKYH4LG.mjs} +10 -7
- package/dist/{chunk-77GNHH2Z.cjs → chunk-JCYYXBAJ.cjs} +3 -3
- package/dist/{chunk-C4SPBWFM.cjs → chunk-JEZO6VUR.cjs} +10 -1
- package/dist/{chunk-ZWM5KGAA.cjs → chunk-KCQBAKIY.cjs} +23 -20
- package/dist/{chunk-OTC5BDGO.mjs → chunk-KHKLMNI5.mjs} +12 -7
- package/dist/{chunk-DZ5ZVB2K.cjs → chunk-KKSTAEMY.cjs} +1 -1
- package/dist/{chunk-N2NAS2AM.cjs → chunk-L4DD7ODZ.cjs} +2 -2
- package/dist/{chunk-YSCV4SJF.cjs → chunk-L5H2GSUC.cjs} +4 -4
- package/dist/{chunk-OO7GXVSR.mjs → chunk-LI2F57NI.mjs} +1 -1
- package/dist/{chunk-NRSN7G7E.mjs → chunk-MLY2RP5R.mjs} +10 -2
- package/dist/{chunk-BPMATOP2.cjs → chunk-N32CC42M.cjs} +25 -20
- package/dist/{chunk-FNO7A7CM.cjs → chunk-NBBEQLOK.cjs} +34 -16
- package/dist/{chunk-XCMCS4DA.mjs → chunk-ND2CWPOD.mjs} +2 -2
- package/dist/{chunk-GQRWBCWK.mjs → chunk-OAHTRMIC.mjs} +13 -5
- package/dist/{chunk-35WV46VL.mjs → chunk-OCIEZME4.mjs} +876 -685
- package/dist/{chunk-UH6QN5NL.mjs → chunk-P664ZVTV.mjs} +2 -2
- package/dist/{chunk-TE2G5ION.cjs → chunk-PGZDEPTM.cjs} +88 -33
- package/dist/{chunk-FDR64H6B.mjs → chunk-POSPE3IO.mjs} +59 -2
- package/dist/{chunk-UVW64BCB.cjs → chunk-Q3NXS4MU.cjs} +16 -14
- package/dist/{chunk-4WCZJQUO.mjs → chunk-QFW2IH5E.mjs} +57 -9
- package/dist/{chunk-5SJWVY6R.mjs → chunk-QHSH7IH4.mjs} +9 -0
- package/dist/chunk-QRKIMN7T.mjs +48 -0
- package/dist/chunk-QTXBII4Z.cjs +632 -0
- package/dist/{chunk-CI6E3UOH.cjs → chunk-RG4A6LB2.cjs} +7 -7
- package/dist/{chunk-BJPBQNIE.cjs → chunk-RW63BOV7.cjs} +2 -2
- package/dist/{chunk-FO427P6I.cjs → chunk-RWFLWR5J.cjs} +10 -10
- package/dist/{chunk-FFFW3OQ7.cjs → chunk-S6FJO323.cjs} +2 -2
- package/dist/{chunk-EUV4YR3V.cjs → chunk-SGBJ247Q.cjs} +18 -2
- package/dist/chunk-SGBZPZUW.mjs +75 -0
- package/dist/{chunk-2NNMOPDN.mjs → chunk-SKVTP5PR.mjs} +4 -1
- package/dist/{chunk-2YTDKNH3.cjs → chunk-TGFQVLLF.cjs} +956 -765
- package/dist/{chunk-IHNIDL6H.cjs → chunk-TO4GJ56K.cjs} +22 -11
- package/dist/{chunk-276VJSM6.mjs → chunk-TUBTR2OP.mjs} +250 -118
- package/dist/{chunk-GQ3Z3IZI.cjs → chunk-TYJALEHQ.cjs} +18 -18
- package/dist/chunk-TYMMBFN2.mjs +109 -0
- package/dist/chunk-U6QLDL3G.mjs +576 -0
- package/dist/{chunk-U4KT7QP3.cjs → chunk-ULASELLA.cjs} +26 -1
- package/dist/chunk-UXHS27O6.cjs +75 -0
- package/dist/{chunk-WWIKMBRN.mjs → chunk-VNGH5MLF.mjs} +17 -1
- package/dist/{chunk-EZDQRNQ7.mjs → chunk-VT4WFRHA.mjs} +23 -5
- package/dist/{chunk-CBJJH36A.cjs → chunk-VU6AAZVY.cjs} +20 -4
- package/dist/{chunk-27ZWSI3W.cjs → chunk-VXEEATVD.cjs} +2 -2
- package/dist/{chunk-EWET4D2Y.mjs → chunk-W36M2BQ4.mjs} +3 -3
- package/dist/{chunk-4WQ6PGSJ.cjs → chunk-WEW2JVA4.cjs} +4 -4
- package/dist/{chunk-4E5WBPEG.mjs → chunk-WFRT7JPX.mjs} +8 -533
- package/dist/{chunk-T4OGRVNS.mjs → chunk-WLL43JMO.mjs} +2 -2
- package/dist/chunk-WW46B6HA.cjs +318 -0
- package/dist/{chunk-TKSCR644.cjs → chunk-WXJLNP33.cjs} +2 -2
- package/dist/{chunk-S6VYG6XU.cjs → chunk-XKG2BLFN.cjs} +2 -2
- package/dist/{chunk-4NU4GGTC.cjs → chunk-XKVVMZP5.cjs} +6 -3
- package/dist/{chunk-NMHWYWDR.cjs → chunk-YR2VBEMO.cjs} +658 -526
- package/dist/{chunk-OHLSEQ57.mjs → chunk-ZJD2PN6Z.mjs} +10 -8
- package/dist/{chunk-3BU22U3M.cjs → chunk-ZXH4TS3F.cjs} +5 -2
- package/dist/{client-plugins-r1mOtSC1.d.ts → client-plugins-BvlNhGEB.d.ts} +54 -7
- package/dist/{client-plugins-C3mK9Pol.d.mts → client-plugins-DUrIYX9B.d.mts} +54 -7
- package/dist/client-plugins.d.mts +1 -1
- package/dist/client-plugins.d.ts +1 -1
- package/dist/client.cjs +8 -8
- package/dist/client.d.mts +5 -5
- package/dist/client.d.ts +5 -5
- package/dist/client.mjs +7 -7
- package/dist/config.d.mts +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/{devtools-ERIKFEXX.mjs → devtools-JYJNOLPQ.mjs} +8 -6
- package/dist/{devtools-JZJJY5CK.cjs → devtools-VQWJANJV.cjs} +9 -7
- package/dist/docs.cjs +12 -10
- package/dist/docs.d.mts +20 -2
- package/dist/docs.d.ts +20 -2
- package/dist/docs.mjs +11 -9
- package/dist/headers.cjs +6 -4
- package/dist/headers.d.mts +11 -1
- package/dist/headers.d.ts +11 -1
- package/dist/headers.mjs +5 -3
- package/dist/i18n/client.cjs +11 -11
- package/dist/i18n/client.mjs +3 -3
- package/dist/index.cjs +62 -46
- package/dist/index.d.mts +16 -16
- package/dist/index.d.ts +16 -16
- package/dist/index.mjs +62 -46
- package/dist/integrations.cjs +5 -3
- package/dist/integrations.d.mts +1 -1
- package/dist/integrations.d.ts +1 -1
- package/dist/integrations.mjs +4 -2
- package/dist/internal/app-markdown-runtime.cjs +5 -3
- package/dist/internal/app-markdown-runtime.d.mts +19 -5
- package/dist/internal/app-markdown-runtime.d.ts +19 -5
- package/dist/internal/app-markdown-runtime.mjs +4 -2
- package/dist/internal/build-runtime.cjs +33 -30
- package/dist/internal/build-runtime.d.mts +3 -3
- package/dist/internal/build-runtime.d.ts +3 -3
- package/dist/internal/build-runtime.mjs +32 -29
- package/dist/internal/cli-runtime.cjs +14 -12
- package/dist/internal/cli-runtime.mjs +13 -11
- package/dist/internal/client-error-overlay.cjs +4 -4
- package/dist/internal/client-error-overlay.mjs +1 -1
- package/dist/internal/client-runtime.cjs +2 -2
- package/dist/internal/client-runtime.mjs +1 -1
- package/dist/internal/compression-runtime.d.mts +1 -1
- package/dist/internal/compression-runtime.d.ts +1 -1
- package/dist/internal/config-runtime.cjs +9 -7
- package/dist/internal/config-runtime.d.mts +2 -2
- package/dist/internal/config-runtime.d.ts +2 -2
- package/dist/internal/config-runtime.mjs +8 -6
- package/dist/internal/docs-precompiled-runtime.cjs +19 -13
- package/dist/internal/docs-precompiled-runtime.d.mts +5 -0
- package/dist/internal/docs-precompiled-runtime.d.ts +5 -0
- package/dist/internal/docs-precompiled-runtime.mjs +14 -8
- package/dist/internal/infra-analytics-runtime.cjs +5 -5
- package/dist/internal/infra-analytics-runtime.mjs +3 -3
- package/dist/internal/product-telemetry-runtime.cjs +2 -2
- package/dist/internal/product-telemetry-runtime.mjs +1 -1
- package/dist/internal/production-node-env.cjs +6 -2
- package/dist/internal/production-node-env.d.mts +10 -1
- package/dist/internal/production-node-env.d.ts +10 -1
- package/dist/internal/production-node-env.mjs +5 -1
- package/dist/internal/production-runtime.cjs +39 -54
- package/dist/internal/production-runtime.d.mts +51 -11
- package/dist/internal/production-runtime.d.ts +51 -11
- package/dist/internal/production-runtime.mjs +39 -54
- package/dist/markdown.cjs +8 -2
- package/dist/markdown.d.mts +1 -1
- package/dist/markdown.d.ts +1 -1
- package/dist/markdown.mjs +7 -1
- package/dist/middleware.cjs +10 -8
- package/dist/middleware.d.mts +27 -5
- package/dist/middleware.d.ts +27 -5
- package/dist/middleware.mjs +10 -8
- package/dist/navigation.cjs +7 -7
- package/dist/navigation.d.mts +4 -4
- package/dist/navigation.d.ts +4 -4
- package/dist/navigation.mjs +6 -6
- package/dist/plugin.cjs +25 -23
- package/dist/plugin.d.mts +1 -1
- package/dist/plugin.d.ts +1 -1
- package/dist/plugin.mjs +24 -22
- package/dist/{production-runtime-CCeVZXst.d.mts → production-runtime-BQ4_WLwQ.d.mts} +1 -1
- package/dist/{production-runtime-DPnsggY3.d.ts → production-runtime-D2aMyzjr.d.ts} +1 -1
- package/dist/query/client.cjs +9 -9
- package/dist/query/client.mjs +4 -4
- package/dist/{render-plan-Cw4f5E_R.d.ts → render-plan-25p4hrj4.d.ts} +1 -1
- package/dist/{render-plan-BuGaPFe6.d.mts → render-plan-DtkXMN8D.d.mts} +1 -1
- package/dist/renderer-client.cjs +12 -12
- package/dist/renderer-client.d.mts +3 -3
- package/dist/renderer-client.d.ts +3 -3
- package/dist/renderer-client.mjs +4 -4
- package/dist/renderer.d.mts +13 -4
- package/dist/renderer.d.ts +13 -4
- package/dist/{request-CsGARcAw.d.mts → request-DgCkIdcn.d.mts} +4 -2
- package/dist/{request-Bkg-hERy.d.ts → request-jF4jwx8f.d.ts} +4 -2
- package/dist/request.cjs +3 -3
- package/dist/request.d.mts +2 -2
- package/dist/request.d.ts +2 -2
- package/dist/request.mjs +2 -2
- package/dist/{route-rendering-BUZMH_64.d.ts → route-rendering-Bji6S6a_.d.ts} +1 -1
- package/dist/{route-rendering-f11yh5dp.d.mts → route-rendering-CSBF78Ya.d.mts} +1 -1
- package/dist/{router-Cp6yRE8A.d.mts → router-B09Ui3Qm.d.mts} +1 -1
- package/dist/{router-B8CR9GbD.d.ts → router-CPB9cXtG.d.ts} +1 -1
- package/dist/routes.cjs +2 -2
- package/dist/routes.d.mts +1 -1
- package/dist/routes.d.ts +1 -1
- package/dist/routes.mjs +1 -1
- package/dist/{runtime-CAEv36S_.d.mts → runtime-CM6E6yuI.d.mts} +1 -1
- package/dist/{runtime-CQVsT330.d.ts → runtime-EDMwLdjv.d.ts} +1 -1
- package/dist/server-fn.cjs +3 -3
- package/dist/server-fn.mjs +2 -2
- package/dist/server-plugins.cjs +5 -5
- package/dist/server-plugins.d.mts +2 -2
- package/dist/server-plugins.d.ts +2 -2
- package/dist/server-plugins.mjs +4 -4
- package/dist/server-query.cjs +4 -4
- package/dist/server-query.mjs +3 -3
- package/dist/server.cjs +51 -49
- package/dist/server.d.mts +7 -7
- package/dist/server.d.ts +7 -7
- package/dist/server.mjs +29 -27
- package/dist/{spa-router-BuciWGCZ.d.ts → spa-router-B_N8XgVu.d.ts} +2 -2
- package/dist/{spa-router-DwbqGkGj.d.mts → spa-router-Cgimzfbi.d.mts} +2 -2
- package/dist/testing.cjs +8 -8
- package/dist/testing.d.mts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.mjs +6 -6
- package/dist/theme/server.cjs +4 -4
- package/dist/theme/server.mjs +3 -3
- package/dist/{utils-CaoWKtYM.d.ts → utils-BNxAKAuT.d.ts} +1 -1
- package/dist/{utils-B9V0S_yL.d.mts → utils-DZciYXYl.d.mts} +1 -1
- package/dist/version.cjs +2 -2
- package/dist/version.mjs +1 -1
- package/dist/vite.cjs +25 -23
- package/dist/vite.d.mts +1 -1
- package/dist/vite.d.ts +1 -1
- package/dist/vite.mjs +24 -22
- package/package.json +1 -1
- package/types/middleware.d.ts +5 -1
- package/dist/chunk-655RLQQL.mjs +0 -43
- package/dist/chunk-FXEF4PPL.mjs +0 -47
- package/dist/chunk-IZY3V5XW.mjs +0 -23
- package/dist/chunk-MRMI32SN.cjs +0 -1157
- package/dist/chunk-MT763TDW.cjs +0 -43
- package/dist/chunk-XD32KALF.cjs +0 -47
- /package/dist/{chunk-SJNMVDDF.cjs → chunk-FUCSUGDM.cjs} +0 -0
- /package/dist/{chunk-UDNPLXW7.mjs → chunk-MYIZXDZA.mjs} +0 -0
|
@@ -0,0 +1,576 @@
|
|
|
1
|
+
import {
|
|
2
|
+
_markFarmOwnedResponse,
|
|
3
|
+
_withFarmResponseHeaders
|
|
4
|
+
} from "./chunk-Z3HATSKO.mjs";
|
|
5
|
+
import {
|
|
6
|
+
_resolveCurrentCspNonce
|
|
7
|
+
} from "./chunk-QRKIMN7T.mjs";
|
|
8
|
+
import {
|
|
9
|
+
__name
|
|
10
|
+
} from "./chunk-LPEX4YW6.mjs";
|
|
11
|
+
|
|
12
|
+
// src/security.ts
|
|
13
|
+
function resolveFarmSecurityConfig(input) {
|
|
14
|
+
if (input === void 0) return { csp: false };
|
|
15
|
+
if (!isPlainRecord(input)) {
|
|
16
|
+
throw new TypeError("security must be an object containing the csp option.");
|
|
17
|
+
}
|
|
18
|
+
if (Object.prototype.hasOwnProperty.call(input, "contentSecurityPolicy")) {
|
|
19
|
+
throw new TypeError(
|
|
20
|
+
"security.contentSecurityPolicy is not supported. Use security.csp instead."
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
const csp = input.csp;
|
|
24
|
+
if (csp === void 0 || csp === false) return { csp: false };
|
|
25
|
+
if (typeof csp === "string") {
|
|
26
|
+
return {
|
|
27
|
+
csp: {
|
|
28
|
+
value: validateSerializedCsp(csp),
|
|
29
|
+
reportOnly: false,
|
|
30
|
+
nonce: false
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
if (!isPlainRecord(csp)) {
|
|
35
|
+
throw new TypeError("security.csp must be a policy string, false, or an options object.");
|
|
36
|
+
}
|
|
37
|
+
const reportOnly = validateReportOnly(csp.reportOnly);
|
|
38
|
+
const nonce = validateNonce(csp.nonce);
|
|
39
|
+
if (Object.prototype.hasOwnProperty.call(csp, "value")) {
|
|
40
|
+
if (Object.prototype.hasOwnProperty.call(csp, "policy") || Object.prototype.hasOwnProperty.call(csp, "directives")) {
|
|
41
|
+
throw new TypeError(
|
|
42
|
+
"Resolved security.csp values cannot include policy or directives options."
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
csp: {
|
|
47
|
+
value: validateSerializedCsp(csp.value),
|
|
48
|
+
reportOnly,
|
|
49
|
+
nonce
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
const { policy, directives } = csp;
|
|
54
|
+
if (policy !== void 0 && directives !== void 0) {
|
|
55
|
+
throw new TypeError("security.csp accepts either policy or directives, not both.");
|
|
56
|
+
}
|
|
57
|
+
if (policy === void 0 && directives === void 0) {
|
|
58
|
+
throw new TypeError("security.csp requires a policy string or directives object.");
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
csp: {
|
|
62
|
+
value: policy !== void 0 ? validateSerializedCsp(policy) : serializeFarmCspDirectives(directives),
|
|
63
|
+
reportOnly,
|
|
64
|
+
nonce
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
__name(resolveFarmSecurityConfig, "resolveFarmSecurityConfig");
|
|
69
|
+
function serializeFarmCspDirectives(directives) {
|
|
70
|
+
if (!isPlainRecord(directives)) {
|
|
71
|
+
throw new TypeError("security.csp.directives must be an object.");
|
|
72
|
+
}
|
|
73
|
+
const serialized = [];
|
|
74
|
+
const normalizedNames = /* @__PURE__ */ new Set();
|
|
75
|
+
for (const [configuredName, configuredValue] of Object.entries(directives)) {
|
|
76
|
+
if (configuredValue === false || configuredValue === null || configuredValue === void 0) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const name = normalizeDirectiveName(configuredName);
|
|
80
|
+
if (normalizedNames.has(name)) {
|
|
81
|
+
throw new TypeError(`security.csp contains the duplicate directive ${JSON.stringify(name)}.`);
|
|
82
|
+
}
|
|
83
|
+
normalizedNames.add(name);
|
|
84
|
+
const values = configuredValue === true ? [] : (Array.isArray(configuredValue) ? configuredValue : [configuredValue]).map(
|
|
85
|
+
validateDirectiveValue
|
|
86
|
+
);
|
|
87
|
+
serialized.push(values.length > 0 ? `${name} ${values.join(" ")}` : name);
|
|
88
|
+
}
|
|
89
|
+
if (serialized.length === 0) {
|
|
90
|
+
throw new TypeError("security.csp.directives must contain at least one enabled directive.");
|
|
91
|
+
}
|
|
92
|
+
return serialized.join("; ");
|
|
93
|
+
}
|
|
94
|
+
__name(serializeFarmCspDirectives, "serializeFarmCspDirectives");
|
|
95
|
+
function getFarmSecurityHeader(security, nonce) {
|
|
96
|
+
if (!security.csp) return void 0;
|
|
97
|
+
if (security.csp.nonce && !nonce) return void 0;
|
|
98
|
+
return {
|
|
99
|
+
key: security.csp.reportOnly ? "Content-Security-Policy-Report-Only" : "Content-Security-Policy",
|
|
100
|
+
value: nonce ? applyFarmCspNonceToPolicy(security.csp.value, nonce) : security.csp.value
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
__name(getFarmSecurityHeader, "getFarmSecurityHeader");
|
|
104
|
+
function createFarmCspNonce(security) {
|
|
105
|
+
if (!security.csp || !security.csp.nonce) return void 0;
|
|
106
|
+
const bytes = new Uint8Array(16);
|
|
107
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
108
|
+
return Array.from(bytes, (value) => value.toString(16).padStart(2, "0")).join("");
|
|
109
|
+
}
|
|
110
|
+
__name(createFarmCspNonce, "createFarmCspNonce");
|
|
111
|
+
function applyFarmCspNonceToPolicy(policy, nonce) {
|
|
112
|
+
validateCspNonce(nonce);
|
|
113
|
+
return applyFarmCspScriptSourcesToPolicy(policy, [`'nonce-${nonce}'`]);
|
|
114
|
+
}
|
|
115
|
+
__name(applyFarmCspNonceToPolicy, "applyFarmCspNonceToPolicy");
|
|
116
|
+
function applyFarmCspHashesToPolicy(policy, hashes) {
|
|
117
|
+
const sources = hashes.map((hash) => {
|
|
118
|
+
if (!/^sha(?:256|384|512)-[A-Za-z0-9+/]+={0,2}$/.test(hash)) {
|
|
119
|
+
throw new TypeError(`Invalid CSP script hash: ${JSON.stringify(hash)}.`);
|
|
120
|
+
}
|
|
121
|
+
return `'${hash}'`;
|
|
122
|
+
});
|
|
123
|
+
return applyFarmCspScriptSourcesToPolicy(policy, sources);
|
|
124
|
+
}
|
|
125
|
+
__name(applyFarmCspHashesToPolicy, "applyFarmCspHashesToPolicy");
|
|
126
|
+
function applyFarmCspScriptSourcesToPolicy(policy, sources) {
|
|
127
|
+
const uniqueSources = [...new Set(sources)];
|
|
128
|
+
if (uniqueSources.length === 0) return policy;
|
|
129
|
+
const segments = policy.split(";").map((segment) => segment.trim()).filter(Boolean);
|
|
130
|
+
const names = segments.map((segment) => segment.split(/\s+/, 1)[0].toLowerCase());
|
|
131
|
+
const governingName = names.includes("script-src-elem") ? "script-src-elem" : names.includes("script-src") ? "script-src" : names.includes("default-src") ? "default-src" : void 0;
|
|
132
|
+
if (!governingName) return `${policy}; script-src ${uniqueSources.join(" ")}`;
|
|
133
|
+
return segments.map((segment, index) => {
|
|
134
|
+
if (names[index] !== governingName) return segment;
|
|
135
|
+
const existing = new Set(segment.split(/\s+/));
|
|
136
|
+
const missing = uniqueSources.filter((source) => !existing.has(source));
|
|
137
|
+
return missing.length > 0 ? `${segment} ${missing.join(" ")}` : segment;
|
|
138
|
+
}).join("; ");
|
|
139
|
+
}
|
|
140
|
+
__name(applyFarmCspScriptSourcesToPolicy, "applyFarmCspScriptSourcesToPolicy");
|
|
141
|
+
function addFarmCspNonceToScriptTags(html, nonce) {
|
|
142
|
+
validateCspNonce(nonce);
|
|
143
|
+
return createFarmScriptTagRewriter((tag) => stampScriptTag(tag, nonce)).write(html, true);
|
|
144
|
+
}
|
|
145
|
+
__name(addFarmCspNonceToScriptTags, "addFarmCspNonceToScriptTags");
|
|
146
|
+
function stampFarmCspNonce(html, nonce = _resolveCurrentCspNonce()) {
|
|
147
|
+
return nonce && html ? addFarmCspNonceToScriptTags(html, nonce) : html;
|
|
148
|
+
}
|
|
149
|
+
__name(stampFarmCspNonce, "stampFarmCspNonce");
|
|
150
|
+
function replaceFarmCspNonceMarker(html, marker, nonce = _resolveCurrentCspNonce()) {
|
|
151
|
+
validateCspNonce(marker);
|
|
152
|
+
if (nonce) validateCspNonce(nonce);
|
|
153
|
+
return createFarmScriptTagRewriter((tag) => {
|
|
154
|
+
const range = findScriptTagAttributeRange(tag, "nonce");
|
|
155
|
+
if (!range || readAttributeValue(tag.slice(range.start, range.end)) !== marker) return tag;
|
|
156
|
+
return nonce ? stampScriptTag(tag, nonce) : stripScriptNonceAttribute(tag);
|
|
157
|
+
}).write(html, true);
|
|
158
|
+
}
|
|
159
|
+
__name(replaceFarmCspNonceMarker, "replaceFarmCspNonceMarker");
|
|
160
|
+
function filterFarmCspNonces(html, nonce) {
|
|
161
|
+
return createFarmCspNonceRewriter(nonce).write(html, true);
|
|
162
|
+
}
|
|
163
|
+
__name(filterFarmCspNonces, "filterFarmCspNonces");
|
|
164
|
+
function removeFarmCspNoncesFromScriptTags(html) {
|
|
165
|
+
return createFarmScriptTagRewriter(stripScriptNonceAttribute).write(html, true);
|
|
166
|
+
}
|
|
167
|
+
__name(removeFarmCspNoncesFromScriptTags, "removeFarmCspNoncesFromScriptTags");
|
|
168
|
+
async function createFarmCspScriptHashes(html) {
|
|
169
|
+
const hashes = [];
|
|
170
|
+
const seen = /* @__PURE__ */ new Set();
|
|
171
|
+
for (const content of collectFarmInlineScriptContents(html)) {
|
|
172
|
+
const digest = await globalThis.crypto.subtle.digest(
|
|
173
|
+
"SHA-256",
|
|
174
|
+
new TextEncoder().encode(content)
|
|
175
|
+
);
|
|
176
|
+
let binary = "";
|
|
177
|
+
for (const byte of new Uint8Array(digest)) binary += String.fromCharCode(byte);
|
|
178
|
+
const hash = `sha256-${globalThis.btoa(binary)}`;
|
|
179
|
+
if (!seen.has(hash)) {
|
|
180
|
+
seen.add(hash);
|
|
181
|
+
hashes.push(hash);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return hashes;
|
|
185
|
+
}
|
|
186
|
+
__name(createFarmCspScriptHashes, "createFarmCspScriptHashes");
|
|
187
|
+
async function applyFarmCspHashesToHtml(html, security) {
|
|
188
|
+
if (!security.csp || !security.csp.nonce) return void 0;
|
|
189
|
+
const hashes = await createFarmCspScriptHashes(html);
|
|
190
|
+
const staticHtml = removeFarmCspNoncesFromScriptTags(html);
|
|
191
|
+
return {
|
|
192
|
+
html: staticHtml,
|
|
193
|
+
header: {
|
|
194
|
+
key: security.csp.reportOnly ? "Content-Security-Policy-Report-Only" : "Content-Security-Policy",
|
|
195
|
+
value: applyFarmCspHashesToPolicy(security.csp.value, hashes)
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
__name(applyFarmCspHashesToHtml, "applyFarmCspHashesToHtml");
|
|
200
|
+
function applyFarmCspNonceToResponse(response, security, nonce = createFarmCspNonce(security)) {
|
|
201
|
+
if (!security.csp || !security.csp.nonce || !nonce) return response;
|
|
202
|
+
if (!response.headers.get("content-type")?.toLowerCase().includes("text/html")) return response;
|
|
203
|
+
const securityHeader = getFarmSecurityHeader(security, nonce);
|
|
204
|
+
if (!response.body) {
|
|
205
|
+
return _withFarmResponseHeaders(response, (headers2) => {
|
|
206
|
+
headers2.set(securityHeader.key, securityHeader.value);
|
|
207
|
+
headers2.delete("content-length");
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
const headers = new Headers(response.headers);
|
|
211
|
+
headers.set(securityHeader.key, securityHeader.value);
|
|
212
|
+
headers.delete("content-length");
|
|
213
|
+
const decoder = new TextDecoder();
|
|
214
|
+
const encoder = new TextEncoder();
|
|
215
|
+
const rewriter = createFarmCspNonceRewriter(nonce);
|
|
216
|
+
const body = response.body.pipeThrough(
|
|
217
|
+
new TransformStream({
|
|
218
|
+
transform(chunk, controller) {
|
|
219
|
+
const output = rewriter.write(decoder.decode(chunk, { stream: true }));
|
|
220
|
+
if (output) controller.enqueue(encoder.encode(output));
|
|
221
|
+
},
|
|
222
|
+
flush(controller) {
|
|
223
|
+
const output = rewriter.write(decoder.decode(), true);
|
|
224
|
+
if (output) controller.enqueue(encoder.encode(output));
|
|
225
|
+
}
|
|
226
|
+
})
|
|
227
|
+
);
|
|
228
|
+
return _markFarmOwnedResponse(
|
|
229
|
+
new Response(body, {
|
|
230
|
+
status: response.status,
|
|
231
|
+
statusText: response.statusText,
|
|
232
|
+
headers
|
|
233
|
+
})
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
__name(applyFarmCspNonceToResponse, "applyFarmCspNonceToResponse");
|
|
237
|
+
function farmCspBlocksFrameworkInlineScripts(security) {
|
|
238
|
+
if (!security.csp) return false;
|
|
239
|
+
if (security.csp.nonce) return false;
|
|
240
|
+
const directives = parseCspDirectives(security.csp.value);
|
|
241
|
+
const governing = directives.get("script-src-elem") ?? directives.get("script-src") ?? directives.get("default-src");
|
|
242
|
+
if (!governing) return false;
|
|
243
|
+
const sources = governing.map((source) => source.toLowerCase());
|
|
244
|
+
const disablesUnsafeInline = sources.some(
|
|
245
|
+
(value) => value === "'strict-dynamic'" || value.startsWith("'nonce-") || value.startsWith("'sha256-") || value.startsWith("'sha384-") || value.startsWith("'sha512-")
|
|
246
|
+
);
|
|
247
|
+
return !sources.includes("'unsafe-inline'") || disablesUnsafeInline;
|
|
248
|
+
}
|
|
249
|
+
__name(farmCspBlocksFrameworkInlineScripts, "farmCspBlocksFrameworkInlineScripts");
|
|
250
|
+
function parseCspDirectives(value) {
|
|
251
|
+
const directives = /* @__PURE__ */ new Map();
|
|
252
|
+
for (const segment of value.split(";")) {
|
|
253
|
+
const parts = segment.trim().split(/\s+/).filter(Boolean);
|
|
254
|
+
if (parts.length === 0) continue;
|
|
255
|
+
const name = parts[0].toLowerCase();
|
|
256
|
+
if (!directives.has(name)) directives.set(name, parts.slice(1));
|
|
257
|
+
}
|
|
258
|
+
return directives;
|
|
259
|
+
}
|
|
260
|
+
__name(parseCspDirectives, "parseCspDirectives");
|
|
261
|
+
function normalizeDirectiveName(value) {
|
|
262
|
+
const name = value.trim().replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
263
|
+
if (!/^[a-z][a-z0-9-]*$/.test(name)) {
|
|
264
|
+
throw new TypeError(`Invalid security.csp directive name: ${JSON.stringify(value)}.`);
|
|
265
|
+
}
|
|
266
|
+
return name;
|
|
267
|
+
}
|
|
268
|
+
__name(normalizeDirectiveName, "normalizeDirectiveName");
|
|
269
|
+
function validateDirectiveValue(value) {
|
|
270
|
+
if (typeof value !== "string") {
|
|
271
|
+
throw new TypeError("security.csp directive values must be strings or booleans.");
|
|
272
|
+
}
|
|
273
|
+
const normalized = value.trim();
|
|
274
|
+
if (!normalized || /[;\r\n]/.test(normalized) || normalized.includes("\0")) {
|
|
275
|
+
throw new TypeError(`Invalid security.csp directive value: ${JSON.stringify(value)}.`);
|
|
276
|
+
}
|
|
277
|
+
return normalized;
|
|
278
|
+
}
|
|
279
|
+
__name(validateDirectiveValue, "validateDirectiveValue");
|
|
280
|
+
function validateSerializedCsp(value) {
|
|
281
|
+
if (typeof value !== "string") {
|
|
282
|
+
throw new TypeError("security.csp policy must be a non-empty single-line string.");
|
|
283
|
+
}
|
|
284
|
+
const normalized = value.trim().replace(/;+$/g, "").trim();
|
|
285
|
+
if (!normalized || /[\r\n]/.test(normalized) || normalized.includes("\0")) {
|
|
286
|
+
throw new TypeError("security.csp policy must be a non-empty single-line string.");
|
|
287
|
+
}
|
|
288
|
+
return normalized;
|
|
289
|
+
}
|
|
290
|
+
__name(validateSerializedCsp, "validateSerializedCsp");
|
|
291
|
+
function validateReportOnly(value) {
|
|
292
|
+
if (value === void 0) return false;
|
|
293
|
+
if (typeof value !== "boolean") {
|
|
294
|
+
throw new TypeError("security.csp.reportOnly must be a boolean.");
|
|
295
|
+
}
|
|
296
|
+
return value;
|
|
297
|
+
}
|
|
298
|
+
__name(validateReportOnly, "validateReportOnly");
|
|
299
|
+
function validateNonce(value) {
|
|
300
|
+
if (value === void 0) return false;
|
|
301
|
+
if (typeof value !== "boolean") {
|
|
302
|
+
throw new TypeError("security.csp.nonce must be a boolean.");
|
|
303
|
+
}
|
|
304
|
+
return value;
|
|
305
|
+
}
|
|
306
|
+
__name(validateNonce, "validateNonce");
|
|
307
|
+
function validateCspNonce(value) {
|
|
308
|
+
if (!/^[A-Za-z0-9+/_-]+={0,2}$/.test(value)) {
|
|
309
|
+
throw new TypeError("A CSP nonce must be a base64 or base64url value.");
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
__name(validateCspNonce, "validateCspNonce");
|
|
313
|
+
function createFarmCspNonceRewriter(nonce) {
|
|
314
|
+
validateCspNonce(nonce);
|
|
315
|
+
return createFarmScriptTagRewriter((tag) => keepOwnScriptNonce(tag, nonce));
|
|
316
|
+
}
|
|
317
|
+
__name(createFarmCspNonceRewriter, "createFarmCspNonceRewriter");
|
|
318
|
+
function createFarmScriptTagRewriter(transformScriptTag) {
|
|
319
|
+
let pending = "";
|
|
320
|
+
let rawTextElement;
|
|
321
|
+
return {
|
|
322
|
+
write(chunk, final = false) {
|
|
323
|
+
pending += chunk;
|
|
324
|
+
let output = "";
|
|
325
|
+
while (pending) {
|
|
326
|
+
if (rawTextElement) {
|
|
327
|
+
if (rawTextElement === "plaintext") {
|
|
328
|
+
output += pending;
|
|
329
|
+
pending = "";
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
332
|
+
const closing = `</${rawTextElement}`;
|
|
333
|
+
const start2 = findRawTextEnd(pending, rawTextElement);
|
|
334
|
+
if (start2 === -1) {
|
|
335
|
+
if (final) {
|
|
336
|
+
output += pending;
|
|
337
|
+
pending = "";
|
|
338
|
+
} else {
|
|
339
|
+
const keep = matchingSuffixLength(pending, closing);
|
|
340
|
+
output += pending.slice(0, pending.length - keep);
|
|
341
|
+
pending = pending.slice(pending.length - keep);
|
|
342
|
+
}
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
345
|
+
output += pending.slice(0, start2);
|
|
346
|
+
pending = pending.slice(start2);
|
|
347
|
+
const end2 = findHtmlTagEnd(pending);
|
|
348
|
+
if (end2 === -1) {
|
|
349
|
+
if (final) {
|
|
350
|
+
output += pending;
|
|
351
|
+
pending = "";
|
|
352
|
+
}
|
|
353
|
+
break;
|
|
354
|
+
}
|
|
355
|
+
output += pending.slice(0, end2 + 1);
|
|
356
|
+
pending = pending.slice(end2 + 1);
|
|
357
|
+
rawTextElement = void 0;
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
const start = pending.indexOf("<");
|
|
361
|
+
if (start === -1) {
|
|
362
|
+
output += pending;
|
|
363
|
+
pending = "";
|
|
364
|
+
break;
|
|
365
|
+
}
|
|
366
|
+
output += pending.slice(0, start);
|
|
367
|
+
pending = pending.slice(start);
|
|
368
|
+
if (pending.startsWith("<!--")) {
|
|
369
|
+
const end2 = pending.indexOf("-->", 4);
|
|
370
|
+
if (end2 === -1) {
|
|
371
|
+
if (final) {
|
|
372
|
+
output += pending;
|
|
373
|
+
pending = "";
|
|
374
|
+
}
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
377
|
+
output += pending.slice(0, end2 + 3);
|
|
378
|
+
pending = pending.slice(end2 + 3);
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
if (!final && "<!--".startsWith(pending)) break;
|
|
382
|
+
const tagNameMatch = pending.match(/^<\/?([a-z][a-z0-9:-]*)\b/i);
|
|
383
|
+
if (!tagNameMatch) {
|
|
384
|
+
if (!final && /^<\/?[a-z][a-z0-9:-]*$/i.test(pending)) break;
|
|
385
|
+
output += pending[0];
|
|
386
|
+
pending = pending.slice(1);
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
const end = findHtmlTagEnd(pending);
|
|
390
|
+
if (end === -1) {
|
|
391
|
+
if (!final) break;
|
|
392
|
+
output += pending;
|
|
393
|
+
pending = "";
|
|
394
|
+
break;
|
|
395
|
+
}
|
|
396
|
+
const tag = pending.slice(0, end + 1);
|
|
397
|
+
const tagName = tagNameMatch[1].toLowerCase();
|
|
398
|
+
const isClosing = pending.startsWith("</");
|
|
399
|
+
const isSelfClosing = /\/\s*>$/.test(tag);
|
|
400
|
+
output += !isClosing && tagName === "script" ? transformScriptTag(tag) : tag;
|
|
401
|
+
pending = pending.slice(end + 1);
|
|
402
|
+
if (!isClosing && !isSelfClosing && rawTextElements.has(tagName)) {
|
|
403
|
+
rawTextElement = tagName;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
return output;
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
__name(createFarmScriptTagRewriter, "createFarmScriptTagRewriter");
|
|
411
|
+
var rawTextElements = /* @__PURE__ */ new Map([
|
|
412
|
+
["iframe", /<\/iframe(?=[\s/>]|$)/gi],
|
|
413
|
+
["noembed", /<\/noembed(?=[\s/>]|$)/gi],
|
|
414
|
+
["noframes", /<\/noframes(?=[\s/>]|$)/gi],
|
|
415
|
+
["plaintext", null],
|
|
416
|
+
["script", /<\/script(?=[\s/>]|$)/gi],
|
|
417
|
+
["style", /<\/style(?=[\s/>]|$)/gi],
|
|
418
|
+
["textarea", /<\/textarea(?=[\s/>]|$)/gi],
|
|
419
|
+
["title", /<\/title(?=[\s/>]|$)/gi],
|
|
420
|
+
["xmp", /<\/xmp(?=[\s/>]|$)/gi]
|
|
421
|
+
]);
|
|
422
|
+
function stampScriptTag(tag, nonce) {
|
|
423
|
+
const opening = tag.match(/^<script\b/i)?.[0];
|
|
424
|
+
if (!opening) return tag;
|
|
425
|
+
const attributes = stripScriptNonceAttribute(tag).slice(opening.length, -1);
|
|
426
|
+
return `<script nonce="${nonce}"${attributes}>`;
|
|
427
|
+
}
|
|
428
|
+
__name(stampScriptTag, "stampScriptTag");
|
|
429
|
+
function keepOwnScriptNonce(tag, nonce) {
|
|
430
|
+
const opening = tag.match(/^<script\b/i)?.[0];
|
|
431
|
+
if (!opening) return tag;
|
|
432
|
+
const range = findScriptTagAttributeRange(tag, "nonce");
|
|
433
|
+
if (!range) return tag;
|
|
434
|
+
const stripped = stripScriptNonceAttribute(tag);
|
|
435
|
+
const attributes = stripped.slice(opening.length, -1);
|
|
436
|
+
if (/<(?:script|style)/i.test(attributes)) return stripped;
|
|
437
|
+
if (readAttributeValue(tag.slice(range.start, range.end)) !== nonce) return stripped;
|
|
438
|
+
return `<script nonce="${nonce}"${attributes}>`;
|
|
439
|
+
}
|
|
440
|
+
__name(keepOwnScriptNonce, "keepOwnScriptNonce");
|
|
441
|
+
function readAttributeValue(attribute) {
|
|
442
|
+
const equals = attribute.indexOf("=");
|
|
443
|
+
if (equals === -1) return void 0;
|
|
444
|
+
const value = attribute.slice(equals + 1).trim();
|
|
445
|
+
const quote = value[0];
|
|
446
|
+
if (quote === '"' || quote === "'") {
|
|
447
|
+
return value.length > 1 && value.endsWith(quote) ? value.slice(1, -1) : void 0;
|
|
448
|
+
}
|
|
449
|
+
return value;
|
|
450
|
+
}
|
|
451
|
+
__name(readAttributeValue, "readAttributeValue");
|
|
452
|
+
function stripScriptNonceAttribute(tag) {
|
|
453
|
+
let normalized = tag;
|
|
454
|
+
let range = findScriptTagAttributeRange(normalized, "nonce");
|
|
455
|
+
while (range) {
|
|
456
|
+
normalized = normalized.slice(0, range.start) + normalized.slice(range.end);
|
|
457
|
+
range = findScriptTagAttributeRange(normalized, "nonce");
|
|
458
|
+
}
|
|
459
|
+
return normalized;
|
|
460
|
+
}
|
|
461
|
+
__name(stripScriptNonceAttribute, "stripScriptNonceAttribute");
|
|
462
|
+
function collectFarmInlineScriptContents(html) {
|
|
463
|
+
const contents = [];
|
|
464
|
+
let offset = 0;
|
|
465
|
+
while (offset < html.length) {
|
|
466
|
+
const start = html.indexOf("<", offset);
|
|
467
|
+
if (start === -1) break;
|
|
468
|
+
if (html.startsWith("<!--", start)) {
|
|
469
|
+
const commentEnd = html.indexOf("-->", start + 4);
|
|
470
|
+
offset = commentEnd === -1 ? html.length : commentEnd + 3;
|
|
471
|
+
continue;
|
|
472
|
+
}
|
|
473
|
+
const remaining = html.slice(start);
|
|
474
|
+
const tagNameMatch = remaining.match(/^<\/?([a-z][a-z0-9:-]*)\b/i);
|
|
475
|
+
if (!tagNameMatch) {
|
|
476
|
+
offset = start + 1;
|
|
477
|
+
continue;
|
|
478
|
+
}
|
|
479
|
+
const tagEnd = findHtmlTagEnd(remaining);
|
|
480
|
+
if (tagEnd === -1) break;
|
|
481
|
+
const tag = remaining.slice(0, tagEnd + 1);
|
|
482
|
+
const tagName = tagNameMatch[1].toLowerCase();
|
|
483
|
+
const isClosing = remaining.startsWith("</");
|
|
484
|
+
const isSelfClosing = /\/\s*>$/.test(tag);
|
|
485
|
+
offset = start + tagEnd + 1;
|
|
486
|
+
if (isClosing || isSelfClosing || !rawTextElements.has(tagName)) continue;
|
|
487
|
+
if (tagName === "plaintext") break;
|
|
488
|
+
const closingStart = findRawTextEnd(html, tagName, offset);
|
|
489
|
+
const contentEnd = closingStart === -1 ? html.length : closingStart;
|
|
490
|
+
if (tagName === "script" && findScriptTagAttributeRange(tag, "nonce") && !findScriptTagAttributeRange(tag, "src")) {
|
|
491
|
+
contents.push(html.slice(offset, contentEnd));
|
|
492
|
+
}
|
|
493
|
+
if (closingStart === -1) break;
|
|
494
|
+
const closingEnd = findHtmlTagEnd(html.slice(contentEnd));
|
|
495
|
+
if (closingEnd === -1) break;
|
|
496
|
+
offset = contentEnd + closingEnd + 1;
|
|
497
|
+
}
|
|
498
|
+
return contents;
|
|
499
|
+
}
|
|
500
|
+
__name(collectFarmInlineScriptContents, "collectFarmInlineScriptContents");
|
|
501
|
+
function findScriptTagAttributeRange(tag, expectedName) {
|
|
502
|
+
const opening = tag.match(/^<script\b/i)?.[0];
|
|
503
|
+
if (!opening) return void 0;
|
|
504
|
+
let offset = opening.length;
|
|
505
|
+
while (offset < tag.length - 1) {
|
|
506
|
+
const whitespaceStart = offset;
|
|
507
|
+
while (/\s/.test(tag[offset] || "")) offset++;
|
|
508
|
+
if (tag[offset] === "/" || tag[offset] === ">" || offset >= tag.length - 1) break;
|
|
509
|
+
const nameStart = offset;
|
|
510
|
+
while (offset < tag.length && !/[\s=/>]/.test(tag[offset])) offset++;
|
|
511
|
+
const name = tag.slice(nameStart, offset).toLowerCase();
|
|
512
|
+
while (/\s/.test(tag[offset] || "")) offset++;
|
|
513
|
+
if (tag[offset] === "=") {
|
|
514
|
+
offset++;
|
|
515
|
+
while (/\s/.test(tag[offset] || "")) offset++;
|
|
516
|
+
const quote = tag[offset] === '"' || tag[offset] === "'" ? tag[offset++] : void 0;
|
|
517
|
+
if (quote) {
|
|
518
|
+
while (offset < tag.length && tag[offset] !== quote) offset++;
|
|
519
|
+
if (tag[offset] === quote) offset++;
|
|
520
|
+
} else {
|
|
521
|
+
while (offset < tag.length && !/[\s>]/.test(tag[offset])) offset++;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
if (name === expectedName) return { start: whitespaceStart, end: offset };
|
|
525
|
+
}
|
|
526
|
+
return void 0;
|
|
527
|
+
}
|
|
528
|
+
__name(findScriptTagAttributeRange, "findScriptTagAttributeRange");
|
|
529
|
+
function findRawTextEnd(input, tagName, offset = 0) {
|
|
530
|
+
const closing = rawTextElements.get(tagName);
|
|
531
|
+
closing.lastIndex = offset;
|
|
532
|
+
return closing.exec(input)?.index ?? -1;
|
|
533
|
+
}
|
|
534
|
+
__name(findRawTextEnd, "findRawTextEnd");
|
|
535
|
+
function matchingSuffixLength(input, token) {
|
|
536
|
+
const limit = Math.min(token.length - 1, input.length);
|
|
537
|
+
for (let length = limit; length > 0; length--) {
|
|
538
|
+
if (token.startsWith(input.slice(-length).toLowerCase())) return length;
|
|
539
|
+
}
|
|
540
|
+
return 0;
|
|
541
|
+
}
|
|
542
|
+
__name(matchingSuffixLength, "matchingSuffixLength");
|
|
543
|
+
function findHtmlTagEnd(tag) {
|
|
544
|
+
let quote;
|
|
545
|
+
for (let index = 1; index < tag.length; index++) {
|
|
546
|
+
const character = tag[index];
|
|
547
|
+
if (quote) {
|
|
548
|
+
if (character === quote) quote = void 0;
|
|
549
|
+
} else if (character === '"' || character === "'") {
|
|
550
|
+
quote = character;
|
|
551
|
+
} else if (character === ">") {
|
|
552
|
+
return index;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
return -1;
|
|
556
|
+
}
|
|
557
|
+
__name(findHtmlTagEnd, "findHtmlTagEnd");
|
|
558
|
+
function isPlainRecord(value) {
|
|
559
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
560
|
+
const prototype = Object.getPrototypeOf(value);
|
|
561
|
+
return prototype === Object.prototype || prototype === null;
|
|
562
|
+
}
|
|
563
|
+
__name(isPlainRecord, "isPlainRecord");
|
|
564
|
+
|
|
565
|
+
export {
|
|
566
|
+
resolveFarmSecurityConfig,
|
|
567
|
+
getFarmSecurityHeader,
|
|
568
|
+
createFarmCspNonce,
|
|
569
|
+
stampFarmCspNonce,
|
|
570
|
+
replaceFarmCspNonceMarker,
|
|
571
|
+
filterFarmCspNonces,
|
|
572
|
+
applyFarmCspHashesToHtml,
|
|
573
|
+
applyFarmCspNonceToResponse,
|
|
574
|
+
farmCspBlocksFrameworkInlineScripts,
|
|
575
|
+
createFarmCspNonceRewriter
|
|
576
|
+
};
|
|
@@ -4,6 +4,7 @@ var _chunkS3JO3N4Hcjs = require('./chunk-S3JO3N4H.cjs');
|
|
|
4
4
|
|
|
5
5
|
// src/server/request-bridge.ts
|
|
6
6
|
var CURRENT_REQUEST_RESOLVER_KEY = /* @__PURE__ */ Symbol.for("farm.currentRequestResolver");
|
|
7
|
+
var APP_REQUEST_VIEW_KEY = /* @__PURE__ */ Symbol.for("farm.appRequestView");
|
|
7
8
|
function getGlobalState() {
|
|
8
9
|
return globalThis;
|
|
9
10
|
}
|
|
@@ -16,8 +17,32 @@ function _resolveCurrentRequest() {
|
|
|
16
17
|
return _optionalChain([getGlobalState, 'call', _ => _(), 'access', _2 => _2[CURRENT_REQUEST_RESOLVER_KEY], 'optionalCall', _3 => _3()]);
|
|
17
18
|
}
|
|
18
19
|
_chunkS3JO3N4Hcjs.__name.call(void 0, _resolveCurrentRequest, "_resolveCurrentRequest");
|
|
20
|
+
function _setAppRequestView(view) {
|
|
21
|
+
getGlobalState()[APP_REQUEST_VIEW_KEY] = view;
|
|
22
|
+
}
|
|
23
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, _setAppRequestView, "_setAppRequestView");
|
|
24
|
+
function _resolveCurrentRequestForApp() {
|
|
25
|
+
const request = _resolveCurrentRequest();
|
|
26
|
+
const view = getGlobalState()[APP_REQUEST_VIEW_KEY];
|
|
27
|
+
return request && view ? view(request) : request;
|
|
28
|
+
}
|
|
29
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, _resolveCurrentRequestForApp, "_resolveCurrentRequestForApp");
|
|
30
|
+
var CSP_NONCE_RESOLVER_KEY = /* @__PURE__ */ Symbol.for("farm.cspNonceResolver");
|
|
31
|
+
function _setCspNonceResolver(resolver) {
|
|
32
|
+
globalThis[CSP_NONCE_RESOLVER_KEY] = resolver;
|
|
33
|
+
}
|
|
34
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, _setCspNonceResolver, "_setCspNonceResolver");
|
|
35
|
+
function _resolveCurrentCspNonce() {
|
|
36
|
+
const resolver = globalThis[CSP_NONCE_RESOLVER_KEY];
|
|
37
|
+
return _optionalChain([resolver, 'optionalCall', _4 => _4()]);
|
|
38
|
+
}
|
|
39
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, _resolveCurrentCspNonce, "_resolveCurrentCspNonce");
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
19
44
|
|
|
20
45
|
|
|
21
46
|
|
|
22
47
|
|
|
23
|
-
exports._setCurrentRequestResolver = _setCurrentRequestResolver; exports._resolveCurrentRequest = _resolveCurrentRequest;
|
|
48
|
+
exports._setCurrentRequestResolver = _setCurrentRequestResolver; exports._resolveCurrentRequest = _resolveCurrentRequest; exports._setAppRequestView = _setAppRequestView; exports._resolveCurrentRequestForApp = _resolveCurrentRequestForApp; exports._setCspNonceResolver = _setCspNonceResolver; exports._resolveCurrentCspNonce = _resolveCurrentCspNonce;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _chunkS3JO3N4Hcjs = require('./chunk-S3JO3N4H.cjs');
|
|
4
|
+
|
|
5
|
+
// src/api/dev-dispatch.ts
|
|
6
|
+
var _http = require('http'); var _http2 = _interopRequireDefault(_http);
|
|
7
|
+
var _https = require('https'); var _https2 = _interopRequireDefault(_https);
|
|
8
|
+
var _stream = require('stream');
|
|
9
|
+
function createFarmDevServerDispatch(server) {
|
|
10
|
+
return (request) => new Promise((resolve, reject) => {
|
|
11
|
+
const address = _optionalChain([server, 'access', _ => _.httpServer, 'optionalAccess', _2 => _2.address, 'call', _3 => _3()]);
|
|
12
|
+
if (!address || typeof address === "string") {
|
|
13
|
+
throw new Error(
|
|
14
|
+
"Farm cannot dispatch an app endpoint request: the Vite dev server has no listening HTTP server."
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
const url = new URL(request.url);
|
|
18
|
+
const headers = {};
|
|
19
|
+
request.headers.forEach((value, name) => {
|
|
20
|
+
headers[name] = value;
|
|
21
|
+
});
|
|
22
|
+
headers.host = url.host;
|
|
23
|
+
const secure = Boolean(server.config.server.https);
|
|
24
|
+
const outgoing = (secure ? _https2.default : _http2.default).request(
|
|
25
|
+
{
|
|
26
|
+
host: loopbackAddress(address),
|
|
27
|
+
port: address.port,
|
|
28
|
+
method: request.method,
|
|
29
|
+
path: `${url.pathname}${url.search}`,
|
|
30
|
+
headers,
|
|
31
|
+
signal: request.signal,
|
|
32
|
+
// The listener is this process's own dev server, often with a self-signed certificate.
|
|
33
|
+
...secure ? { rejectUnauthorized: false } : {}
|
|
34
|
+
},
|
|
35
|
+
(incoming) => {
|
|
36
|
+
const responseHeaders = new Headers();
|
|
37
|
+
for (const [name, value] of Object.entries(incoming.headers)) {
|
|
38
|
+
if (value === void 0) continue;
|
|
39
|
+
for (const entry of Array.isArray(value) ? value : [value]) {
|
|
40
|
+
responseHeaders.append(name, entry);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const status = _nullishCoalesce(incoming.statusCode, () => ( 502));
|
|
44
|
+
const hasBody = request.method !== "HEAD" && status !== 204 && status !== 205 && status !== 304;
|
|
45
|
+
if (!hasBody) incoming.resume();
|
|
46
|
+
try {
|
|
47
|
+
resolve(
|
|
48
|
+
new Response(
|
|
49
|
+
hasBody ? _stream.Readable.toWeb(incoming) : null,
|
|
50
|
+
{ status, statusText: incoming.statusMessage, headers: responseHeaders }
|
|
51
|
+
)
|
|
52
|
+
);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
incoming.destroy();
|
|
55
|
+
reject(error);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
outgoing.on("error", reject);
|
|
60
|
+
if (request.body) {
|
|
61
|
+
_stream.Readable.fromWeb(request.body).on("error", (error) => outgoing.destroy(error)).pipe(outgoing);
|
|
62
|
+
} else {
|
|
63
|
+
outgoing.end();
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, createFarmDevServerDispatch, "createFarmDevServerDispatch");
|
|
68
|
+
function loopbackAddress({ address }) {
|
|
69
|
+
return address === "0.0.0.0" ? "127.0.0.1" : address === "::" ? "::1" : address;
|
|
70
|
+
}
|
|
71
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, loopbackAddress, "loopbackAddress");
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
exports.createFarmDevServerDispatch = createFarmDevServerDispatch;
|