@eidos.space/just-bash 3.0.2
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 +53 -0
- package/LICENSE +201 -0
- package/README.md +609 -0
- package/dist/AGENTS.md +325 -0
- package/dist/Bash.d.ts +257 -0
- package/dist/ast/types.d.ts +609 -0
- package/dist/banned-patterns-test.d.ts +1 -0
- package/dist/bin/chunks/alias-YRVAW27Y.js +3 -0
- package/dist/bin/chunks/awk2-RLMNTGI7.js +3 -0
- package/dist/bin/chunks/base64-RZRLGMB3.js +3 -0
- package/dist/bin/chunks/basename-F3AQ4KAQ.js +3 -0
- package/dist/bin/chunks/bash-CLP24TE2.js +3 -0
- package/dist/bin/chunks/cat-LQH5FSAR.js +3 -0
- package/dist/bin/chunks/chmod-S564JCJW.js +3 -0
- package/dist/bin/chunks/chunk-22HCD466.js +3 -0
- package/dist/bin/chunks/chunk-2AIXTPH2.js +9 -0
- package/dist/bin/chunks/chunk-2ETT4ELS.js +4 -0
- package/dist/bin/chunks/chunk-2GG3NVC4.js +10 -0
- package/dist/bin/chunks/chunk-2NRAWO6E.js +7 -0
- package/dist/bin/chunks/chunk-2SVX7I5P.js +14 -0
- package/dist/bin/chunks/chunk-3BYTCO2H.js +12 -0
- package/dist/bin/chunks/chunk-3MRB66F4.js +3 -0
- package/dist/bin/chunks/chunk-3UKQXBQ3.js +6 -0
- package/dist/bin/chunks/chunk-3WIMLJM7.js +8 -0
- package/dist/bin/chunks/chunk-47WZ2U6M.js +9 -0
- package/dist/bin/chunks/chunk-4KSZJAQK.js +6 -0
- package/dist/bin/chunks/chunk-5XSZHUEI.js +15 -0
- package/dist/bin/chunks/chunk-6FSBHK6H.js +22 -0
- package/dist/bin/chunks/chunk-6WJQNLR2.js +7 -0
- package/dist/bin/chunks/chunk-77MLOOQS.js +11 -0
- package/dist/bin/chunks/chunk-7AYT3UKI.js +6 -0
- package/dist/bin/chunks/chunk-7JZKVC3F.js +2 -0
- package/dist/bin/chunks/chunk-7NC4CPHS.js +20 -0
- package/dist/bin/chunks/chunk-7UU7KPEM.js +7 -0
- package/dist/bin/chunks/chunk-7VCQWCSH.js +15 -0
- package/dist/bin/chunks/chunk-AGKL4LDL.js +4 -0
- package/dist/bin/chunks/chunk-AJF3OBTR.js +4 -0
- package/dist/bin/chunks/chunk-ALVEEXFD.js +19 -0
- package/dist/bin/chunks/chunk-B2DRBHGQ.js +3 -0
- package/dist/bin/chunks/chunk-BE4PARL3.js +13 -0
- package/dist/bin/chunks/chunk-BGX3RW7H.js +10 -0
- package/dist/bin/chunks/chunk-BIJXTWZ4.js +3 -0
- package/dist/bin/chunks/chunk-BPZJYOUA.js +33 -0
- package/dist/bin/chunks/chunk-BZP56QBM.js +24 -0
- package/dist/bin/chunks/chunk-C7ISPH7Y.js +18 -0
- package/dist/bin/chunks/chunk-CAZ75E7E.js +3 -0
- package/dist/bin/chunks/chunk-D6CPXGKK.js +75 -0
- package/dist/bin/chunks/chunk-DJAX3ZRG.js +8 -0
- package/dist/bin/chunks/chunk-DYIBFLS3.js +17 -0
- package/dist/bin/chunks/chunk-EDTBGO7F.js +37 -0
- package/dist/bin/chunks/chunk-F3GKANW3.js +12 -0
- package/dist/bin/chunks/chunk-F3WNDKOC.js +3 -0
- package/dist/bin/chunks/chunk-FKVQZWJQ.js +10 -0
- package/dist/bin/chunks/chunk-FOUVACI7.js +16 -0
- package/dist/bin/chunks/chunk-FVRXEJYQ.js +141 -0
- package/dist/bin/chunks/chunk-G4AUMZUY.js +4 -0
- package/dist/bin/chunks/chunk-H7JTIXAO.js +4 -0
- package/dist/bin/chunks/chunk-HL4ZS7TX.js +6 -0
- package/dist/bin/chunks/chunk-HN2DCT7T.js +13 -0
- package/dist/bin/chunks/chunk-I4IRHQDW.js +3 -0
- package/dist/bin/chunks/chunk-IEXQTXU5.js +34 -0
- package/dist/bin/chunks/chunk-IZGLHVBB.js +8 -0
- package/dist/bin/chunks/chunk-J7TUF2VI.js +9 -0
- package/dist/bin/chunks/chunk-JNUX75OX.js +85 -0
- package/dist/bin/chunks/chunk-JXLDT4KX.js +4 -0
- package/dist/bin/chunks/chunk-JZW7NFK2.js +288 -0
- package/dist/bin/chunks/chunk-KFMPGSUT.js +9 -0
- package/dist/bin/chunks/chunk-KI54R2QB.js +3 -0
- package/dist/bin/chunks/chunk-KRRM5UCC.js +3 -0
- package/dist/bin/chunks/chunk-KUMHQGUR.js +3 -0
- package/dist/bin/chunks/chunk-L24QXM5S.js +34 -0
- package/dist/bin/chunks/chunk-LAHBP3FW.js +11 -0
- package/dist/bin/chunks/chunk-LC6D27QJ.js +3 -0
- package/dist/bin/chunks/chunk-LNNWMRCB.js +3 -0
- package/dist/bin/chunks/chunk-LNVSXNT7.js +3 -0
- package/dist/bin/chunks/chunk-LSQTB2QK.js +7 -0
- package/dist/bin/chunks/chunk-M65CQLJE.js +101 -0
- package/dist/bin/chunks/chunk-MLUOPG3W.js +3 -0
- package/dist/bin/chunks/chunk-MNWK4UIM.js +22 -0
- package/dist/bin/chunks/chunk-MROECM42.js +3 -0
- package/dist/bin/chunks/chunk-MUFNRCMY.js +24 -0
- package/dist/bin/chunks/chunk-N6YW4W3Z.js +29 -0
- package/dist/bin/chunks/chunk-NE4R2FVV.js +5 -0
- package/dist/bin/chunks/chunk-NXVG64T3.js +22 -0
- package/dist/bin/chunks/chunk-NYIPFY36.js +3 -0
- package/dist/bin/chunks/chunk-O2BCKSMK.js +3 -0
- package/dist/bin/chunks/chunk-OLEQNRKX.js +8 -0
- package/dist/bin/chunks/chunk-OPMLWMNH.js +17 -0
- package/dist/bin/chunks/chunk-PAYQNSZN.js +18 -0
- package/dist/bin/chunks/chunk-PBOVSFTJ.js +3 -0
- package/dist/bin/chunks/chunk-PXP4YYZA.js +13 -0
- package/dist/bin/chunks/chunk-PZQVSQX6.js +4 -0
- package/dist/bin/chunks/chunk-Q2GOPGDA.js +6 -0
- package/dist/bin/chunks/chunk-Q4UMTSRO.js +15 -0
- package/dist/bin/chunks/chunk-QL33F2W6.js +8 -0
- package/dist/bin/chunks/chunk-RVPTAYDS.js +4 -0
- package/dist/bin/chunks/chunk-SMSELHIY.js +12 -0
- package/dist/bin/chunks/chunk-UGJM7CKP.js +17 -0
- package/dist/bin/chunks/chunk-UO5LOD7U.js +12 -0
- package/dist/bin/chunks/chunk-UOMNSQEZ.js +10 -0
- package/dist/bin/chunks/chunk-UR4CEP4Y.js +3 -0
- package/dist/bin/chunks/chunk-V2RP73X4.js +15 -0
- package/dist/bin/chunks/chunk-VBDLSL7Y.js +10 -0
- package/dist/bin/chunks/chunk-VZK4FHWJ.js +3 -0
- package/dist/bin/chunks/chunk-WDWNEHHE.js +9 -0
- package/dist/bin/chunks/chunk-X4MX6EHF.js +6 -0
- package/dist/bin/chunks/chunk-XBB73LFB.js +5 -0
- package/dist/bin/chunks/chunk-XFFUAO3F.js +3 -0
- package/dist/bin/chunks/chunk-XHCCSVP6.js +9 -0
- package/dist/bin/chunks/chunk-XJ37N3S5.js +7 -0
- package/dist/bin/chunks/chunk-XPTYN6UE.js +8 -0
- package/dist/bin/chunks/chunk-XRUDFQG5.js +7 -0
- package/dist/bin/chunks/chunk-Y4FPH5DQ.js +64 -0
- package/dist/bin/chunks/chunk-YJ5OCPSK.js +7 -0
- package/dist/bin/chunks/chunk-YOIFOOGX.js +9 -0
- package/dist/bin/chunks/chunk-YOKQNNQO.js +6 -0
- package/dist/bin/chunks/chunk-YUZRUF5F.js +10 -0
- package/dist/bin/chunks/chunk-YY5PJR7O.js +7 -0
- package/dist/bin/chunks/chunk-ZFUVUYWG.js +15 -0
- package/dist/bin/chunks/clear-FGNEKYDU.js +3 -0
- package/dist/bin/chunks/column-AQB3A3PJ.js +3 -0
- package/dist/bin/chunks/comm-Q4VDF6ZO.js +3 -0
- package/dist/bin/chunks/cp-HYXTMN3D.js +3 -0
- package/dist/bin/chunks/curl-PLHETP4J.js +27 -0
- package/dist/bin/chunks/cut-ZI2HIAW7.js +3 -0
- package/dist/bin/chunks/date-JEZYSA4F.js +3 -0
- package/dist/bin/chunks/diff-YDJ42RKS.js +3 -0
- package/dist/bin/chunks/dirname-VCINTLPD.js +3 -0
- package/dist/bin/chunks/du-4LRQIGRG.js +3 -0
- package/dist/bin/chunks/echo-KCOHTNDF.js +3 -0
- package/dist/bin/chunks/env-NY32PQJM.js +3 -0
- package/dist/bin/chunks/expand-YYSO35NS.js +3 -0
- package/dist/bin/chunks/expansion-PPP6PD75.js +3 -0
- package/dist/bin/chunks/expr-7PLWSWZI.js +3 -0
- package/dist/bin/chunks/file-GRZLWDVH.js +3 -0
- package/dist/bin/chunks/find-P4DOE7CE.js +3 -0
- package/dist/bin/chunks/flag-coverage-RFKIBJ6L.js +3 -0
- package/dist/bin/chunks/fold-5MF7QZWQ.js +3 -0
- package/dist/bin/chunks/grep-VAYCFO4O.js +3 -0
- package/dist/bin/chunks/gzip-UGBQQKIH.js +3 -0
- package/dist/bin/chunks/head-QNC2ZYDO.js +3 -0
- package/dist/bin/chunks/help-CGUEOGXQ.js +3 -0
- package/dist/bin/chunks/history-AQQWW3QB.js +3 -0
- package/dist/bin/chunks/hostname-USNWOQCK.js +3 -0
- package/dist/bin/chunks/html-to-markdown-QEFY7XQR.js +3 -0
- package/dist/bin/chunks/join-EJ73DYTK.js +3 -0
- package/dist/bin/chunks/jq-GGTKKMEN.js +3 -0
- package/dist/bin/chunks/js-exec-BC6NI55L.js +98 -0
- package/dist/bin/chunks/js-exec-worker.js +4443 -0
- package/dist/bin/chunks/ln-LP4HMCSM.js +3 -0
- package/dist/bin/chunks/ls-KBNHNZWQ.js +3 -0
- package/dist/bin/chunks/md5sum-MCVDIB35.js +3 -0
- package/dist/bin/chunks/mkdir-P4DKRCDX.js +3 -0
- package/dist/bin/chunks/mv-QQK4FQX6.js +3 -0
- package/dist/bin/chunks/nl-KUPLVCTS.js +3 -0
- package/dist/bin/chunks/od-YQ5ZUI2H.js +3 -0
- package/dist/bin/chunks/paste-A5KKPWXX.js +3 -0
- package/dist/bin/chunks/printf-Z5C2UOI5.js +3 -0
- package/dist/bin/chunks/pwd-FCNDA467.js +3 -0
- package/dist/bin/chunks/python3-BQWDPUBM.js +13 -0
- package/dist/bin/chunks/readlink-25V57VOL.js +3 -0
- package/dist/bin/chunks/rev-PYHOZ4D4.js +3 -0
- package/dist/bin/chunks/rg-BGFMSIVK.js +3 -0
- package/dist/bin/chunks/rm-ECNUFR66.js +3 -0
- package/dist/bin/chunks/rmdir-DLOHIA7Q.js +3 -0
- package/dist/bin/chunks/sed-FWA634SN.js +3 -0
- package/dist/bin/chunks/seq-UXDJE6FB.js +3 -0
- package/dist/bin/chunks/sha1sum-4KF52U3Y.js +3 -0
- package/dist/bin/chunks/sha256sum-6YEPULPX.js +3 -0
- package/dist/bin/chunks/sleep-QHAPNY3Q.js +3 -0
- package/dist/bin/chunks/sort-4C6WOKNK.js +3 -0
- package/dist/bin/chunks/split-TV7NL7LA.js +3 -0
- package/dist/bin/chunks/sqlite3-W777NCI4.js +3 -0
- package/dist/bin/chunks/sqlite3-worker.js +1728 -0
- package/dist/bin/chunks/stat-BD6KT3BP.js +3 -0
- package/dist/bin/chunks/strings-MDD72LR6.js +3 -0
- package/dist/bin/chunks/tac-C2N4NQ6S.js +3 -0
- package/dist/bin/chunks/tail-BCB5W6JC.js +3 -0
- package/dist/bin/chunks/tar-DOO744MK.js +3 -0
- package/dist/bin/chunks/tee-UQHPO4OW.js +3 -0
- package/dist/bin/chunks/time-ZPY52VT2.js +3 -0
- package/dist/bin/chunks/timeout-5AX3ZS3X.js +3 -0
- package/dist/bin/chunks/touch-DFGSVIX7.js +3 -0
- package/dist/bin/chunks/tr-G7K6M6HP.js +3 -0
- package/dist/bin/chunks/tree-6D7SMPUR.js +3 -0
- package/dist/bin/chunks/true-SKL4L7JP.js +3 -0
- package/dist/bin/chunks/unexpand-QIR4EDPG.js +3 -0
- package/dist/bin/chunks/uniq-I7PVFJR4.js +3 -0
- package/dist/bin/chunks/wc-6NGWULAP.js +3 -0
- package/dist/bin/chunks/which-LCXKCLFC.js +3 -0
- package/dist/bin/chunks/whoami-TZDZDU7T.js +3 -0
- package/dist/bin/chunks/worker.js +3150 -0
- package/dist/bin/chunks/xan-KX4VPXUN.js +3 -0
- package/dist/bin/chunks/xan-view-JXOZLJ7S.js +3 -0
- package/dist/bin/chunks/xargs-UWHPYLY7.js +3 -0
- package/dist/bin/chunks/yq-GCDCJBKB.js +3 -0
- package/dist/bin/just-bash.js +755 -0
- package/dist/bin/shell/chunks/alias-YRVAW27Y.js +3 -0
- package/dist/bin/shell/chunks/awk2-RLMNTGI7.js +3 -0
- package/dist/bin/shell/chunks/base64-RZRLGMB3.js +3 -0
- package/dist/bin/shell/chunks/basename-F3AQ4KAQ.js +3 -0
- package/dist/bin/shell/chunks/bash-CLP24TE2.js +3 -0
- package/dist/bin/shell/chunks/cat-LQH5FSAR.js +3 -0
- package/dist/bin/shell/chunks/chmod-S564JCJW.js +3 -0
- package/dist/bin/shell/chunks/chunk-22HCD466.js +3 -0
- package/dist/bin/shell/chunks/chunk-2AIXTPH2.js +9 -0
- package/dist/bin/shell/chunks/chunk-2ETT4ELS.js +4 -0
- package/dist/bin/shell/chunks/chunk-2GG3NVC4.js +10 -0
- package/dist/bin/shell/chunks/chunk-2NRAWO6E.js +7 -0
- package/dist/bin/shell/chunks/chunk-2SVX7I5P.js +14 -0
- package/dist/bin/shell/chunks/chunk-3BYTCO2H.js +12 -0
- package/dist/bin/shell/chunks/chunk-3MRB66F4.js +3 -0
- package/dist/bin/shell/chunks/chunk-3UKQXBQ3.js +6 -0
- package/dist/bin/shell/chunks/chunk-3WIMLJM7.js +8 -0
- package/dist/bin/shell/chunks/chunk-47WZ2U6M.js +9 -0
- package/dist/bin/shell/chunks/chunk-4KSZJAQK.js +6 -0
- package/dist/bin/shell/chunks/chunk-5XSZHUEI.js +15 -0
- package/dist/bin/shell/chunks/chunk-6FSBHK6H.js +22 -0
- package/dist/bin/shell/chunks/chunk-6WJQNLR2.js +7 -0
- package/dist/bin/shell/chunks/chunk-77MLOOQS.js +11 -0
- package/dist/bin/shell/chunks/chunk-7AYT3UKI.js +6 -0
- package/dist/bin/shell/chunks/chunk-7JZKVC3F.js +2 -0
- package/dist/bin/shell/chunks/chunk-7NC4CPHS.js +20 -0
- package/dist/bin/shell/chunks/chunk-7UU7KPEM.js +7 -0
- package/dist/bin/shell/chunks/chunk-7VCQWCSH.js +15 -0
- package/dist/bin/shell/chunks/chunk-AGKL4LDL.js +4 -0
- package/dist/bin/shell/chunks/chunk-AJF3OBTR.js +4 -0
- package/dist/bin/shell/chunks/chunk-ALVEEXFD.js +19 -0
- package/dist/bin/shell/chunks/chunk-B2DRBHGQ.js +3 -0
- package/dist/bin/shell/chunks/chunk-BE4PARL3.js +13 -0
- package/dist/bin/shell/chunks/chunk-BGX3RW7H.js +10 -0
- package/dist/bin/shell/chunks/chunk-BIJXTWZ4.js +3 -0
- package/dist/bin/shell/chunks/chunk-BPZJYOUA.js +33 -0
- package/dist/bin/shell/chunks/chunk-BZP56QBM.js +24 -0
- package/dist/bin/shell/chunks/chunk-C7ISPH7Y.js +18 -0
- package/dist/bin/shell/chunks/chunk-CAZ75E7E.js +3 -0
- package/dist/bin/shell/chunks/chunk-D6CPXGKK.js +75 -0
- package/dist/bin/shell/chunks/chunk-DJAX3ZRG.js +8 -0
- package/dist/bin/shell/chunks/chunk-DYIBFLS3.js +17 -0
- package/dist/bin/shell/chunks/chunk-EDTBGO7F.js +37 -0
- package/dist/bin/shell/chunks/chunk-F3GKANW3.js +12 -0
- package/dist/bin/shell/chunks/chunk-F3WNDKOC.js +3 -0
- package/dist/bin/shell/chunks/chunk-FKVQZWJQ.js +10 -0
- package/dist/bin/shell/chunks/chunk-FOUVACI7.js +16 -0
- package/dist/bin/shell/chunks/chunk-FVRXEJYQ.js +141 -0
- package/dist/bin/shell/chunks/chunk-G4AUMZUY.js +4 -0
- package/dist/bin/shell/chunks/chunk-H7JTIXAO.js +4 -0
- package/dist/bin/shell/chunks/chunk-HL4ZS7TX.js +6 -0
- package/dist/bin/shell/chunks/chunk-HN2DCT7T.js +13 -0
- package/dist/bin/shell/chunks/chunk-I4IRHQDW.js +3 -0
- package/dist/bin/shell/chunks/chunk-IEXQTXU5.js +34 -0
- package/dist/bin/shell/chunks/chunk-IZGLHVBB.js +8 -0
- package/dist/bin/shell/chunks/chunk-J7TUF2VI.js +9 -0
- package/dist/bin/shell/chunks/chunk-JNUX75OX.js +85 -0
- package/dist/bin/shell/chunks/chunk-JXLDT4KX.js +4 -0
- package/dist/bin/shell/chunks/chunk-JZW7NFK2.js +288 -0
- package/dist/bin/shell/chunks/chunk-KFMPGSUT.js +9 -0
- package/dist/bin/shell/chunks/chunk-KI54R2QB.js +3 -0
- package/dist/bin/shell/chunks/chunk-KRRM5UCC.js +3 -0
- package/dist/bin/shell/chunks/chunk-KUMHQGUR.js +3 -0
- package/dist/bin/shell/chunks/chunk-L24QXM5S.js +34 -0
- package/dist/bin/shell/chunks/chunk-LAHBP3FW.js +11 -0
- package/dist/bin/shell/chunks/chunk-LC6D27QJ.js +3 -0
- package/dist/bin/shell/chunks/chunk-LNNWMRCB.js +3 -0
- package/dist/bin/shell/chunks/chunk-LNVSXNT7.js +3 -0
- package/dist/bin/shell/chunks/chunk-LSQTB2QK.js +7 -0
- package/dist/bin/shell/chunks/chunk-M65CQLJE.js +101 -0
- package/dist/bin/shell/chunks/chunk-MLUOPG3W.js +3 -0
- package/dist/bin/shell/chunks/chunk-MNWK4UIM.js +22 -0
- package/dist/bin/shell/chunks/chunk-MROECM42.js +3 -0
- package/dist/bin/shell/chunks/chunk-MUFNRCMY.js +24 -0
- package/dist/bin/shell/chunks/chunk-N6YW4W3Z.js +29 -0
- package/dist/bin/shell/chunks/chunk-NE4R2FVV.js +5 -0
- package/dist/bin/shell/chunks/chunk-NXVG64T3.js +22 -0
- package/dist/bin/shell/chunks/chunk-NYIPFY36.js +3 -0
- package/dist/bin/shell/chunks/chunk-O2BCKSMK.js +3 -0
- package/dist/bin/shell/chunks/chunk-OLEQNRKX.js +8 -0
- package/dist/bin/shell/chunks/chunk-OPMLWMNH.js +17 -0
- package/dist/bin/shell/chunks/chunk-PAYQNSZN.js +18 -0
- package/dist/bin/shell/chunks/chunk-PBOVSFTJ.js +3 -0
- package/dist/bin/shell/chunks/chunk-PXP4YYZA.js +13 -0
- package/dist/bin/shell/chunks/chunk-PZQVSQX6.js +4 -0
- package/dist/bin/shell/chunks/chunk-Q2GOPGDA.js +6 -0
- package/dist/bin/shell/chunks/chunk-Q4UMTSRO.js +15 -0
- package/dist/bin/shell/chunks/chunk-QL33F2W6.js +8 -0
- package/dist/bin/shell/chunks/chunk-RVPTAYDS.js +4 -0
- package/dist/bin/shell/chunks/chunk-SMSELHIY.js +12 -0
- package/dist/bin/shell/chunks/chunk-UGJM7CKP.js +17 -0
- package/dist/bin/shell/chunks/chunk-UO5LOD7U.js +12 -0
- package/dist/bin/shell/chunks/chunk-UOMNSQEZ.js +10 -0
- package/dist/bin/shell/chunks/chunk-UR4CEP4Y.js +3 -0
- package/dist/bin/shell/chunks/chunk-V2RP73X4.js +15 -0
- package/dist/bin/shell/chunks/chunk-VBDLSL7Y.js +10 -0
- package/dist/bin/shell/chunks/chunk-VZK4FHWJ.js +3 -0
- package/dist/bin/shell/chunks/chunk-WDWNEHHE.js +9 -0
- package/dist/bin/shell/chunks/chunk-X4MX6EHF.js +6 -0
- package/dist/bin/shell/chunks/chunk-XBB73LFB.js +5 -0
- package/dist/bin/shell/chunks/chunk-XFFUAO3F.js +3 -0
- package/dist/bin/shell/chunks/chunk-XHCCSVP6.js +9 -0
- package/dist/bin/shell/chunks/chunk-XJ37N3S5.js +7 -0
- package/dist/bin/shell/chunks/chunk-XPTYN6UE.js +8 -0
- package/dist/bin/shell/chunks/chunk-XRUDFQG5.js +7 -0
- package/dist/bin/shell/chunks/chunk-Y4FPH5DQ.js +64 -0
- package/dist/bin/shell/chunks/chunk-YJ5OCPSK.js +7 -0
- package/dist/bin/shell/chunks/chunk-YOIFOOGX.js +9 -0
- package/dist/bin/shell/chunks/chunk-YOKQNNQO.js +6 -0
- package/dist/bin/shell/chunks/chunk-YUZRUF5F.js +10 -0
- package/dist/bin/shell/chunks/chunk-YY5PJR7O.js +7 -0
- package/dist/bin/shell/chunks/chunk-ZFUVUYWG.js +15 -0
- package/dist/bin/shell/chunks/clear-FGNEKYDU.js +3 -0
- package/dist/bin/shell/chunks/column-AQB3A3PJ.js +3 -0
- package/dist/bin/shell/chunks/comm-Q4VDF6ZO.js +3 -0
- package/dist/bin/shell/chunks/cp-HYXTMN3D.js +3 -0
- package/dist/bin/shell/chunks/curl-PLHETP4J.js +27 -0
- package/dist/bin/shell/chunks/cut-ZI2HIAW7.js +3 -0
- package/dist/bin/shell/chunks/date-JEZYSA4F.js +3 -0
- package/dist/bin/shell/chunks/diff-YDJ42RKS.js +3 -0
- package/dist/bin/shell/chunks/dirname-VCINTLPD.js +3 -0
- package/dist/bin/shell/chunks/du-4LRQIGRG.js +3 -0
- package/dist/bin/shell/chunks/echo-KCOHTNDF.js +3 -0
- package/dist/bin/shell/chunks/env-NY32PQJM.js +3 -0
- package/dist/bin/shell/chunks/expand-YYSO35NS.js +3 -0
- package/dist/bin/shell/chunks/expansion-PPP6PD75.js +3 -0
- package/dist/bin/shell/chunks/expr-7PLWSWZI.js +3 -0
- package/dist/bin/shell/chunks/file-GRZLWDVH.js +3 -0
- package/dist/bin/shell/chunks/find-P4DOE7CE.js +3 -0
- package/dist/bin/shell/chunks/flag-coverage-RFKIBJ6L.js +3 -0
- package/dist/bin/shell/chunks/fold-5MF7QZWQ.js +3 -0
- package/dist/bin/shell/chunks/grep-VAYCFO4O.js +3 -0
- package/dist/bin/shell/chunks/gzip-UGBQQKIH.js +3 -0
- package/dist/bin/shell/chunks/head-QNC2ZYDO.js +3 -0
- package/dist/bin/shell/chunks/help-CGUEOGXQ.js +3 -0
- package/dist/bin/shell/chunks/history-AQQWW3QB.js +3 -0
- package/dist/bin/shell/chunks/hostname-USNWOQCK.js +3 -0
- package/dist/bin/shell/chunks/html-to-markdown-QEFY7XQR.js +3 -0
- package/dist/bin/shell/chunks/join-EJ73DYTK.js +3 -0
- package/dist/bin/shell/chunks/jq-GGTKKMEN.js +3 -0
- package/dist/bin/shell/chunks/js-exec-BC6NI55L.js +98 -0
- package/dist/bin/shell/chunks/ln-LP4HMCSM.js +3 -0
- package/dist/bin/shell/chunks/ls-KBNHNZWQ.js +3 -0
- package/dist/bin/shell/chunks/md5sum-MCVDIB35.js +3 -0
- package/dist/bin/shell/chunks/mkdir-P4DKRCDX.js +3 -0
- package/dist/bin/shell/chunks/mv-QQK4FQX6.js +3 -0
- package/dist/bin/shell/chunks/nl-KUPLVCTS.js +3 -0
- package/dist/bin/shell/chunks/od-YQ5ZUI2H.js +3 -0
- package/dist/bin/shell/chunks/paste-A5KKPWXX.js +3 -0
- package/dist/bin/shell/chunks/printf-Z5C2UOI5.js +3 -0
- package/dist/bin/shell/chunks/pwd-FCNDA467.js +3 -0
- package/dist/bin/shell/chunks/python3-BQWDPUBM.js +13 -0
- package/dist/bin/shell/chunks/readlink-25V57VOL.js +3 -0
- package/dist/bin/shell/chunks/rev-PYHOZ4D4.js +3 -0
- package/dist/bin/shell/chunks/rg-BGFMSIVK.js +3 -0
- package/dist/bin/shell/chunks/rm-ECNUFR66.js +3 -0
- package/dist/bin/shell/chunks/rmdir-DLOHIA7Q.js +3 -0
- package/dist/bin/shell/chunks/sed-FWA634SN.js +3 -0
- package/dist/bin/shell/chunks/seq-UXDJE6FB.js +3 -0
- package/dist/bin/shell/chunks/sha1sum-4KF52U3Y.js +3 -0
- package/dist/bin/shell/chunks/sha256sum-6YEPULPX.js +3 -0
- package/dist/bin/shell/chunks/sleep-QHAPNY3Q.js +3 -0
- package/dist/bin/shell/chunks/sort-4C6WOKNK.js +3 -0
- package/dist/bin/shell/chunks/split-TV7NL7LA.js +3 -0
- package/dist/bin/shell/chunks/sqlite3-W777NCI4.js +3 -0
- package/dist/bin/shell/chunks/stat-BD6KT3BP.js +3 -0
- package/dist/bin/shell/chunks/strings-MDD72LR6.js +3 -0
- package/dist/bin/shell/chunks/tac-C2N4NQ6S.js +3 -0
- package/dist/bin/shell/chunks/tail-BCB5W6JC.js +3 -0
- package/dist/bin/shell/chunks/tar-DOO744MK.js +3 -0
- package/dist/bin/shell/chunks/tee-UQHPO4OW.js +3 -0
- package/dist/bin/shell/chunks/time-ZPY52VT2.js +3 -0
- package/dist/bin/shell/chunks/timeout-5AX3ZS3X.js +3 -0
- package/dist/bin/shell/chunks/touch-DFGSVIX7.js +3 -0
- package/dist/bin/shell/chunks/tr-G7K6M6HP.js +3 -0
- package/dist/bin/shell/chunks/tree-6D7SMPUR.js +3 -0
- package/dist/bin/shell/chunks/true-SKL4L7JP.js +3 -0
- package/dist/bin/shell/chunks/unexpand-QIR4EDPG.js +3 -0
- package/dist/bin/shell/chunks/uniq-I7PVFJR4.js +3 -0
- package/dist/bin/shell/chunks/wc-6NGWULAP.js +3 -0
- package/dist/bin/shell/chunks/which-LCXKCLFC.js +3 -0
- package/dist/bin/shell/chunks/whoami-TZDZDU7T.js +3 -0
- package/dist/bin/shell/chunks/xan-KX4VPXUN.js +3 -0
- package/dist/bin/shell/chunks/xan-view-JXOZLJ7S.js +3 -0
- package/dist/bin/shell/chunks/xargs-UWHPYLY7.js +3 -0
- package/dist/bin/shell/chunks/yq-GCDCJBKB.js +3 -0
- package/dist/bin/shell/shell.js +734 -0
- package/dist/browser.d.ts +23 -0
- package/dist/bundle/browser.js +1515 -0
- package/dist/bundle/chunks/alias-RTYYYW3D.js +2 -0
- package/dist/bundle/chunks/awk2-LA3USKJP.js +2 -0
- package/dist/bundle/chunks/base64-C2AIWVNC.js +2 -0
- package/dist/bundle/chunks/basename-UB3CIYNI.js +2 -0
- package/dist/bundle/chunks/bash-YZ33HQZQ.js +2 -0
- package/dist/bundle/chunks/cat-TSFMZVYS.js +2 -0
- package/dist/bundle/chunks/chmod-TFEPA42X.js +2 -0
- package/dist/bundle/chunks/chunk-27JIFWUR.js +3 -0
- package/dist/bundle/chunks/chunk-2JIPICV3.js +13 -0
- package/dist/bundle/chunks/chunk-2SMD2AUA.js +3 -0
- package/dist/bundle/chunks/chunk-2VDTE5BV.js +14 -0
- package/dist/bundle/chunks/chunk-2VJJEDV2.js +8 -0
- package/dist/bundle/chunks/chunk-46RN27KI.js +100 -0
- package/dist/bundle/chunks/chunk-4I3HOE5Z.js +21 -0
- package/dist/bundle/chunks/chunk-4JLVZKHC.js +8 -0
- package/dist/bundle/chunks/chunk-4MZPEZTU.js +3 -0
- package/dist/bundle/chunks/chunk-4N6J7B5P.js +6 -0
- package/dist/bundle/chunks/chunk-4RUAZWKT.js +33 -0
- package/dist/bundle/chunks/chunk-4WKZNNJK.js +2 -0
- package/dist/bundle/chunks/chunk-5H5SCKJM.js +11 -0
- package/dist/bundle/chunks/chunk-6LASZU3O.js +5 -0
- package/dist/bundle/chunks/chunk-6SHYIICL.js +4 -0
- package/dist/bundle/chunks/chunk-6VAT5Z2D.js +5 -0
- package/dist/bundle/chunks/chunk-7AISL3XV.js +12 -0
- package/dist/bundle/chunks/chunk-7EUWTCWK.js +2 -0
- package/dist/bundle/chunks/chunk-7JHM3L42.js +6 -0
- package/dist/bundle/chunks/chunk-A4R2GWRF.js +9 -0
- package/dist/bundle/chunks/chunk-ACSZB4FE.js +11 -0
- package/dist/bundle/chunks/chunk-AQ6FYS2X.js +2 -0
- package/dist/bundle/chunks/chunk-BVKWRAS6.js +12 -0
- package/dist/bundle/chunks/chunk-BZUGFHVS.js +2 -0
- package/dist/bundle/chunks/chunk-CBJVD2XA.js +7 -0
- package/dist/bundle/chunks/chunk-CHFEPBH4.js +18 -0
- package/dist/bundle/chunks/chunk-CN5XGDNN.js +6 -0
- package/dist/bundle/chunks/chunk-DLL7UR66.js +2 -0
- package/dist/bundle/chunks/chunk-EBAPSGAO.js +9 -0
- package/dist/bundle/chunks/chunk-FAXLQUCQ.js +10 -0
- package/dist/bundle/chunks/chunk-FHC24QSK.js +7 -0
- package/dist/bundle/chunks/chunk-FJK43EBQ.js +14 -0
- package/dist/bundle/chunks/chunk-FOCWZZDE.js +2 -0
- package/dist/bundle/chunks/chunk-FW54FHZR.js +2 -0
- package/dist/bundle/chunks/chunk-FX4RBUYU.js +5 -0
- package/dist/bundle/chunks/chunk-FX7KQCEA.js +33 -0
- package/dist/bundle/chunks/chunk-FZRQOL3C.js +7 -0
- package/dist/bundle/chunks/chunk-G5EVRAOO.js +74 -0
- package/dist/bundle/chunks/chunk-GGC5NEPZ.js +8 -0
- package/dist/bundle/chunks/chunk-GIUR5SNU.js +15 -0
- package/dist/bundle/chunks/chunk-GJC3WVOW.js +2 -0
- package/dist/bundle/chunks/chunk-GSPYNYZA.js +6 -0
- package/dist/bundle/chunks/chunk-GTQIUQM6.js +5 -0
- package/dist/bundle/chunks/chunk-HBVMHTO5.js +2 -0
- package/dist/bundle/chunks/chunk-HDRAUQK2.js +2 -0
- package/dist/bundle/chunks/chunk-HJBTD7PY.js +21 -0
- package/dist/bundle/chunks/chunk-ICIEVHY5.js +36 -0
- package/dist/bundle/chunks/chunk-KATRCGLX.js +2 -0
- package/dist/bundle/chunks/chunk-KD3KENL6.js +11 -0
- package/dist/bundle/chunks/chunk-KWGBQNTV.js +32 -0
- package/dist/bundle/chunks/chunk-L2UW7DWF.js +2 -0
- package/dist/bundle/chunks/chunk-L64BMZUV.js +2 -0
- package/dist/bundle/chunks/chunk-LEKBROJD.js +6 -0
- package/dist/bundle/chunks/chunk-LNBPBRV4.js +21 -0
- package/dist/bundle/chunks/chunk-LPJEKUCB.js +8 -0
- package/dist/bundle/chunks/chunk-LSLPJOYM.js +3 -0
- package/dist/bundle/chunks/chunk-MFDPAVC6.js +14 -0
- package/dist/bundle/chunks/chunk-MLIO3BK2.js +7 -0
- package/dist/bundle/chunks/chunk-MQKGGNPS.js +16 -0
- package/dist/bundle/chunks/chunk-MZFCCXPZ.js +63 -0
- package/dist/bundle/chunks/chunk-N6DXJ2JN.js +287 -0
- package/dist/bundle/chunks/chunk-NRSASXYY.js +2 -0
- package/dist/bundle/chunks/chunk-OC35HPHG.js +2 -0
- package/dist/bundle/chunks/chunk-OGJ5CFPR.js +9 -0
- package/dist/bundle/chunks/chunk-OVGANXCG.js +8 -0
- package/dist/bundle/chunks/chunk-Q7H5W7YE.js +140 -0
- package/dist/bundle/chunks/chunk-QAYAQNCG.js +23 -0
- package/dist/bundle/chunks/chunk-QIQMJJZ4.js +4 -0
- package/dist/bundle/chunks/chunk-R4IFXNY5.js +28 -0
- package/dist/bundle/chunks/chunk-R74UQCKX.js +5 -0
- package/dist/bundle/chunks/chunk-S3LEJEPP.js +2 -0
- package/dist/bundle/chunks/chunk-S443BAN4.js +7 -0
- package/dist/bundle/chunks/chunk-SAI2SPQQ.js +8 -0
- package/dist/bundle/chunks/chunk-SBBYKIYU.js +3 -0
- package/dist/bundle/chunks/chunk-SETW5JBN.js +9 -0
- package/dist/bundle/chunks/chunk-SHKOQWO4.js +3 -0
- package/dist/bundle/chunks/chunk-SJYEXC2Z.js +14 -0
- package/dist/bundle/chunks/chunk-SO6R3ZKN.js +16 -0
- package/dist/bundle/chunks/chunk-STHBFACM.js +1 -0
- package/dist/bundle/chunks/chunk-SX2HC7SO.js +2 -0
- package/dist/bundle/chunks/chunk-T4TFLF3R.js +16 -0
- package/dist/bundle/chunks/chunk-TDD4NFYE.js +2 -0
- package/dist/bundle/chunks/chunk-TN7HHBQW.js +5 -0
- package/dist/bundle/chunks/chunk-U73A73IE.js +17 -0
- package/dist/bundle/chunks/chunk-UIJUTQPH.js +3 -0
- package/dist/bundle/chunks/chunk-UP6MSJGD.js +17 -0
- package/dist/bundle/chunks/chunk-VLCHOJWK.js +6 -0
- package/dist/bundle/chunks/chunk-VPADYNBD.js +10 -0
- package/dist/bundle/chunks/chunk-W5DWRFSU.js +2 -0
- package/dist/bundle/chunks/chunk-WM5IJFMP.js +8 -0
- package/dist/bundle/chunks/chunk-WNH3HOQA.js +2 -0
- package/dist/bundle/chunks/chunk-WPGQVBSY.js +6 -0
- package/dist/bundle/chunks/chunk-WVRWIZF5.js +23 -0
- package/dist/bundle/chunks/chunk-XCQWV4AU.js +12 -0
- package/dist/bundle/chunks/chunk-XDGLKIHR.js +9 -0
- package/dist/bundle/chunks/chunk-XHLMAZX2.js +5 -0
- package/dist/bundle/chunks/chunk-XRFHFXFP.js +2 -0
- package/dist/bundle/chunks/chunk-XUIHBHL5.js +5 -0
- package/dist/bundle/chunks/chunk-XYXUMFSU.js +14 -0
- package/dist/bundle/chunks/chunk-Y4LIDHSD.js +7 -0
- package/dist/bundle/chunks/chunk-YCLFEX4T.js +3 -0
- package/dist/bundle/chunks/chunk-YS4NUBYX.js +9 -0
- package/dist/bundle/chunks/chunk-ZDIT6ST5.js +7 -0
- package/dist/bundle/chunks/chunk-ZDPFA4L3.js +6 -0
- package/dist/bundle/chunks/chunk-ZZKH2ELC.js +11 -0
- package/dist/bundle/chunks/clear-HKGFEOF6.js +2 -0
- package/dist/bundle/chunks/column-XT6UFXNQ.js +2 -0
- package/dist/bundle/chunks/comm-VV2LDX2J.js +2 -0
- package/dist/bundle/chunks/cp-BISAAS7A.js +2 -0
- package/dist/bundle/chunks/curl-GRYA74XW.js +26 -0
- package/dist/bundle/chunks/cut-OKARJCCV.js +2 -0
- package/dist/bundle/chunks/date-UUUPW43J.js +2 -0
- package/dist/bundle/chunks/diff-MWJFIG7X.js +2 -0
- package/dist/bundle/chunks/dirname-MPHRFUTI.js +2 -0
- package/dist/bundle/chunks/du-572XNP42.js +2 -0
- package/dist/bundle/chunks/echo-NDWZZHPO.js +2 -0
- package/dist/bundle/chunks/env-36M5BO7M.js +2 -0
- package/dist/bundle/chunks/expand-JSPG6VOP.js +2 -0
- package/dist/bundle/chunks/expansion-R25BK4W3.js +2 -0
- package/dist/bundle/chunks/expr-5JAACS4X.js +2 -0
- package/dist/bundle/chunks/file-IPZJC3FQ.js +2 -0
- package/dist/bundle/chunks/find-INTH3OLC.js +2 -0
- package/dist/bundle/chunks/flag-coverage-XWSYNE72.js +2 -0
- package/dist/bundle/chunks/fold-4TQNYMSW.js +2 -0
- package/dist/bundle/chunks/grep-V3LQVMRQ.js +2 -0
- package/dist/bundle/chunks/gzip-O5ASJAFY.js +2 -0
- package/dist/bundle/chunks/head-442HYESI.js +2 -0
- package/dist/bundle/chunks/help-HZ6M2CKN.js +2 -0
- package/dist/bundle/chunks/history-WYYKSLSZ.js +2 -0
- package/dist/bundle/chunks/hostname-C4HQXXUP.js +2 -0
- package/dist/bundle/chunks/html-to-markdown-JW4MSQZO.js +2 -0
- package/dist/bundle/chunks/join-TBRGI3LQ.js +2 -0
- package/dist/bundle/chunks/jq-4XLYLOS5.js +2 -0
- package/dist/bundle/chunks/js-exec-N5KEZBH7.js +97 -0
- package/dist/bundle/chunks/js-exec-worker.js +4443 -0
- package/dist/bundle/chunks/ln-4LGSXXGD.js +2 -0
- package/dist/bundle/chunks/ls-ZJGQER7M.js +2 -0
- package/dist/bundle/chunks/md5sum-SPU24VSG.js +2 -0
- package/dist/bundle/chunks/mkdir-MEPGZOB6.js +2 -0
- package/dist/bundle/chunks/mv-W5BIQ646.js +2 -0
- package/dist/bundle/chunks/nl-WSDW7I4O.js +2 -0
- package/dist/bundle/chunks/od-WOKFDJTP.js +2 -0
- package/dist/bundle/chunks/paste-7JC6S4DX.js +2 -0
- package/dist/bundle/chunks/printf-TWGXF445.js +2 -0
- package/dist/bundle/chunks/pwd-WE6EN5AV.js +2 -0
- package/dist/bundle/chunks/python3-POMOR4OA.js +12 -0
- package/dist/bundle/chunks/readlink-OPJF4DL5.js +2 -0
- package/dist/bundle/chunks/rev-5EHFX4EJ.js +2 -0
- package/dist/bundle/chunks/rg-S4FXYXWB.js +2 -0
- package/dist/bundle/chunks/rm-SSGETQVQ.js +2 -0
- package/dist/bundle/chunks/rmdir-OC4ZLPYA.js +2 -0
- package/dist/bundle/chunks/sed-S5UIK574.js +2 -0
- package/dist/bundle/chunks/seq-M5EC7Q57.js +2 -0
- package/dist/bundle/chunks/sha1sum-2PTOAFR6.js +2 -0
- package/dist/bundle/chunks/sha256sum-NS7D3IXX.js +2 -0
- package/dist/bundle/chunks/sleep-X22JJINO.js +2 -0
- package/dist/bundle/chunks/sort-SW2YEO5B.js +2 -0
- package/dist/bundle/chunks/split-4KKZZXXE.js +2 -0
- package/dist/bundle/chunks/sqlite3-CGOEFJAO.js +2 -0
- package/dist/bundle/chunks/sqlite3-worker.js +1728 -0
- package/dist/bundle/chunks/stat-CD34IZ4P.js +2 -0
- package/dist/bundle/chunks/strings-6WDHLGMX.js +2 -0
- package/dist/bundle/chunks/tac-2STMMJYW.js +2 -0
- package/dist/bundle/chunks/tail-R4PCA2C4.js +2 -0
- package/dist/bundle/chunks/tar-STHHZTZ6.js +2 -0
- package/dist/bundle/chunks/tee-YUZ2FKCJ.js +2 -0
- package/dist/bundle/chunks/time-D4LNBSWX.js +2 -0
- package/dist/bundle/chunks/timeout-YDCRSLPQ.js +2 -0
- package/dist/bundle/chunks/touch-UA33VN3N.js +2 -0
- package/dist/bundle/chunks/tr-36LHWFRQ.js +2 -0
- package/dist/bundle/chunks/tree-YLD52CNT.js +2 -0
- package/dist/bundle/chunks/true-FHQXJXBE.js +2 -0
- package/dist/bundle/chunks/unexpand-CADSA4VO.js +2 -0
- package/dist/bundle/chunks/uniq-XSIZR6PB.js +2 -0
- package/dist/bundle/chunks/wc-LF7NU4LA.js +2 -0
- package/dist/bundle/chunks/which-XEM24D5D.js +2 -0
- package/dist/bundle/chunks/whoami-XMTX52VE.js +2 -0
- package/dist/bundle/chunks/worker.js +3150 -0
- package/dist/bundle/chunks/xan-Y6WF3IRG.js +2 -0
- package/dist/bundle/chunks/xan-view-HDVKHFC2.js +2 -0
- package/dist/bundle/chunks/xargs-MGZPH7AX.js +2 -0
- package/dist/bundle/chunks/yq-4QJW3EQG.js +2 -0
- package/dist/bundle/index.cjs +2178 -0
- package/dist/bundle/index.js +710 -0
- package/dist/commands/alias/alias.d.ts +6 -0
- package/dist/commands/awk/ast.d.ts +202 -0
- package/dist/commands/awk/awk2.d.ts +9 -0
- package/dist/commands/awk/builtins.d.ts +17 -0
- package/dist/commands/awk/interpreter/context.d.ts +75 -0
- package/dist/commands/awk/interpreter/expressions.d.ts +17 -0
- package/dist/commands/awk/interpreter/fields.d.ts +25 -0
- package/dist/commands/awk/interpreter/index.d.ts +8 -0
- package/dist/commands/awk/interpreter/interpreter.d.ts +54 -0
- package/dist/commands/awk/interpreter/statements.d.ts +11 -0
- package/dist/commands/awk/interpreter/type-coercion.d.ts +32 -0
- package/dist/commands/awk/interpreter/types.d.ts +13 -0
- package/dist/commands/awk/interpreter/variables.d.ts +35 -0
- package/dist/commands/awk/lexer.d.ts +100 -0
- package/dist/commands/awk/parser2-print.d.ts +35 -0
- package/dist/commands/awk/parser2.d.ts +81 -0
- package/dist/commands/base64/base64.d.ts +7 -0
- package/dist/commands/basename/basename.d.ts +4 -0
- package/dist/commands/bash/bash.d.ts +6 -0
- package/dist/commands/browser-excluded.d.ts +16 -0
- package/dist/commands/cat/cat.d.ts +4 -0
- package/dist/commands/chmod/chmod.d.ts +4 -0
- package/dist/commands/clear/clear.d.ts +4 -0
- package/dist/commands/column/column.d.ts +11 -0
- package/dist/commands/comm/comm.d.ts +12 -0
- package/dist/commands/cp/cp.d.ts +4 -0
- package/dist/commands/curl/curl.d.ts +8 -0
- package/dist/commands/curl/form.d.ts +21 -0
- package/dist/commands/curl/help.d.ts +9 -0
- package/dist/commands/curl/parse.d.ts +9 -0
- package/dist/commands/curl/response-formatting.d.ts +20 -0
- package/dist/commands/curl/types.d.ts +60 -0
- package/dist/commands/cut/cut.d.ts +4 -0
- package/dist/commands/date/date.d.ts +7 -0
- package/dist/commands/diff/diff.d.ts +7 -0
- package/dist/commands/dirname/dirname.d.ts +4 -0
- package/dist/commands/du/du.d.ts +4 -0
- package/dist/commands/duration.d.ts +5 -0
- package/dist/commands/echo/echo.d.ts +4 -0
- package/dist/commands/env/env.d.ts +6 -0
- package/dist/commands/expand/expand.d.ts +12 -0
- package/dist/commands/expand/unexpand.d.ts +12 -0
- package/dist/commands/expr/expr.d.ts +9 -0
- package/dist/commands/file/file.d.ts +9 -0
- package/dist/commands/find/find.d.ts +4 -0
- package/dist/commands/find/matcher.d.ts +69 -0
- package/dist/commands/find/parser.d.ts +2 -0
- package/dist/commands/find/types.d.ts +88 -0
- package/dist/commands/flag-coverage.d.ts +2 -0
- package/dist/commands/fold/fold.d.ts +12 -0
- package/dist/commands/format-mode.d.ts +4 -0
- package/dist/commands/fuzz-flags-types.d.ts +17 -0
- package/dist/commands/fuzz-flags.d.ts +8 -0
- package/dist/commands/grep/grep.d.ts +8 -0
- package/dist/commands/gzip/gzip.d.ts +13 -0
- package/dist/commands/head/head-tail-shared.d.ts +38 -0
- package/dist/commands/head/head.d.ts +4 -0
- package/dist/commands/help/help.d.ts +4 -0
- package/dist/commands/help.d.ts +16 -0
- package/dist/commands/history/history.d.ts +4 -0
- package/dist/commands/hostname/hostname.d.ts +11 -0
- package/dist/commands/html-to-markdown/html-to-markdown.d.ts +9 -0
- package/dist/commands/join/join.d.ts +12 -0
- package/dist/commands/jq/jq.d.ts +9 -0
- package/dist/commands/js-exec/fetch-polyfill.d.ts +6 -0
- package/dist/commands/js-exec/js-exec-worker.d.ts +32 -0
- package/dist/commands/js-exec/js-exec.d.ts +11 -0
- package/dist/commands/js-exec/module-shims.d.ts +29 -0
- package/dist/commands/js-exec/path-polyfill.d.ts +6 -0
- package/dist/commands/ln/ln.d.ts +4 -0
- package/dist/commands/ls/ls.d.ts +4 -0
- package/dist/commands/md5sum/checksum.d.ts +7 -0
- package/dist/commands/md5sum/md5sum.d.ts +4 -0
- package/dist/commands/md5sum/sha1sum.d.ts +4 -0
- package/dist/commands/md5sum/sha256sum.d.ts +4 -0
- package/dist/commands/mkdir/mkdir.d.ts +4 -0
- package/dist/commands/mv/mv.d.ts +4 -0
- package/dist/commands/nl/nl.d.ts +12 -0
- package/dist/commands/od/od.d.ts +12 -0
- package/dist/commands/paste/paste.d.ts +4 -0
- package/dist/commands/printf/escapes.d.ts +25 -0
- package/dist/commands/printf/printf.d.ts +4 -0
- package/dist/commands/printf/strftime.d.ts +9 -0
- package/dist/commands/pwd/pwd.d.ts +4 -0
- package/dist/commands/python3/python3.d.ts +16 -0
- package/dist/commands/python3/worker.d.ts +28 -0
- package/dist/commands/query-engine/builtins/array-builtins.d.ts +20 -0
- package/dist/commands/query-engine/builtins/control-builtins.d.ts +18 -0
- package/dist/commands/query-engine/builtins/date-builtins.d.ts +15 -0
- package/dist/commands/query-engine/builtins/format-builtins.d.ts +11 -0
- package/dist/commands/query-engine/builtins/index-builtins.d.ts +16 -0
- package/dist/commands/query-engine/builtins/index.d.ts +17 -0
- package/dist/commands/query-engine/builtins/math-builtins.d.ts +15 -0
- package/dist/commands/query-engine/builtins/navigation-builtins.d.ts +18 -0
- package/dist/commands/query-engine/builtins/object-builtins.d.ts +15 -0
- package/dist/commands/query-engine/builtins/path-builtins.d.ts +20 -0
- package/dist/commands/query-engine/builtins/sql-builtins.d.ts +16 -0
- package/dist/commands/query-engine/builtins/string-builtins.d.ts +15 -0
- package/dist/commands/query-engine/builtins/type-builtins.d.ts +11 -0
- package/dist/commands/query-engine/evaluator.d.ts +40 -0
- package/dist/commands/query-engine/index.d.ts +8 -0
- package/dist/commands/query-engine/parser-types.d.ts +171 -0
- package/dist/commands/query-engine/parser.d.ts +9 -0
- package/dist/commands/query-engine/path-operations.d.ts +15 -0
- package/dist/commands/query-engine/safe-object.d.ts +83 -0
- package/dist/commands/query-engine/value-operations.d.ts +41 -0
- package/dist/commands/readlink/readlink.d.ts +4 -0
- package/dist/commands/registry.d.ts +56 -0
- package/dist/commands/rev/rev.d.ts +13 -0
- package/dist/commands/rg/file-types.d.ts +49 -0
- package/dist/commands/rg/gitignore.d.ts +98 -0
- package/dist/commands/rg/rg-options.d.ts +61 -0
- package/dist/commands/rg/rg-parser.d.ts +20 -0
- package/dist/commands/rg/rg-search.d.ts +15 -0
- package/dist/commands/rg/rg.d.ts +14 -0
- package/dist/commands/rm/rm.d.ts +4 -0
- package/dist/commands/rmdir/rmdir.d.ts +4 -0
- package/dist/commands/search-engine/index.d.ts +10 -0
- package/dist/commands/search-engine/matcher.d.ts +66 -0
- package/dist/commands/search-engine/regex.d.ts +46 -0
- package/dist/commands/sed/executor.d.ts +7 -0
- package/dist/commands/sed/lexer.d.ts +86 -0
- package/dist/commands/sed/parser.d.ts +18 -0
- package/dist/commands/sed/sed-regex.d.ts +23 -0
- package/dist/commands/sed/sed.d.ts +4 -0
- package/dist/commands/sed/types.d.ts +216 -0
- package/dist/commands/seq/seq.d.ts +16 -0
- package/dist/commands/sleep/sleep.d.ts +4 -0
- package/dist/commands/sort/comparator.d.ts +9 -0
- package/dist/commands/sort/parser.d.ts +11 -0
- package/dist/commands/sort/sort.d.ts +4 -0
- package/dist/commands/sort/types.d.ts +30 -0
- package/dist/commands/split/split.d.ts +12 -0
- package/dist/commands/sqlite3/formatters.d.ts +15 -0
- package/dist/commands/sqlite3/sqlite3.d.ts +23 -0
- package/dist/commands/sqlite3/worker.d.ts +45 -0
- package/dist/commands/sqlite3/worker.js +1728 -0
- package/dist/commands/stat/stat.d.ts +4 -0
- package/dist/commands/strings/strings.d.ts +12 -0
- package/dist/commands/tac/tac.d.ts +11 -0
- package/dist/commands/tail/tail.d.ts +4 -0
- package/dist/commands/tar/archive.d.ts +135 -0
- package/dist/commands/tar/bzip2-compress.d.ts +17 -0
- package/dist/commands/tar/tar-options.d.ts +37 -0
- package/dist/commands/tar/tar.d.ts +10 -0
- package/dist/commands/tee/tee.d.ts +4 -0
- package/dist/commands/time/time.d.ts +27 -0
- package/dist/commands/timeout/timeout.d.ts +4 -0
- package/dist/commands/touch/touch.d.ts +4 -0
- package/dist/commands/tr/tr.d.ts +4 -0
- package/dist/commands/tree/tree.d.ts +4 -0
- package/dist/commands/true/true.d.ts +6 -0
- package/dist/commands/uniq/uniq.d.ts +4 -0
- package/dist/commands/wc/wc.d.ts +4 -0
- package/dist/commands/which/which.d.ts +4 -0
- package/dist/commands/whoami/whoami.d.ts +11 -0
- package/dist/commands/worker-bridge/bridge-handler.d.ts +73 -0
- package/dist/commands/worker-bridge/protocol.d.ts +141 -0
- package/dist/commands/worker-bridge/sync-backend.d.ts +86 -0
- package/dist/commands/xan/aggregation.d.ts +20 -0
- package/dist/commands/xan/column-selection.d.ts +19 -0
- package/dist/commands/xan/csv.d.ts +37 -0
- package/dist/commands/xan/moonblade-parser.d.ts +80 -0
- package/dist/commands/xan/moonblade-to-jq.d.ts +12 -0
- package/dist/commands/xan/moonblade-tokenizer.d.ts +25 -0
- package/dist/commands/xan/subcommands.d.ts +15 -0
- package/dist/commands/xan/xan-agg.d.ts +8 -0
- package/dist/commands/xan/xan-columns.d.ts +8 -0
- package/dist/commands/xan/xan-core.d.ts +10 -0
- package/dist/commands/xan/xan-data.d.ts +52 -0
- package/dist/commands/xan/xan-filter.d.ts +8 -0
- package/dist/commands/xan/xan-map.d.ts +11 -0
- package/dist/commands/xan/xan-reshape.d.ts +40 -0
- package/dist/commands/xan/xan-simple.d.ts +40 -0
- package/dist/commands/xan/xan-view.d.ts +12 -0
- package/dist/commands/xan/xan.d.ts +10 -0
- package/dist/commands/xargs/xargs.d.ts +4 -0
- package/dist/commands/yq/formats.d.ts +64 -0
- package/dist/commands/yq/yq.d.ts +13 -0
- package/dist/custom-commands.d.ts +42 -0
- package/dist/encoding.d.ts +115 -0
- package/dist/fs/encoding.d.ts +17 -0
- package/dist/fs/in-memory-fs/in-memory-fs.d.ts +75 -0
- package/dist/fs/in-memory-fs/index.d.ts +1 -0
- package/dist/fs/init.d.ts +22 -0
- package/dist/fs/interface.d.ts +251 -0
- package/dist/fs/mountable-fs/index.d.ts +1 -0
- package/dist/fs/mountable-fs/mountable-fs.d.ts +118 -0
- package/dist/fs/overlay-fs/index.d.ts +1 -0
- package/dist/fs/overlay-fs/overlay-fs.d.ts +165 -0
- package/dist/fs/path-utils.d.ts +46 -0
- package/dist/fs/read-write-fs/index.d.ts +1 -0
- package/dist/fs/read-write-fs/read-write-fs.d.ts +98 -0
- package/dist/fs/real-fs-utils.d.ts +90 -0
- package/dist/fs/sanitize-error.d.ts +19 -0
- package/dist/index.d.cts +29 -0
- package/dist/index.d.ts +29 -0
- package/dist/interpreter/alias-expansion.d.ts +23 -0
- package/dist/interpreter/arithmetic.d.ts +24 -0
- package/dist/interpreter/assignment-expansion.d.ts +24 -0
- package/dist/interpreter/builtin-dispatch.d.ts +39 -0
- package/dist/interpreter/builtins/break.d.ts +6 -0
- package/dist/interpreter/builtins/cd.d.ts +6 -0
- package/dist/interpreter/builtins/compgen.d.ts +26 -0
- package/dist/interpreter/builtins/complete.d.ts +17 -0
- package/dist/interpreter/builtins/compopt.d.ts +28 -0
- package/dist/interpreter/builtins/continue.d.ts +6 -0
- package/dist/interpreter/builtins/declare-array-parsing.d.ts +14 -0
- package/dist/interpreter/builtins/declare-print.d.ts +39 -0
- package/dist/interpreter/builtins/declare.d.ts +35 -0
- package/dist/interpreter/builtins/dirs.d.ts +29 -0
- package/dist/interpreter/builtins/eval.d.ts +9 -0
- package/dist/interpreter/builtins/exit.d.ts +5 -0
- package/dist/interpreter/builtins/export.d.ts +14 -0
- package/dist/interpreter/builtins/getopts.d.ts +18 -0
- package/dist/interpreter/builtins/hash.d.ts +19 -0
- package/dist/interpreter/builtins/help.d.ts +12 -0
- package/dist/interpreter/builtins/index.d.ts +45 -0
- package/dist/interpreter/builtins/let.d.ts +18 -0
- package/dist/interpreter/builtins/local.d.ts +6 -0
- package/dist/interpreter/builtins/mapfile.d.ts +17 -0
- package/dist/interpreter/builtins/read.d.ts +6 -0
- package/dist/interpreter/builtins/return.d.ts +6 -0
- package/dist/interpreter/builtins/set.d.ts +9 -0
- package/dist/interpreter/builtins/shift.d.ts +15 -0
- package/dist/interpreter/builtins/shopt.d.ts +7 -0
- package/dist/interpreter/builtins/source.d.ts +6 -0
- package/dist/interpreter/builtins/unset.d.ts +16 -0
- package/dist/interpreter/builtins/variable-assignment.d.ts +66 -0
- package/dist/interpreter/command-resolution.d.ts +43 -0
- package/dist/interpreter/conditionals.d.ts +17 -0
- package/dist/interpreter/control-flow.d.ts +21 -0
- package/dist/interpreter/defense-aware-command-context.d.ts +6 -0
- package/dist/interpreter/errors.d.ts +158 -0
- package/dist/interpreter/expansion/analysis.d.ts +37 -0
- package/dist/interpreter/expansion/arith-text-expansion.d.ts +20 -0
- package/dist/interpreter/expansion/array-pattern-ops.d.ts +21 -0
- package/dist/interpreter/expansion/array-prefix-suffix.d.ts +46 -0
- package/dist/interpreter/expansion/array-slice-transform.d.ts +36 -0
- package/dist/interpreter/expansion/array-word-expansion.d.ts +39 -0
- package/dist/interpreter/expansion/brace-range.d.ts +20 -0
- package/dist/interpreter/expansion/command-substitution.d.ts +23 -0
- package/dist/interpreter/expansion/glob-escape.d.ts +32 -0
- package/dist/interpreter/expansion/indirect-expansion.d.ts +42 -0
- package/dist/interpreter/expansion/parameter-ops.d.ts +113 -0
- package/dist/interpreter/expansion/pattern-expansion.d.ts +23 -0
- package/dist/interpreter/expansion/pattern-removal.d.ts +18 -0
- package/dist/interpreter/expansion/pattern.d.ts +23 -0
- package/dist/interpreter/expansion/positional-params.d.ts +59 -0
- package/dist/interpreter/expansion/prompt.d.ts +39 -0
- package/dist/interpreter/expansion/quoting.d.ts +13 -0
- package/dist/interpreter/expansion/tilde.d.ts +12 -0
- package/dist/interpreter/expansion/unquoted-expansion.d.ts +76 -0
- package/dist/interpreter/expansion/variable-attrs.d.ts +19 -0
- package/dist/interpreter/expansion/variable.d.ts +36 -0
- package/dist/interpreter/expansion/word-glob-expansion.d.ts +33 -0
- package/dist/interpreter/expansion/word-split.d.ts +29 -0
- package/dist/interpreter/expansion.d.ts +53 -0
- package/dist/interpreter/functions.d.ts +12 -0
- package/dist/interpreter/helpers/array.d.ts +43 -0
- package/dist/interpreter/helpers/condition.d.ts +22 -0
- package/dist/interpreter/helpers/errors.d.ts +8 -0
- package/dist/interpreter/helpers/file-tests.d.ts +33 -0
- package/dist/interpreter/helpers/ifs.d.ts +104 -0
- package/dist/interpreter/helpers/loop.d.ts +24 -0
- package/dist/interpreter/helpers/nameref.d.ts +65 -0
- package/dist/interpreter/helpers/numeric-compare.d.ts +13 -0
- package/dist/interpreter/helpers/quoting.d.ts +24 -0
- package/dist/interpreter/helpers/readonly.d.ts +45 -0
- package/dist/interpreter/helpers/regex.d.ts +8 -0
- package/dist/interpreter/helpers/result.d.ts +60 -0
- package/dist/interpreter/helpers/shell-constants.d.ts +25 -0
- package/dist/interpreter/helpers/shellopts.d.ts +28 -0
- package/dist/interpreter/helpers/statements.d.ts +20 -0
- package/dist/interpreter/helpers/string-compare.d.ts +24 -0
- package/dist/interpreter/helpers/string-tests.d.ts +13 -0
- package/dist/interpreter/helpers/tilde.d.ts +13 -0
- package/dist/interpreter/helpers/variable-tests.d.ts +9 -0
- package/dist/interpreter/helpers/word-matching.d.ts +26 -0
- package/dist/interpreter/helpers/word-parts.d.ts +22 -0
- package/dist/interpreter/helpers/xtrace.d.ts +18 -0
- package/dist/interpreter/index.d.ts +3 -0
- package/dist/interpreter/interpreter.d.ts +79 -0
- package/dist/interpreter/pipeline-execution.d.ts +16 -0
- package/dist/interpreter/redirections.d.ts +51 -0
- package/dist/interpreter/simple-command-assignments.d.ts +29 -0
- package/dist/interpreter/subshell-group.d.ts +32 -0
- package/dist/interpreter/type-command.d.ts +37 -0
- package/dist/interpreter/types.d.ts +349 -0
- package/dist/limits.d.ts +52 -0
- package/dist/network/allow-list/shared.d.ts +57 -0
- package/dist/network/allow-list.d.ts +59 -0
- package/dist/network/dns-pin.d.ts +43 -0
- package/dist/network/fetch.d.ts +25 -0
- package/dist/network/index.d.ts +7 -0
- package/dist/network/types.d.ts +155 -0
- package/dist/parser/arithmetic-parser.d.ts +23 -0
- package/dist/parser/arithmetic-primaries.d.ts +45 -0
- package/dist/parser/command-parser.d.ts +10 -0
- package/dist/parser/compound-parser.d.ts +28 -0
- package/dist/parser/conditional-parser.d.ts +8 -0
- package/dist/parser/expansion-parser.d.ts +16 -0
- package/dist/parser/lexer.d.ts +197 -0
- package/dist/parser/parser-substitution.d.ts +62 -0
- package/dist/parser/parser.d.ts +135 -0
- package/dist/parser/types.d.ts +25 -0
- package/dist/parser/word-parser.d.ts +33 -0
- package/dist/sandbox/Command.d.ts +35 -0
- package/dist/sandbox/Sandbox.d.ts +90 -0
- package/dist/sandbox/index.d.ts +2 -0
- package/dist/shell-metadata.d.ts +25 -0
- package/dist/timers.d.ts +4 -0
- package/dist/types.d.ts +247 -0
- package/dist/utils/args.d.ts +55 -0
- package/dist/utils/constants.d.ts +15 -0
- package/dist/utils/file-reader.d.ts +74 -0
- package/dist/utils/glob.d.ts +25 -0
- package/dist/vitest-setup.d.ts +1 -0
- package/package.json +127 -0
- package/vendor/cpython-emscripten/python.cjs +2 -0
- package/vendor/cpython-emscripten/python.wasm +0 -0
- package/vendor/cpython-emscripten/python313.zip +0 -0
|
@@ -0,0 +1,3150 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
// src/commands/python3/worker.ts
|
|
9
|
+
import { createRequire } from "node:module";
|
|
10
|
+
import { dirname } from "node:path";
|
|
11
|
+
import { parentPort, workerData } from "node:worker_threads";
|
|
12
|
+
|
|
13
|
+
// src/fs/sanitize-error.ts
|
|
14
|
+
function sanitizeWithUnixPrefixes(message, includeHostRuntimePrefixes, includeFileUrls) {
|
|
15
|
+
if (!message) return message;
|
|
16
|
+
let sanitized = message.replace(/\n\s+at\s.*/g, "");
|
|
17
|
+
if (includeFileUrls) {
|
|
18
|
+
sanitized = sanitized.replace(/\bfile:\/\/\/?[^\s'",)}\]:]+/g, "<path>");
|
|
19
|
+
}
|
|
20
|
+
sanitized = sanitized.replace(
|
|
21
|
+
includeHostRuntimePrefixes ? /(?:\/(?:Users|home|private|var|opt|Library|System|usr|etc|tmp|nix|snap|workspace|root|srv|mnt|app))\b[^\s'",)}\]:]*/g : /(?:\/(?:Users|home|private|var|opt|Library|System|usr|etc|tmp|nix|snap))\b[^\s'",)}\]:]*/g,
|
|
22
|
+
"<path>"
|
|
23
|
+
);
|
|
24
|
+
sanitized = sanitized.replace(/node:internal\/[^\s'",)}\]:]+/g, "<internal>");
|
|
25
|
+
sanitized = sanitized.replace(/[A-Z]:\\[^\s'",)}\]:]+/g, "<path>");
|
|
26
|
+
if (includeFileUrls) {
|
|
27
|
+
sanitized = sanitized.replace(/\\\\[^\s\\]+\\[^\s'",)}\]:]+/g, "<path>");
|
|
28
|
+
}
|
|
29
|
+
return sanitized;
|
|
30
|
+
}
|
|
31
|
+
function sanitizeErrorMessage(message) {
|
|
32
|
+
return sanitizeWithUnixPrefixes(message, false, false);
|
|
33
|
+
}
|
|
34
|
+
function sanitizeHostErrorMessage(message) {
|
|
35
|
+
return sanitizeWithUnixPrefixes(message, true, true);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// src/security/blocked-globals.ts
|
|
39
|
+
function getBlockedGlobals() {
|
|
40
|
+
const globals = [
|
|
41
|
+
// Direct code execution vectors
|
|
42
|
+
{
|
|
43
|
+
prop: "Function",
|
|
44
|
+
target: globalThis,
|
|
45
|
+
violationType: "function_constructor",
|
|
46
|
+
strategy: "throw",
|
|
47
|
+
reason: "Function constructor allows arbitrary code execution"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
prop: "eval",
|
|
51
|
+
target: globalThis,
|
|
52
|
+
violationType: "eval",
|
|
53
|
+
strategy: "throw",
|
|
54
|
+
reason: "eval() allows arbitrary code execution"
|
|
55
|
+
},
|
|
56
|
+
// Timer functions with string argument allow code execution
|
|
57
|
+
{
|
|
58
|
+
prop: "setTimeout",
|
|
59
|
+
target: globalThis,
|
|
60
|
+
violationType: "setTimeout",
|
|
61
|
+
strategy: "throw",
|
|
62
|
+
reason: "setTimeout with string argument allows code execution"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
prop: "setInterval",
|
|
66
|
+
target: globalThis,
|
|
67
|
+
violationType: "setInterval",
|
|
68
|
+
strategy: "throw",
|
|
69
|
+
reason: "setInterval with string argument allows code execution"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
prop: "setImmediate",
|
|
73
|
+
target: globalThis,
|
|
74
|
+
violationType: "setImmediate",
|
|
75
|
+
strategy: "throw",
|
|
76
|
+
reason: "setImmediate could be used to escape sandbox context"
|
|
77
|
+
},
|
|
78
|
+
// Note: We intentionally do NOT block `process` entirely because:
|
|
79
|
+
// 1. Node.js internals (Promise resolution, etc.) use process.nextTick
|
|
80
|
+
// 2. Blocking process entirely breaks normal async operation
|
|
81
|
+
// 3. The primary code execution vectors (Function, eval) are already blocked
|
|
82
|
+
// However, we DO block specific dangerous process properties.
|
|
83
|
+
{
|
|
84
|
+
prop: "env",
|
|
85
|
+
target: process,
|
|
86
|
+
violationType: "process_env",
|
|
87
|
+
strategy: "throw",
|
|
88
|
+
reason: "process.env could leak sensitive environment variables",
|
|
89
|
+
// Node.js internals and bundled dependencies read these env vars
|
|
90
|
+
// during module loading, file watching, and I/O within the
|
|
91
|
+
// AsyncLocalStorage context. None are user secrets.
|
|
92
|
+
allowedKeys: /* @__PURE__ */ new Set([
|
|
93
|
+
// Node.js core
|
|
94
|
+
"NODE_V8_COVERAGE",
|
|
95
|
+
"NODE_DEBUG",
|
|
96
|
+
"NODE_DEBUG_NATIVE",
|
|
97
|
+
"NODE_COMPILE_CACHE",
|
|
98
|
+
"WATCH_REPORT_DEPENDENCIES",
|
|
99
|
+
// Dependencies
|
|
100
|
+
"FORCE_COLOR",
|
|
101
|
+
// chalk/supports-color
|
|
102
|
+
"DEBUG",
|
|
103
|
+
// debug package
|
|
104
|
+
"UNDICI_NO_FG",
|
|
105
|
+
// undici (Node.js fetch)
|
|
106
|
+
"JEST_WORKER_ID",
|
|
107
|
+
// jest/vitest worker detection
|
|
108
|
+
"__MINIMATCH_TESTING_PLATFORM__",
|
|
109
|
+
// minimatch
|
|
110
|
+
"LOG_TOKENS",
|
|
111
|
+
// query engine debug logging
|
|
112
|
+
"LOG_STREAM"
|
|
113
|
+
// query engine debug logging
|
|
114
|
+
])
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
prop: "binding",
|
|
118
|
+
target: process,
|
|
119
|
+
violationType: "process_binding",
|
|
120
|
+
strategy: "throw",
|
|
121
|
+
reason: "process.binding provides access to native Node.js modules"
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
prop: "_linkedBinding",
|
|
125
|
+
target: process,
|
|
126
|
+
violationType: "process_binding",
|
|
127
|
+
strategy: "throw",
|
|
128
|
+
reason: "process._linkedBinding provides access to native Node.js modules"
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
prop: "dlopen",
|
|
132
|
+
target: process,
|
|
133
|
+
violationType: "process_dlopen",
|
|
134
|
+
strategy: "throw",
|
|
135
|
+
reason: "process.dlopen allows loading native addons"
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
prop: "getBuiltinModule",
|
|
139
|
+
target: process,
|
|
140
|
+
violationType: "process_get_builtin_module",
|
|
141
|
+
strategy: "throw",
|
|
142
|
+
reason: "process.getBuiltinModule allows loading native Node.js modules (fs, child_process, vm)"
|
|
143
|
+
},
|
|
144
|
+
// Note: process.mainModule is handled specially in defense-in-depth-box.ts
|
|
145
|
+
// and worker-defense-in-depth.ts because it may be undefined in ESM contexts
|
|
146
|
+
// but we still want to block both reading and setting it.
|
|
147
|
+
// Process control vectors
|
|
148
|
+
{
|
|
149
|
+
prop: "exit",
|
|
150
|
+
target: process,
|
|
151
|
+
violationType: "process_exit",
|
|
152
|
+
strategy: "throw",
|
|
153
|
+
reason: "process.exit could terminate the interpreter"
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
prop: "abort",
|
|
157
|
+
target: process,
|
|
158
|
+
violationType: "process_exit",
|
|
159
|
+
strategy: "throw",
|
|
160
|
+
reason: "process.abort could crash the interpreter"
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
prop: "kill",
|
|
164
|
+
target: process,
|
|
165
|
+
violationType: "process_kill",
|
|
166
|
+
strategy: "throw",
|
|
167
|
+
reason: "process.kill could signal other processes"
|
|
168
|
+
},
|
|
169
|
+
// Privilege escalation vectors
|
|
170
|
+
{
|
|
171
|
+
prop: "setuid",
|
|
172
|
+
target: process,
|
|
173
|
+
violationType: "process_setuid",
|
|
174
|
+
strategy: "throw",
|
|
175
|
+
reason: "process.setuid could escalate privileges"
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
prop: "setgid",
|
|
179
|
+
target: process,
|
|
180
|
+
violationType: "process_setuid",
|
|
181
|
+
strategy: "throw",
|
|
182
|
+
reason: "process.setgid could escalate privileges"
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
prop: "seteuid",
|
|
186
|
+
target: process,
|
|
187
|
+
violationType: "process_setuid",
|
|
188
|
+
strategy: "throw",
|
|
189
|
+
reason: "process.seteuid could escalate effective user privileges"
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
prop: "setegid",
|
|
193
|
+
target: process,
|
|
194
|
+
violationType: "process_setuid",
|
|
195
|
+
strategy: "throw",
|
|
196
|
+
reason: "process.setegid could escalate effective group privileges"
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
prop: "initgroups",
|
|
200
|
+
target: process,
|
|
201
|
+
violationType: "process_setuid",
|
|
202
|
+
strategy: "throw",
|
|
203
|
+
reason: "process.initgroups could modify supplementary group IDs"
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
prop: "setgroups",
|
|
207
|
+
target: process,
|
|
208
|
+
violationType: "process_setuid",
|
|
209
|
+
strategy: "throw",
|
|
210
|
+
reason: "process.setgroups could modify supplementary group IDs"
|
|
211
|
+
},
|
|
212
|
+
// File permission manipulation
|
|
213
|
+
{
|
|
214
|
+
prop: "umask",
|
|
215
|
+
target: process,
|
|
216
|
+
violationType: "process_umask",
|
|
217
|
+
strategy: "throw",
|
|
218
|
+
reason: "process.umask could modify file creation permissions"
|
|
219
|
+
},
|
|
220
|
+
// Information disclosure vectors
|
|
221
|
+
// Note: process.argv is an array (object) so gets an object proxy
|
|
222
|
+
{
|
|
223
|
+
prop: "argv",
|
|
224
|
+
target: process,
|
|
225
|
+
violationType: "process_argv",
|
|
226
|
+
strategy: "throw",
|
|
227
|
+
reason: "process.argv may contain secrets in CLI arguments"
|
|
228
|
+
},
|
|
229
|
+
// Note: process.execPath is a string primitive, handled specially
|
|
230
|
+
// in defense-in-depth-box.ts and worker-defense-in-depth.ts
|
|
231
|
+
// Note: process.connected is a boolean primitive, handled specially
|
|
232
|
+
// in defense-in-depth-box.ts and worker-defense-in-depth.ts
|
|
233
|
+
// Working directory access/manipulation
|
|
234
|
+
{
|
|
235
|
+
prop: "cwd",
|
|
236
|
+
target: process,
|
|
237
|
+
violationType: "process_chdir",
|
|
238
|
+
strategy: "throw",
|
|
239
|
+
reason: "process.cwd could disclose real host working directory path"
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
prop: "chdir",
|
|
243
|
+
target: process,
|
|
244
|
+
violationType: "process_chdir",
|
|
245
|
+
strategy: "throw",
|
|
246
|
+
reason: "process.chdir could confuse the interpreter's CWD tracking"
|
|
247
|
+
},
|
|
248
|
+
// Diagnostic report (leaks full environment, host paths, system info)
|
|
249
|
+
{
|
|
250
|
+
prop: "report",
|
|
251
|
+
target: process,
|
|
252
|
+
violationType: "process_report",
|
|
253
|
+
strategy: "throw",
|
|
254
|
+
reason: "process.report could disclose full environment, host paths, and system info"
|
|
255
|
+
},
|
|
256
|
+
// Environment file loading (Node 21.7+)
|
|
257
|
+
{
|
|
258
|
+
prop: "loadEnvFile",
|
|
259
|
+
target: process,
|
|
260
|
+
violationType: "process_env",
|
|
261
|
+
strategy: "throw",
|
|
262
|
+
reason: "process.loadEnvFile could load env files bypassing env proxy"
|
|
263
|
+
},
|
|
264
|
+
// Exception handler manipulation
|
|
265
|
+
{
|
|
266
|
+
prop: "setUncaughtExceptionCaptureCallback",
|
|
267
|
+
target: process,
|
|
268
|
+
violationType: "process_exception_handler",
|
|
269
|
+
strategy: "throw",
|
|
270
|
+
reason: "setUncaughtExceptionCaptureCallback could intercept security errors"
|
|
271
|
+
},
|
|
272
|
+
// IPC communication vectors (may be undefined in non-IPC contexts)
|
|
273
|
+
{
|
|
274
|
+
prop: "send",
|
|
275
|
+
target: process,
|
|
276
|
+
violationType: "process_send",
|
|
277
|
+
strategy: "throw",
|
|
278
|
+
reason: "process.send could communicate with parent process in IPC contexts"
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
prop: "channel",
|
|
282
|
+
target: process,
|
|
283
|
+
violationType: "process_channel",
|
|
284
|
+
strategy: "throw",
|
|
285
|
+
reason: "process.channel could access IPC channel to parent process"
|
|
286
|
+
},
|
|
287
|
+
// Timing side-channel vectors
|
|
288
|
+
{
|
|
289
|
+
prop: "cpuUsage",
|
|
290
|
+
target: process,
|
|
291
|
+
violationType: "process_timing",
|
|
292
|
+
strategy: "throw",
|
|
293
|
+
reason: "process.cpuUsage could enable timing side-channel attacks"
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
prop: "memoryUsage",
|
|
297
|
+
target: process,
|
|
298
|
+
violationType: "process_timing",
|
|
299
|
+
strategy: "throw",
|
|
300
|
+
reason: "process.memoryUsage could enable timing side-channel attacks"
|
|
301
|
+
},
|
|
302
|
+
{
|
|
303
|
+
prop: "hrtime",
|
|
304
|
+
target: process,
|
|
305
|
+
violationType: "process_timing",
|
|
306
|
+
strategy: "throw",
|
|
307
|
+
reason: "process.hrtime could enable timing side-channel attacks"
|
|
308
|
+
},
|
|
309
|
+
// We also don't block `require` because:
|
|
310
|
+
// 1. It may not exist in all environments (ESM)
|
|
311
|
+
// 2. import() is the modern escape vector and can't be blocked this way
|
|
312
|
+
// Reference leak vectors
|
|
313
|
+
{
|
|
314
|
+
prop: "WeakRef",
|
|
315
|
+
target: globalThis,
|
|
316
|
+
violationType: "weak_ref",
|
|
317
|
+
strategy: "throw",
|
|
318
|
+
reason: "WeakRef could be used to leak references outside sandbox"
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
prop: "FinalizationRegistry",
|
|
322
|
+
target: globalThis,
|
|
323
|
+
violationType: "finalization_registry",
|
|
324
|
+
strategy: "throw",
|
|
325
|
+
reason: "FinalizationRegistry could be used to leak references outside sandbox"
|
|
326
|
+
},
|
|
327
|
+
// Introspection/interception vectors (freeze instead of throw)
|
|
328
|
+
// SECURITY RATIONALE: Reflect is frozen (not blocked) because:
|
|
329
|
+
// 1. Defense infrastructure uses Reflect.apply/get/set/construct internally
|
|
330
|
+
// 2. Frozen Reflect cannot be mutated but remains fully functional
|
|
331
|
+
// 3. Reflect.construct(Function, ['code']) IS safe because globalThis.Function
|
|
332
|
+
// is replaced with a blocking proxy — Reflect.construct receives the proxy
|
|
333
|
+
// 4. Security depends on NEVER leaking original Function/eval references.
|
|
334
|
+
// If an unpatched Function ref leaked, Reflect.construct would bypass defense.
|
|
335
|
+
{
|
|
336
|
+
prop: "Reflect",
|
|
337
|
+
target: globalThis,
|
|
338
|
+
violationType: "reflect",
|
|
339
|
+
strategy: "freeze",
|
|
340
|
+
reason: "Reflect provides introspection capabilities"
|
|
341
|
+
},
|
|
342
|
+
{
|
|
343
|
+
prop: "Proxy",
|
|
344
|
+
target: globalThis,
|
|
345
|
+
violationType: "proxy",
|
|
346
|
+
strategy: "throw",
|
|
347
|
+
reason: "Proxy allows intercepting and modifying object behavior"
|
|
348
|
+
},
|
|
349
|
+
// WebAssembly allows arbitrary code execution
|
|
350
|
+
{
|
|
351
|
+
prop: "WebAssembly",
|
|
352
|
+
target: globalThis,
|
|
353
|
+
violationType: "webassembly",
|
|
354
|
+
strategy: "throw",
|
|
355
|
+
reason: "WebAssembly allows executing arbitrary compiled code"
|
|
356
|
+
},
|
|
357
|
+
// SharedArrayBuffer and Atomics can enable side-channel attacks
|
|
358
|
+
{
|
|
359
|
+
prop: "SharedArrayBuffer",
|
|
360
|
+
target: globalThis,
|
|
361
|
+
violationType: "shared_array_buffer",
|
|
362
|
+
strategy: "throw",
|
|
363
|
+
reason: "SharedArrayBuffer could enable side-channel communication or timing attacks"
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
prop: "Atomics",
|
|
367
|
+
target: globalThis,
|
|
368
|
+
violationType: "atomics",
|
|
369
|
+
strategy: "throw",
|
|
370
|
+
reason: "Atomics could enable side-channel communication or timing attacks"
|
|
371
|
+
},
|
|
372
|
+
// Note: Error.prepareStackTrace is handled specially in defense-in-depth-box.ts
|
|
373
|
+
// because we only want to block SETTING it, not reading (V8 reads it internally)
|
|
374
|
+
// Timing side-channel: performance.now() provides sub-millisecond resolution
|
|
375
|
+
// Note: Date.now() is intentionally NOT blocked — it's used for $SECONDS,
|
|
376
|
+
// date command, and has only ~1ms resolution (vs process.hrtime at ns).
|
|
377
|
+
{
|
|
378
|
+
prop: "performance",
|
|
379
|
+
target: globalThis,
|
|
380
|
+
violationType: "performance_timing",
|
|
381
|
+
strategy: "throw",
|
|
382
|
+
reason: "performance.now() provides sub-millisecond timing for side-channel attacks"
|
|
383
|
+
},
|
|
384
|
+
// Block direct access to process.stdout and process.stderr to prevent
|
|
385
|
+
// writing to the host's actual stdout/stderr, bypassing the interpreter's
|
|
386
|
+
// output accumulation.
|
|
387
|
+
{
|
|
388
|
+
prop: "stdout",
|
|
389
|
+
target: process,
|
|
390
|
+
violationType: "process_stdout",
|
|
391
|
+
strategy: "throw",
|
|
392
|
+
reason: "process.stdout could bypass interpreter output to write to host stdout"
|
|
393
|
+
},
|
|
394
|
+
{
|
|
395
|
+
prop: "stderr",
|
|
396
|
+
target: process,
|
|
397
|
+
violationType: "process_stderr",
|
|
398
|
+
strategy: "throw",
|
|
399
|
+
reason: "process.stderr could bypass interpreter output to write to host stderr"
|
|
400
|
+
},
|
|
401
|
+
// Prototype pollution vectors
|
|
402
|
+
{
|
|
403
|
+
prop: "__defineGetter__",
|
|
404
|
+
target: Object.prototype,
|
|
405
|
+
violationType: "prototype_mutation",
|
|
406
|
+
strategy: "throw",
|
|
407
|
+
reason: "__defineGetter__ allows prototype pollution via getter injection"
|
|
408
|
+
},
|
|
409
|
+
{
|
|
410
|
+
prop: "__defineSetter__",
|
|
411
|
+
target: Object.prototype,
|
|
412
|
+
violationType: "prototype_mutation",
|
|
413
|
+
strategy: "throw",
|
|
414
|
+
reason: "__defineSetter__ allows prototype pollution via setter injection"
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
prop: "__lookupGetter__",
|
|
418
|
+
target: Object.prototype,
|
|
419
|
+
violationType: "prototype_mutation",
|
|
420
|
+
strategy: "throw",
|
|
421
|
+
reason: "__lookupGetter__ enables introspection for prototype pollution attacks"
|
|
422
|
+
},
|
|
423
|
+
{
|
|
424
|
+
prop: "__lookupSetter__",
|
|
425
|
+
target: Object.prototype,
|
|
426
|
+
violationType: "prototype_mutation",
|
|
427
|
+
strategy: "throw",
|
|
428
|
+
reason: "__lookupSetter__ enables introspection for prototype pollution attacks"
|
|
429
|
+
},
|
|
430
|
+
// Freeze JSON and Math to prevent mutation of built-in utility objects
|
|
431
|
+
{
|
|
432
|
+
prop: "JSON",
|
|
433
|
+
target: globalThis,
|
|
434
|
+
violationType: "json_mutation",
|
|
435
|
+
strategy: "freeze",
|
|
436
|
+
reason: "Freeze JSON to prevent mutation of parsing/serialization"
|
|
437
|
+
},
|
|
438
|
+
{
|
|
439
|
+
prop: "Math",
|
|
440
|
+
target: globalThis,
|
|
441
|
+
violationType: "math_mutation",
|
|
442
|
+
strategy: "freeze",
|
|
443
|
+
reason: "Freeze Math to prevent mutation of math utilities"
|
|
444
|
+
}
|
|
445
|
+
];
|
|
446
|
+
try {
|
|
447
|
+
const AsyncFunction = Object.getPrototypeOf(async () => {
|
|
448
|
+
}).constructor;
|
|
449
|
+
if (AsyncFunction && AsyncFunction !== Function) {
|
|
450
|
+
globals.push({
|
|
451
|
+
prop: "constructor",
|
|
452
|
+
target: Object.getPrototypeOf(async () => {
|
|
453
|
+
}),
|
|
454
|
+
violationType: "async_function_constructor",
|
|
455
|
+
strategy: "throw",
|
|
456
|
+
reason: "AsyncFunction constructor allows arbitrary async code execution"
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
} catch {
|
|
460
|
+
}
|
|
461
|
+
try {
|
|
462
|
+
const GeneratorFunction = Object.getPrototypeOf(
|
|
463
|
+
function* () {
|
|
464
|
+
}
|
|
465
|
+
).constructor;
|
|
466
|
+
if (GeneratorFunction && GeneratorFunction !== Function) {
|
|
467
|
+
globals.push({
|
|
468
|
+
prop: "constructor",
|
|
469
|
+
target: Object.getPrototypeOf(function* () {
|
|
470
|
+
}),
|
|
471
|
+
violationType: "generator_function_constructor",
|
|
472
|
+
strategy: "throw",
|
|
473
|
+
reason: "GeneratorFunction constructor allows arbitrary generator code execution"
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
} catch {
|
|
477
|
+
}
|
|
478
|
+
try {
|
|
479
|
+
const AsyncGeneratorFunction = Object.getPrototypeOf(
|
|
480
|
+
async function* () {
|
|
481
|
+
}
|
|
482
|
+
).constructor;
|
|
483
|
+
if (AsyncGeneratorFunction && AsyncGeneratorFunction !== Function && AsyncGeneratorFunction !== Object.getPrototypeOf(async () => {
|
|
484
|
+
}).constructor) {
|
|
485
|
+
globals.push({
|
|
486
|
+
prop: "constructor",
|
|
487
|
+
target: Object.getPrototypeOf(async function* () {
|
|
488
|
+
}),
|
|
489
|
+
violationType: "async_generator_function_constructor",
|
|
490
|
+
strategy: "throw",
|
|
491
|
+
reason: "AsyncGeneratorFunction constructor allows arbitrary async generator code execution"
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
} catch {
|
|
495
|
+
}
|
|
496
|
+
return globals.filter((g) => {
|
|
497
|
+
try {
|
|
498
|
+
return g.target[g.prop] !== void 0;
|
|
499
|
+
} catch {
|
|
500
|
+
return false;
|
|
501
|
+
}
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// src/security/defense-in-depth-box.ts
|
|
506
|
+
var IS_BROWSER = typeof __BROWSER__ !== "undefined" && __BROWSER__;
|
|
507
|
+
var AsyncLocalStorageClass = null;
|
|
508
|
+
if (!IS_BROWSER) {
|
|
509
|
+
try {
|
|
510
|
+
const { AsyncLocalStorage } = __require("node:async_hooks");
|
|
511
|
+
AsyncLocalStorageClass = AsyncLocalStorage;
|
|
512
|
+
} catch {
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
var executionContext = !IS_BROWSER && AsyncLocalStorageClass ? new AsyncLocalStorageClass() : null;
|
|
516
|
+
|
|
517
|
+
// src/security/worker-defense-in-depth.ts
|
|
518
|
+
var DEFENSE_IN_DEPTH_NOTICE = "\n\nThis is a defense-in-depth measure and indicates a bug in just-bash. Please report this at security@vercel.com";
|
|
519
|
+
var WorkerSecurityViolationError = class extends Error {
|
|
520
|
+
constructor(message, violation) {
|
|
521
|
+
super(message + DEFENSE_IN_DEPTH_NOTICE);
|
|
522
|
+
this.violation = violation;
|
|
523
|
+
this.name = "WorkerSecurityViolationError";
|
|
524
|
+
}
|
|
525
|
+
violation;
|
|
526
|
+
};
|
|
527
|
+
var MAX_STORED_VIOLATIONS = 1e3;
|
|
528
|
+
function generateExecutionId() {
|
|
529
|
+
if (typeof crypto !== "undefined" && crypto.randomUUID) {
|
|
530
|
+
return crypto.randomUUID();
|
|
531
|
+
}
|
|
532
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
533
|
+
const r = Math.random() * 16 | 0;
|
|
534
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
535
|
+
return v.toString(16);
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
var WorkerDefenseInDepth = class {
|
|
539
|
+
config;
|
|
540
|
+
isActivated = false;
|
|
541
|
+
originalDescriptors = [];
|
|
542
|
+
violations = [];
|
|
543
|
+
executionId;
|
|
544
|
+
/**
|
|
545
|
+
* Original Proxy constructor, captured before patching.
|
|
546
|
+
* This is captured at instance creation time to ensure we get the unpatched version.
|
|
547
|
+
*/
|
|
548
|
+
originalProxy;
|
|
549
|
+
/**
|
|
550
|
+
* Recursion guard to prevent infinite loops when proxy traps trigger
|
|
551
|
+
* code that accesses the same proxied object (e.g., process.env).
|
|
552
|
+
*/
|
|
553
|
+
inTrap = false;
|
|
554
|
+
/**
|
|
555
|
+
* Create and activate the worker defense layer.
|
|
556
|
+
*
|
|
557
|
+
* @param config - Configuration for the defense layer
|
|
558
|
+
*/
|
|
559
|
+
constructor(config) {
|
|
560
|
+
this.originalProxy = Proxy;
|
|
561
|
+
this.config = config;
|
|
562
|
+
this.executionId = generateExecutionId();
|
|
563
|
+
if (config.enabled !== false) {
|
|
564
|
+
this.activate();
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Get statistics about the defense layer.
|
|
569
|
+
*/
|
|
570
|
+
getStats() {
|
|
571
|
+
return {
|
|
572
|
+
violationsBlocked: this.violations.length,
|
|
573
|
+
violations: [...this.violations],
|
|
574
|
+
isActive: this.isActivated
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Clear stored violations. Useful for testing.
|
|
579
|
+
*/
|
|
580
|
+
clearViolations() {
|
|
581
|
+
this.violations = [];
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Get the execution ID for this worker.
|
|
585
|
+
*/
|
|
586
|
+
getExecutionId() {
|
|
587
|
+
return this.executionId;
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Deactivate the defense layer and restore original globals.
|
|
591
|
+
* Typically only needed for testing.
|
|
592
|
+
*/
|
|
593
|
+
deactivate() {
|
|
594
|
+
if (!this.isActivated) {
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
this.restorePatches();
|
|
598
|
+
this.isActivated = false;
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Activate the defense layer by applying patches.
|
|
602
|
+
*/
|
|
603
|
+
activate() {
|
|
604
|
+
if (this.isActivated) {
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
this.applyPatches();
|
|
608
|
+
this.isActivated = true;
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* Get a human-readable path for a target object and property.
|
|
612
|
+
*/
|
|
613
|
+
getPathForTarget(target, prop) {
|
|
614
|
+
if (target === globalThis) {
|
|
615
|
+
return `globalThis.${prop}`;
|
|
616
|
+
}
|
|
617
|
+
if (typeof process !== "undefined" && target === process) {
|
|
618
|
+
return `process.${prop}`;
|
|
619
|
+
}
|
|
620
|
+
if (target === Error) {
|
|
621
|
+
return `Error.${prop}`;
|
|
622
|
+
}
|
|
623
|
+
if (target === Function.prototype) {
|
|
624
|
+
return `Function.prototype.${prop}`;
|
|
625
|
+
}
|
|
626
|
+
if (target === Object.prototype) {
|
|
627
|
+
return `Object.prototype.${prop}`;
|
|
628
|
+
}
|
|
629
|
+
return `<object>.${prop}`;
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* Record a violation and invoke the callback.
|
|
633
|
+
* In worker context, blocking always happens (no audit mode context check).
|
|
634
|
+
*/
|
|
635
|
+
recordViolation(type, path, message) {
|
|
636
|
+
const violation = {
|
|
637
|
+
timestamp: Date.now(),
|
|
638
|
+
type,
|
|
639
|
+
message,
|
|
640
|
+
path,
|
|
641
|
+
stack: new Error().stack,
|
|
642
|
+
executionId: this.executionId
|
|
643
|
+
};
|
|
644
|
+
if (this.violations.length < MAX_STORED_VIOLATIONS) {
|
|
645
|
+
this.violations.push(violation);
|
|
646
|
+
}
|
|
647
|
+
if (this.config.onViolation) {
|
|
648
|
+
try {
|
|
649
|
+
this.config.onViolation(violation);
|
|
650
|
+
} catch (e) {
|
|
651
|
+
console.debug(
|
|
652
|
+
"[WorkerDefenseInDepth] onViolation callback threw:",
|
|
653
|
+
e instanceof Error ? e.message : e
|
|
654
|
+
);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
return violation;
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* Create a blocking proxy for a function.
|
|
661
|
+
* In worker context, always blocks (no context check needed).
|
|
662
|
+
*/
|
|
663
|
+
createBlockingProxy(original, path, violationType) {
|
|
664
|
+
const self = this;
|
|
665
|
+
const auditMode = this.config.auditMode;
|
|
666
|
+
return new this.originalProxy(original, {
|
|
667
|
+
apply(target, thisArg, args) {
|
|
668
|
+
const message = `${path} is blocked in worker context`;
|
|
669
|
+
const violation = self.recordViolation(violationType, path, message);
|
|
670
|
+
if (!auditMode) {
|
|
671
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
672
|
+
}
|
|
673
|
+
return Reflect.apply(target, thisArg, args);
|
|
674
|
+
},
|
|
675
|
+
construct(target, args, newTarget) {
|
|
676
|
+
const message = `${path} constructor is blocked in worker context`;
|
|
677
|
+
const violation = self.recordViolation(violationType, path, message);
|
|
678
|
+
if (!auditMode) {
|
|
679
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
680
|
+
}
|
|
681
|
+
return Reflect.construct(target, args, newTarget);
|
|
682
|
+
}
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
/**
|
|
686
|
+
* Create a blocking proxy for an object (blocks all property access).
|
|
687
|
+
*/
|
|
688
|
+
createBlockingObjectProxy(original, path, violationType, allowedKeys) {
|
|
689
|
+
const self = this;
|
|
690
|
+
const auditMode = this.config.auditMode;
|
|
691
|
+
return new this.originalProxy(original, {
|
|
692
|
+
get(target, prop, receiver) {
|
|
693
|
+
if (self.inTrap) {
|
|
694
|
+
return Reflect.get(target, prop, receiver);
|
|
695
|
+
}
|
|
696
|
+
if (allowedKeys && typeof prop === "string" && allowedKeys.has(prop)) {
|
|
697
|
+
return Reflect.get(target, prop, receiver);
|
|
698
|
+
}
|
|
699
|
+
self.inTrap = true;
|
|
700
|
+
try {
|
|
701
|
+
const fullPath = `${path}.${String(prop)}`;
|
|
702
|
+
const message = `${fullPath} is blocked in worker context`;
|
|
703
|
+
const violation = self.recordViolation(
|
|
704
|
+
violationType,
|
|
705
|
+
fullPath,
|
|
706
|
+
message
|
|
707
|
+
);
|
|
708
|
+
if (!auditMode) {
|
|
709
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
710
|
+
}
|
|
711
|
+
return Reflect.get(target, prop, receiver);
|
|
712
|
+
} finally {
|
|
713
|
+
self.inTrap = false;
|
|
714
|
+
}
|
|
715
|
+
},
|
|
716
|
+
set(target, prop, value, receiver) {
|
|
717
|
+
if (self.inTrap) {
|
|
718
|
+
return Reflect.set(target, prop, value, receiver);
|
|
719
|
+
}
|
|
720
|
+
self.inTrap = true;
|
|
721
|
+
try {
|
|
722
|
+
const fullPath = `${path}.${String(prop)}`;
|
|
723
|
+
const message = `${fullPath} modification is blocked in worker context`;
|
|
724
|
+
const violation = self.recordViolation(
|
|
725
|
+
violationType,
|
|
726
|
+
fullPath,
|
|
727
|
+
message
|
|
728
|
+
);
|
|
729
|
+
if (!auditMode) {
|
|
730
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
731
|
+
}
|
|
732
|
+
return Reflect.set(target, prop, value, receiver);
|
|
733
|
+
} finally {
|
|
734
|
+
self.inTrap = false;
|
|
735
|
+
}
|
|
736
|
+
},
|
|
737
|
+
ownKeys(target) {
|
|
738
|
+
if (self.inTrap) {
|
|
739
|
+
return Reflect.ownKeys(target);
|
|
740
|
+
}
|
|
741
|
+
self.inTrap = true;
|
|
742
|
+
try {
|
|
743
|
+
const message = `${path} enumeration is blocked in worker context`;
|
|
744
|
+
const violation = self.recordViolation(violationType, path, message);
|
|
745
|
+
if (!auditMode) {
|
|
746
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
747
|
+
}
|
|
748
|
+
return Reflect.ownKeys(target);
|
|
749
|
+
} finally {
|
|
750
|
+
self.inTrap = false;
|
|
751
|
+
}
|
|
752
|
+
},
|
|
753
|
+
getOwnPropertyDescriptor(target, prop) {
|
|
754
|
+
if (self.inTrap) {
|
|
755
|
+
return Reflect.getOwnPropertyDescriptor(target, prop);
|
|
756
|
+
}
|
|
757
|
+
self.inTrap = true;
|
|
758
|
+
try {
|
|
759
|
+
const fullPath = `${path}.${String(prop)}`;
|
|
760
|
+
const message = `${fullPath} descriptor access is blocked in worker context`;
|
|
761
|
+
const violation = self.recordViolation(
|
|
762
|
+
violationType,
|
|
763
|
+
fullPath,
|
|
764
|
+
message
|
|
765
|
+
);
|
|
766
|
+
if (!auditMode) {
|
|
767
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
768
|
+
}
|
|
769
|
+
return Reflect.getOwnPropertyDescriptor(target, prop);
|
|
770
|
+
} finally {
|
|
771
|
+
self.inTrap = false;
|
|
772
|
+
}
|
|
773
|
+
},
|
|
774
|
+
has(target, prop) {
|
|
775
|
+
if (self.inTrap) {
|
|
776
|
+
return Reflect.has(target, prop);
|
|
777
|
+
}
|
|
778
|
+
self.inTrap = true;
|
|
779
|
+
try {
|
|
780
|
+
const fullPath = `${path}.${String(prop)}`;
|
|
781
|
+
const message = `${fullPath} existence check is blocked in worker context`;
|
|
782
|
+
const violation = self.recordViolation(
|
|
783
|
+
violationType,
|
|
784
|
+
fullPath,
|
|
785
|
+
message
|
|
786
|
+
);
|
|
787
|
+
if (!auditMode) {
|
|
788
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
789
|
+
}
|
|
790
|
+
return Reflect.has(target, prop);
|
|
791
|
+
} finally {
|
|
792
|
+
self.inTrap = false;
|
|
793
|
+
}
|
|
794
|
+
},
|
|
795
|
+
deleteProperty(target, prop) {
|
|
796
|
+
if (self.inTrap) {
|
|
797
|
+
return Reflect.deleteProperty(target, prop);
|
|
798
|
+
}
|
|
799
|
+
self.inTrap = true;
|
|
800
|
+
try {
|
|
801
|
+
const fullPath = `${path}.${String(prop)}`;
|
|
802
|
+
const message = `${fullPath} deletion is blocked in worker context`;
|
|
803
|
+
const violation = self.recordViolation(
|
|
804
|
+
violationType,
|
|
805
|
+
fullPath,
|
|
806
|
+
message
|
|
807
|
+
);
|
|
808
|
+
if (!auditMode) {
|
|
809
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
810
|
+
}
|
|
811
|
+
return Reflect.deleteProperty(target, prop);
|
|
812
|
+
} finally {
|
|
813
|
+
self.inTrap = false;
|
|
814
|
+
}
|
|
815
|
+
},
|
|
816
|
+
setPrototypeOf(target, proto) {
|
|
817
|
+
if (self.inTrap) {
|
|
818
|
+
return Reflect.setPrototypeOf(target, proto);
|
|
819
|
+
}
|
|
820
|
+
self.inTrap = true;
|
|
821
|
+
try {
|
|
822
|
+
const message = `${path} setPrototypeOf is blocked in worker context`;
|
|
823
|
+
const violation = self.recordViolation(violationType, path, message);
|
|
824
|
+
if (!auditMode) {
|
|
825
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
826
|
+
}
|
|
827
|
+
return Reflect.setPrototypeOf(target, proto);
|
|
828
|
+
} finally {
|
|
829
|
+
self.inTrap = false;
|
|
830
|
+
}
|
|
831
|
+
},
|
|
832
|
+
defineProperty(target, prop, descriptor) {
|
|
833
|
+
if (self.inTrap) {
|
|
834
|
+
return Reflect.defineProperty(target, prop, descriptor);
|
|
835
|
+
}
|
|
836
|
+
self.inTrap = true;
|
|
837
|
+
try {
|
|
838
|
+
const fullPath = `${path}.${String(prop)}`;
|
|
839
|
+
const message = `${fullPath} defineProperty is blocked in worker context`;
|
|
840
|
+
const violation = self.recordViolation(
|
|
841
|
+
violationType,
|
|
842
|
+
fullPath,
|
|
843
|
+
message
|
|
844
|
+
);
|
|
845
|
+
if (!auditMode) {
|
|
846
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
847
|
+
}
|
|
848
|
+
return Reflect.defineProperty(target, prop, descriptor);
|
|
849
|
+
} finally {
|
|
850
|
+
self.inTrap = false;
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
});
|
|
854
|
+
}
|
|
855
|
+
/**
|
|
856
|
+
* Apply security patches to dangerous globals.
|
|
857
|
+
*/
|
|
858
|
+
applyPatches() {
|
|
859
|
+
const blockedGlobals = getBlockedGlobals();
|
|
860
|
+
const excludeTypes = new Set(this.config.excludeViolationTypes ?? []);
|
|
861
|
+
for (const blocked of blockedGlobals) {
|
|
862
|
+
if (excludeTypes.has(blocked.violationType)) {
|
|
863
|
+
continue;
|
|
864
|
+
}
|
|
865
|
+
this.applyPatch(blocked);
|
|
866
|
+
}
|
|
867
|
+
if (!excludeTypes.has("function_constructor")) {
|
|
868
|
+
this.protectConstructorChain(excludeTypes);
|
|
869
|
+
}
|
|
870
|
+
if (!excludeTypes.has("error_prepare_stack_trace")) {
|
|
871
|
+
this.protectErrorPrepareStackTrace();
|
|
872
|
+
}
|
|
873
|
+
if (!excludeTypes.has("module_load")) {
|
|
874
|
+
this.protectModuleLoad();
|
|
875
|
+
}
|
|
876
|
+
if (!excludeTypes.has("module_resolve_filename")) {
|
|
877
|
+
this.protectModuleResolveFilename();
|
|
878
|
+
}
|
|
879
|
+
if (!excludeTypes.has("process_main_module")) {
|
|
880
|
+
this.protectProcessMainModule();
|
|
881
|
+
}
|
|
882
|
+
if (!excludeTypes.has("process_exec_path")) {
|
|
883
|
+
this.protectProcessExecPath();
|
|
884
|
+
}
|
|
885
|
+
if (!excludeTypes.has("process_connected")) {
|
|
886
|
+
this.protectProcessConnected();
|
|
887
|
+
}
|
|
888
|
+
this.lockWellKnownSymbols();
|
|
889
|
+
if (!excludeTypes.has("proxy")) {
|
|
890
|
+
this.protectProxyRevocable();
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
/**
|
|
894
|
+
* Lock well-known Symbol properties on built-in constructors/prototypes.
|
|
895
|
+
*/
|
|
896
|
+
lockWellKnownSymbols() {
|
|
897
|
+
const lock = (obj, sym) => {
|
|
898
|
+
try {
|
|
899
|
+
const desc = Object.getOwnPropertyDescriptor(obj, sym);
|
|
900
|
+
if (desc?.configurable) {
|
|
901
|
+
if ("value" in desc) {
|
|
902
|
+
Object.defineProperty(obj, sym, {
|
|
903
|
+
...desc,
|
|
904
|
+
configurable: false,
|
|
905
|
+
writable: false
|
|
906
|
+
});
|
|
907
|
+
return;
|
|
908
|
+
}
|
|
909
|
+
Object.defineProperty(obj, sym, { ...desc, configurable: false });
|
|
910
|
+
}
|
|
911
|
+
} catch {
|
|
912
|
+
}
|
|
913
|
+
};
|
|
914
|
+
for (const ctor of [Array, Map, Set, RegExp, Promise]) {
|
|
915
|
+
lock(ctor, Symbol.species);
|
|
916
|
+
}
|
|
917
|
+
for (const proto of [
|
|
918
|
+
Array.prototype,
|
|
919
|
+
String.prototype,
|
|
920
|
+
Map.prototype,
|
|
921
|
+
Set.prototype
|
|
922
|
+
]) {
|
|
923
|
+
lock(proto, Symbol.iterator);
|
|
924
|
+
}
|
|
925
|
+
lock(Symbol.prototype, Symbol.toPrimitive);
|
|
926
|
+
lock(Date.prototype, Symbol.toPrimitive);
|
|
927
|
+
for (const sym of [
|
|
928
|
+
Symbol.match,
|
|
929
|
+
Symbol.matchAll,
|
|
930
|
+
Symbol.replace,
|
|
931
|
+
Symbol.search,
|
|
932
|
+
Symbol.split
|
|
933
|
+
]) {
|
|
934
|
+
lock(RegExp.prototype, sym);
|
|
935
|
+
}
|
|
936
|
+
lock(Function.prototype, Symbol.hasInstance);
|
|
937
|
+
lock(Array.prototype, Symbol.unscopables);
|
|
938
|
+
for (const proto of [
|
|
939
|
+
Map.prototype,
|
|
940
|
+
Set.prototype,
|
|
941
|
+
Promise.prototype,
|
|
942
|
+
ArrayBuffer.prototype
|
|
943
|
+
]) {
|
|
944
|
+
lock(proto, Symbol.toStringTag);
|
|
945
|
+
}
|
|
946
|
+
try {
|
|
947
|
+
const stackDesc = Object.getOwnPropertyDescriptor(
|
|
948
|
+
Error,
|
|
949
|
+
"stackTraceLimit"
|
|
950
|
+
);
|
|
951
|
+
this.originalDescriptors.push({
|
|
952
|
+
target: Error,
|
|
953
|
+
prop: "stackTraceLimit",
|
|
954
|
+
descriptor: stackDesc
|
|
955
|
+
});
|
|
956
|
+
Object.defineProperty(Error, "stackTraceLimit", {
|
|
957
|
+
value: Error.stackTraceLimit,
|
|
958
|
+
writable: false,
|
|
959
|
+
configurable: true
|
|
960
|
+
});
|
|
961
|
+
} catch {
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
/**
|
|
965
|
+
* Block Proxy.revocable to prevent bypassing Proxy constructor blocking.
|
|
966
|
+
*
|
|
967
|
+
* Proxy.revocable internally uses the real Proxy constructor, so it bypasses
|
|
968
|
+
* our blocking proxy on globalThis.Proxy. We replace it with a wrapper that
|
|
969
|
+
* always blocks in worker context.
|
|
970
|
+
*/
|
|
971
|
+
protectProxyRevocable() {
|
|
972
|
+
const self = this;
|
|
973
|
+
const auditMode = this.config.auditMode;
|
|
974
|
+
try {
|
|
975
|
+
const originalRevocable = this.originalProxy.revocable;
|
|
976
|
+
if (typeof originalRevocable !== "function") return;
|
|
977
|
+
const descriptor = Object.getOwnPropertyDescriptor(
|
|
978
|
+
this.originalProxy,
|
|
979
|
+
"revocable"
|
|
980
|
+
);
|
|
981
|
+
this.originalDescriptors.push({
|
|
982
|
+
target: this.originalProxy,
|
|
983
|
+
prop: "revocable",
|
|
984
|
+
descriptor
|
|
985
|
+
});
|
|
986
|
+
Object.defineProperty(this.originalProxy, "revocable", {
|
|
987
|
+
value: function revocable(_target, _handler) {
|
|
988
|
+
const message = "Proxy.revocable is blocked in worker context";
|
|
989
|
+
const violation = self.recordViolation(
|
|
990
|
+
"proxy",
|
|
991
|
+
"Proxy.revocable",
|
|
992
|
+
message
|
|
993
|
+
);
|
|
994
|
+
if (!auditMode) {
|
|
995
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
996
|
+
}
|
|
997
|
+
return originalRevocable(_target, _handler);
|
|
998
|
+
},
|
|
999
|
+
writable: false,
|
|
1000
|
+
configurable: true
|
|
1001
|
+
// Must be configurable for restoration
|
|
1002
|
+
});
|
|
1003
|
+
} catch {
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
/**
|
|
1007
|
+
* Protect against .constructor.constructor escape vector.
|
|
1008
|
+
* @param excludeTypes - Set of violation types to skip
|
|
1009
|
+
*/
|
|
1010
|
+
protectConstructorChain(excludeTypes) {
|
|
1011
|
+
let AsyncFunction = null;
|
|
1012
|
+
let GeneratorFunction = null;
|
|
1013
|
+
let AsyncGeneratorFunction = null;
|
|
1014
|
+
try {
|
|
1015
|
+
AsyncFunction = Object.getPrototypeOf(async () => {
|
|
1016
|
+
}).constructor;
|
|
1017
|
+
} catch {
|
|
1018
|
+
}
|
|
1019
|
+
try {
|
|
1020
|
+
GeneratorFunction = Object.getPrototypeOf(function* () {
|
|
1021
|
+
}).constructor;
|
|
1022
|
+
} catch {
|
|
1023
|
+
}
|
|
1024
|
+
try {
|
|
1025
|
+
AsyncGeneratorFunction = Object.getPrototypeOf(
|
|
1026
|
+
async function* () {
|
|
1027
|
+
}
|
|
1028
|
+
).constructor;
|
|
1029
|
+
} catch {
|
|
1030
|
+
}
|
|
1031
|
+
this.patchPrototypeConstructor(
|
|
1032
|
+
Function.prototype,
|
|
1033
|
+
"Function.prototype.constructor",
|
|
1034
|
+
"function_constructor"
|
|
1035
|
+
);
|
|
1036
|
+
if (!excludeTypes.has("async_function_constructor") && AsyncFunction && AsyncFunction !== Function) {
|
|
1037
|
+
this.patchPrototypeConstructor(
|
|
1038
|
+
AsyncFunction.prototype,
|
|
1039
|
+
"AsyncFunction.prototype.constructor",
|
|
1040
|
+
"async_function_constructor"
|
|
1041
|
+
);
|
|
1042
|
+
}
|
|
1043
|
+
if (!excludeTypes.has("generator_function_constructor") && GeneratorFunction && GeneratorFunction !== Function) {
|
|
1044
|
+
this.patchPrototypeConstructor(
|
|
1045
|
+
GeneratorFunction.prototype,
|
|
1046
|
+
"GeneratorFunction.prototype.constructor",
|
|
1047
|
+
"generator_function_constructor"
|
|
1048
|
+
);
|
|
1049
|
+
}
|
|
1050
|
+
if (!excludeTypes.has("async_generator_function_constructor") && AsyncGeneratorFunction && AsyncGeneratorFunction !== Function && AsyncGeneratorFunction !== AsyncFunction) {
|
|
1051
|
+
this.patchPrototypeConstructor(
|
|
1052
|
+
AsyncGeneratorFunction.prototype,
|
|
1053
|
+
"AsyncGeneratorFunction.prototype.constructor",
|
|
1054
|
+
"async_generator_function_constructor"
|
|
1055
|
+
);
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
/**
|
|
1059
|
+
* Protect Error.prepareStackTrace from being set.
|
|
1060
|
+
*/
|
|
1061
|
+
protectErrorPrepareStackTrace() {
|
|
1062
|
+
const self = this;
|
|
1063
|
+
const auditMode = this.config.auditMode;
|
|
1064
|
+
try {
|
|
1065
|
+
const originalDescriptor = Object.getOwnPropertyDescriptor(
|
|
1066
|
+
Error,
|
|
1067
|
+
"prepareStackTrace"
|
|
1068
|
+
);
|
|
1069
|
+
this.originalDescriptors.push({
|
|
1070
|
+
target: Error,
|
|
1071
|
+
prop: "prepareStackTrace",
|
|
1072
|
+
descriptor: originalDescriptor
|
|
1073
|
+
});
|
|
1074
|
+
let currentValue = originalDescriptor?.value;
|
|
1075
|
+
Object.defineProperty(Error, "prepareStackTrace", {
|
|
1076
|
+
get() {
|
|
1077
|
+
return currentValue;
|
|
1078
|
+
},
|
|
1079
|
+
set(value) {
|
|
1080
|
+
const message = "Error.prepareStackTrace modification is blocked in worker context";
|
|
1081
|
+
const violation = self.recordViolation(
|
|
1082
|
+
"error_prepare_stack_trace",
|
|
1083
|
+
"Error.prepareStackTrace",
|
|
1084
|
+
message
|
|
1085
|
+
);
|
|
1086
|
+
if (!auditMode) {
|
|
1087
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
1088
|
+
}
|
|
1089
|
+
currentValue = value;
|
|
1090
|
+
},
|
|
1091
|
+
configurable: true
|
|
1092
|
+
});
|
|
1093
|
+
} catch {
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
/**
|
|
1097
|
+
* Patch a prototype's constructor property.
|
|
1098
|
+
*
|
|
1099
|
+
* Returns a proxy that allows reading properties (like .name) but blocks
|
|
1100
|
+
* calling the constructor as a function (which would allow code execution).
|
|
1101
|
+
*/
|
|
1102
|
+
patchPrototypeConstructor(prototype, path, violationType) {
|
|
1103
|
+
const self = this;
|
|
1104
|
+
const auditMode = this.config.auditMode;
|
|
1105
|
+
try {
|
|
1106
|
+
const originalDescriptor = Object.getOwnPropertyDescriptor(
|
|
1107
|
+
prototype,
|
|
1108
|
+
"constructor"
|
|
1109
|
+
);
|
|
1110
|
+
this.originalDescriptors.push({
|
|
1111
|
+
target: prototype,
|
|
1112
|
+
prop: "constructor",
|
|
1113
|
+
descriptor: originalDescriptor
|
|
1114
|
+
});
|
|
1115
|
+
const originalValue = originalDescriptor?.value;
|
|
1116
|
+
const constructorProxy = originalValue && typeof originalValue === "function" ? new this.originalProxy(originalValue, {
|
|
1117
|
+
apply(_target, _thisArg, _args) {
|
|
1118
|
+
const message = `${path} invocation is blocked in worker context`;
|
|
1119
|
+
const violation = self.recordViolation(
|
|
1120
|
+
violationType,
|
|
1121
|
+
path,
|
|
1122
|
+
message
|
|
1123
|
+
);
|
|
1124
|
+
if (!auditMode) {
|
|
1125
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
1126
|
+
}
|
|
1127
|
+
return void 0;
|
|
1128
|
+
},
|
|
1129
|
+
construct(_target, _args, _newTarget) {
|
|
1130
|
+
const message = `${path} construction is blocked in worker context`;
|
|
1131
|
+
const violation = self.recordViolation(
|
|
1132
|
+
violationType,
|
|
1133
|
+
path,
|
|
1134
|
+
message
|
|
1135
|
+
);
|
|
1136
|
+
if (!auditMode) {
|
|
1137
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
1138
|
+
}
|
|
1139
|
+
return {};
|
|
1140
|
+
},
|
|
1141
|
+
// Allow all property access (like .name, .prototype, etc.)
|
|
1142
|
+
get(target, prop, receiver) {
|
|
1143
|
+
return Reflect.get(target, prop, receiver);
|
|
1144
|
+
},
|
|
1145
|
+
getPrototypeOf(target) {
|
|
1146
|
+
return Reflect.getPrototypeOf(target);
|
|
1147
|
+
},
|
|
1148
|
+
has(target, prop) {
|
|
1149
|
+
return Reflect.has(target, prop);
|
|
1150
|
+
},
|
|
1151
|
+
ownKeys(target) {
|
|
1152
|
+
return Reflect.ownKeys(target);
|
|
1153
|
+
},
|
|
1154
|
+
getOwnPropertyDescriptor(target, prop) {
|
|
1155
|
+
return Reflect.getOwnPropertyDescriptor(target, prop);
|
|
1156
|
+
}
|
|
1157
|
+
}) : originalValue;
|
|
1158
|
+
Object.defineProperty(prototype, "constructor", {
|
|
1159
|
+
get() {
|
|
1160
|
+
return constructorProxy;
|
|
1161
|
+
},
|
|
1162
|
+
set(value) {
|
|
1163
|
+
const message = `${path} modification is blocked in worker context`;
|
|
1164
|
+
const violation = self.recordViolation(violationType, path, message);
|
|
1165
|
+
if (!auditMode) {
|
|
1166
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
1167
|
+
}
|
|
1168
|
+
Object.defineProperty(this, "constructor", {
|
|
1169
|
+
value,
|
|
1170
|
+
writable: true,
|
|
1171
|
+
configurable: true
|
|
1172
|
+
});
|
|
1173
|
+
},
|
|
1174
|
+
configurable: true
|
|
1175
|
+
});
|
|
1176
|
+
} catch {
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
/**
|
|
1180
|
+
* Protect process.mainModule from being accessed or set.
|
|
1181
|
+
*
|
|
1182
|
+
* The attack vector is:
|
|
1183
|
+
* ```
|
|
1184
|
+
* process.mainModule.require('child_process').execSync('whoami')
|
|
1185
|
+
* process.mainModule.constructor._load('vm')
|
|
1186
|
+
* ```
|
|
1187
|
+
*
|
|
1188
|
+
* process.mainModule may be undefined in ESM contexts but could exist in
|
|
1189
|
+
* CommonJS workers. We block both reading and setting.
|
|
1190
|
+
*/
|
|
1191
|
+
protectProcessMainModule() {
|
|
1192
|
+
if (typeof process === "undefined") return;
|
|
1193
|
+
const self = this;
|
|
1194
|
+
const auditMode = this.config.auditMode;
|
|
1195
|
+
try {
|
|
1196
|
+
const originalDescriptor = Object.getOwnPropertyDescriptor(
|
|
1197
|
+
process,
|
|
1198
|
+
"mainModule"
|
|
1199
|
+
);
|
|
1200
|
+
this.originalDescriptors.push({
|
|
1201
|
+
target: process,
|
|
1202
|
+
prop: "mainModule",
|
|
1203
|
+
descriptor: originalDescriptor
|
|
1204
|
+
});
|
|
1205
|
+
const currentValue = originalDescriptor?.value;
|
|
1206
|
+
if (currentValue !== void 0) {
|
|
1207
|
+
Object.defineProperty(process, "mainModule", {
|
|
1208
|
+
get() {
|
|
1209
|
+
const message = "process.mainModule access is blocked in worker context";
|
|
1210
|
+
const violation = self.recordViolation(
|
|
1211
|
+
"process_main_module",
|
|
1212
|
+
"process.mainModule",
|
|
1213
|
+
message
|
|
1214
|
+
);
|
|
1215
|
+
if (!auditMode) {
|
|
1216
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
1217
|
+
}
|
|
1218
|
+
return currentValue;
|
|
1219
|
+
},
|
|
1220
|
+
set(value) {
|
|
1221
|
+
const message = "process.mainModule modification is blocked in worker context";
|
|
1222
|
+
const violation = self.recordViolation(
|
|
1223
|
+
"process_main_module",
|
|
1224
|
+
"process.mainModule",
|
|
1225
|
+
message
|
|
1226
|
+
);
|
|
1227
|
+
if (!auditMode) {
|
|
1228
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
1229
|
+
}
|
|
1230
|
+
Object.defineProperty(process, "mainModule", {
|
|
1231
|
+
value,
|
|
1232
|
+
writable: true,
|
|
1233
|
+
configurable: true
|
|
1234
|
+
});
|
|
1235
|
+
},
|
|
1236
|
+
configurable: true
|
|
1237
|
+
});
|
|
1238
|
+
}
|
|
1239
|
+
} catch {
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
/**
|
|
1243
|
+
* Protect process.execPath from being read or set in worker context.
|
|
1244
|
+
*
|
|
1245
|
+
* process.execPath is a string primitive (not an object), so it cannot be
|
|
1246
|
+
* proxied via the normal blocked globals mechanism. We use Object.defineProperty
|
|
1247
|
+
* with getter/setter (same pattern as protectProcessMainModule).
|
|
1248
|
+
*/
|
|
1249
|
+
protectProcessExecPath() {
|
|
1250
|
+
if (typeof process === "undefined") return;
|
|
1251
|
+
const self = this;
|
|
1252
|
+
const auditMode = this.config.auditMode;
|
|
1253
|
+
try {
|
|
1254
|
+
const originalDescriptor = Object.getOwnPropertyDescriptor(
|
|
1255
|
+
process,
|
|
1256
|
+
"execPath"
|
|
1257
|
+
);
|
|
1258
|
+
this.originalDescriptors.push({
|
|
1259
|
+
target: process,
|
|
1260
|
+
prop: "execPath",
|
|
1261
|
+
descriptor: originalDescriptor
|
|
1262
|
+
});
|
|
1263
|
+
const currentValue = originalDescriptor?.value ?? process.execPath;
|
|
1264
|
+
Object.defineProperty(process, "execPath", {
|
|
1265
|
+
get() {
|
|
1266
|
+
const message = "process.execPath access is blocked in worker context";
|
|
1267
|
+
const violation = self.recordViolation(
|
|
1268
|
+
"process_exec_path",
|
|
1269
|
+
"process.execPath",
|
|
1270
|
+
message
|
|
1271
|
+
);
|
|
1272
|
+
if (!auditMode) {
|
|
1273
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
1274
|
+
}
|
|
1275
|
+
return currentValue;
|
|
1276
|
+
},
|
|
1277
|
+
set(value) {
|
|
1278
|
+
const message = "process.execPath modification is blocked in worker context";
|
|
1279
|
+
const violation = self.recordViolation(
|
|
1280
|
+
"process_exec_path",
|
|
1281
|
+
"process.execPath",
|
|
1282
|
+
message
|
|
1283
|
+
);
|
|
1284
|
+
if (!auditMode) {
|
|
1285
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
1286
|
+
}
|
|
1287
|
+
Object.defineProperty(process, "execPath", {
|
|
1288
|
+
value,
|
|
1289
|
+
writable: true,
|
|
1290
|
+
configurable: true
|
|
1291
|
+
});
|
|
1292
|
+
},
|
|
1293
|
+
configurable: true
|
|
1294
|
+
});
|
|
1295
|
+
} catch {
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
/**
|
|
1299
|
+
* Protect process.connected from being read or set in worker context.
|
|
1300
|
+
*
|
|
1301
|
+
* process.connected is a boolean primitive (not an object), so it cannot be
|
|
1302
|
+
* proxied via the normal blocked globals mechanism. We use Object.defineProperty
|
|
1303
|
+
* with getter/setter (same pattern as protectProcessExecPath).
|
|
1304
|
+
*
|
|
1305
|
+
* Only protects if process.connected exists (IPC contexts).
|
|
1306
|
+
*/
|
|
1307
|
+
protectProcessConnected() {
|
|
1308
|
+
if (typeof process === "undefined") return;
|
|
1309
|
+
if (process.connected === void 0) return;
|
|
1310
|
+
const self = this;
|
|
1311
|
+
const auditMode = this.config.auditMode;
|
|
1312
|
+
try {
|
|
1313
|
+
const originalDescriptor = Object.getOwnPropertyDescriptor(
|
|
1314
|
+
process,
|
|
1315
|
+
"connected"
|
|
1316
|
+
);
|
|
1317
|
+
this.originalDescriptors.push({
|
|
1318
|
+
target: process,
|
|
1319
|
+
prop: "connected",
|
|
1320
|
+
descriptor: originalDescriptor
|
|
1321
|
+
});
|
|
1322
|
+
const currentValue = originalDescriptor?.value ?? process.connected;
|
|
1323
|
+
Object.defineProperty(process, "connected", {
|
|
1324
|
+
get() {
|
|
1325
|
+
const message = "process.connected access is blocked in worker context";
|
|
1326
|
+
const violation = self.recordViolation(
|
|
1327
|
+
"process_connected",
|
|
1328
|
+
"process.connected",
|
|
1329
|
+
message
|
|
1330
|
+
);
|
|
1331
|
+
if (!auditMode) {
|
|
1332
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
1333
|
+
}
|
|
1334
|
+
return currentValue;
|
|
1335
|
+
},
|
|
1336
|
+
set(value) {
|
|
1337
|
+
const message = "process.connected modification is blocked in worker context";
|
|
1338
|
+
const violation = self.recordViolation(
|
|
1339
|
+
"process_connected",
|
|
1340
|
+
"process.connected",
|
|
1341
|
+
message
|
|
1342
|
+
);
|
|
1343
|
+
if (!auditMode) {
|
|
1344
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
1345
|
+
}
|
|
1346
|
+
Object.defineProperty(process, "connected", {
|
|
1347
|
+
value,
|
|
1348
|
+
writable: true,
|
|
1349
|
+
configurable: true
|
|
1350
|
+
});
|
|
1351
|
+
},
|
|
1352
|
+
configurable: true
|
|
1353
|
+
});
|
|
1354
|
+
} catch {
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
/**
|
|
1358
|
+
* Protect Module._load from being called.
|
|
1359
|
+
*
|
|
1360
|
+
* The attack vector is:
|
|
1361
|
+
* ```
|
|
1362
|
+
* module.constructor._load('child_process')
|
|
1363
|
+
* require.main.constructor._load('vm')
|
|
1364
|
+
* ```
|
|
1365
|
+
*
|
|
1366
|
+
* We access the Module class and replace _load with a blocking proxy.
|
|
1367
|
+
*/
|
|
1368
|
+
protectModuleLoad() {
|
|
1369
|
+
const self = this;
|
|
1370
|
+
const auditMode = this.config.auditMode;
|
|
1371
|
+
try {
|
|
1372
|
+
let ModuleClass = null;
|
|
1373
|
+
if (typeof process !== "undefined") {
|
|
1374
|
+
const mainModule = process.mainModule;
|
|
1375
|
+
if (mainModule && typeof mainModule === "object") {
|
|
1376
|
+
ModuleClass = mainModule.constructor;
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
if (!ModuleClass && typeof __require !== "undefined" && typeof __require.main !== "undefined") {
|
|
1380
|
+
ModuleClass = __require.main.constructor;
|
|
1381
|
+
}
|
|
1382
|
+
if (!ModuleClass || typeof ModuleClass._load !== "function") {
|
|
1383
|
+
return;
|
|
1384
|
+
}
|
|
1385
|
+
const original = ModuleClass._load;
|
|
1386
|
+
const descriptor = Object.getOwnPropertyDescriptor(ModuleClass, "_load");
|
|
1387
|
+
this.originalDescriptors.push({
|
|
1388
|
+
target: ModuleClass,
|
|
1389
|
+
prop: "_load",
|
|
1390
|
+
descriptor
|
|
1391
|
+
});
|
|
1392
|
+
const path = "Module._load";
|
|
1393
|
+
const proxy = new this.originalProxy(original, {
|
|
1394
|
+
apply(_target, _thisArg, _args) {
|
|
1395
|
+
const message = `${path} is blocked in worker context`;
|
|
1396
|
+
const violation = self.recordViolation("module_load", path, message);
|
|
1397
|
+
if (!auditMode) {
|
|
1398
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
1399
|
+
}
|
|
1400
|
+
return Reflect.apply(_target, _thisArg, _args);
|
|
1401
|
+
}
|
|
1402
|
+
});
|
|
1403
|
+
Object.defineProperty(ModuleClass, "_load", {
|
|
1404
|
+
value: proxy,
|
|
1405
|
+
writable: true,
|
|
1406
|
+
configurable: true
|
|
1407
|
+
});
|
|
1408
|
+
} catch {
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
/**
|
|
1412
|
+
* Protect Module._resolveFilename from being called in worker context.
|
|
1413
|
+
*
|
|
1414
|
+
* Module._resolveFilename is called for both require() and import() resolution.
|
|
1415
|
+
* Blocking it catches file-based import() specifiers.
|
|
1416
|
+
*
|
|
1417
|
+
* data: and blob: URLs are handled by ESM loader hooks registered
|
|
1418
|
+
* in the main thread (DefenseInDepthBox.protectDynamicImport).
|
|
1419
|
+
*/
|
|
1420
|
+
protectModuleResolveFilename() {
|
|
1421
|
+
const self = this;
|
|
1422
|
+
const auditMode = this.config.auditMode;
|
|
1423
|
+
try {
|
|
1424
|
+
let ModuleClass = null;
|
|
1425
|
+
if (typeof process !== "undefined") {
|
|
1426
|
+
const mainModule = process.mainModule;
|
|
1427
|
+
if (mainModule && typeof mainModule === "object") {
|
|
1428
|
+
ModuleClass = mainModule.constructor;
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
if (!ModuleClass && typeof __require !== "undefined" && typeof __require.main !== "undefined") {
|
|
1432
|
+
ModuleClass = __require.main.constructor;
|
|
1433
|
+
}
|
|
1434
|
+
if (!ModuleClass || typeof ModuleClass._resolveFilename !== "function") {
|
|
1435
|
+
return;
|
|
1436
|
+
}
|
|
1437
|
+
const original = ModuleClass._resolveFilename;
|
|
1438
|
+
const descriptor = Object.getOwnPropertyDescriptor(
|
|
1439
|
+
ModuleClass,
|
|
1440
|
+
"_resolveFilename"
|
|
1441
|
+
);
|
|
1442
|
+
this.originalDescriptors.push({
|
|
1443
|
+
target: ModuleClass,
|
|
1444
|
+
prop: "_resolveFilename",
|
|
1445
|
+
descriptor
|
|
1446
|
+
});
|
|
1447
|
+
const path = "Module._resolveFilename";
|
|
1448
|
+
const proxy = new this.originalProxy(original, {
|
|
1449
|
+
apply(_target, _thisArg, _args) {
|
|
1450
|
+
const message = `${path} is blocked in worker context`;
|
|
1451
|
+
const violation = self.recordViolation(
|
|
1452
|
+
"module_resolve_filename",
|
|
1453
|
+
path,
|
|
1454
|
+
message
|
|
1455
|
+
);
|
|
1456
|
+
if (!auditMode) {
|
|
1457
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
1458
|
+
}
|
|
1459
|
+
return Reflect.apply(_target, _thisArg, _args);
|
|
1460
|
+
}
|
|
1461
|
+
});
|
|
1462
|
+
Object.defineProperty(ModuleClass, "_resolveFilename", {
|
|
1463
|
+
value: proxy,
|
|
1464
|
+
writable: true,
|
|
1465
|
+
configurable: true
|
|
1466
|
+
});
|
|
1467
|
+
} catch {
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
/**
|
|
1471
|
+
* Apply a single patch to a blocked global.
|
|
1472
|
+
*/
|
|
1473
|
+
applyPatch(blocked) {
|
|
1474
|
+
const { target, prop, violationType, strategy } = blocked;
|
|
1475
|
+
try {
|
|
1476
|
+
const original = target[prop];
|
|
1477
|
+
if (original === void 0) {
|
|
1478
|
+
return;
|
|
1479
|
+
}
|
|
1480
|
+
const descriptor = Object.getOwnPropertyDescriptor(target, prop);
|
|
1481
|
+
this.originalDescriptors.push({ target, prop, descriptor });
|
|
1482
|
+
if (strategy === "freeze") {
|
|
1483
|
+
if (typeof original === "object" && original !== null) {
|
|
1484
|
+
Object.freeze(original);
|
|
1485
|
+
}
|
|
1486
|
+
} else {
|
|
1487
|
+
const path = this.getPathForTarget(target, prop);
|
|
1488
|
+
const proxy = typeof original === "function" ? this.createBlockingProxy(
|
|
1489
|
+
original,
|
|
1490
|
+
path,
|
|
1491
|
+
violationType
|
|
1492
|
+
) : this.createBlockingObjectProxy(
|
|
1493
|
+
original,
|
|
1494
|
+
path,
|
|
1495
|
+
violationType,
|
|
1496
|
+
blocked.allowedKeys
|
|
1497
|
+
);
|
|
1498
|
+
Object.defineProperty(target, prop, {
|
|
1499
|
+
value: proxy,
|
|
1500
|
+
writable: true,
|
|
1501
|
+
configurable: true
|
|
1502
|
+
});
|
|
1503
|
+
}
|
|
1504
|
+
} catch {
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
/**
|
|
1508
|
+
* Restore all original values.
|
|
1509
|
+
*/
|
|
1510
|
+
restorePatches() {
|
|
1511
|
+
for (let i = this.originalDescriptors.length - 1; i >= 0; i--) {
|
|
1512
|
+
const { target, prop, descriptor } = this.originalDescriptors[i];
|
|
1513
|
+
try {
|
|
1514
|
+
if (descriptor) {
|
|
1515
|
+
Object.defineProperty(target, prop, descriptor);
|
|
1516
|
+
} else {
|
|
1517
|
+
delete target[prop];
|
|
1518
|
+
}
|
|
1519
|
+
} catch {
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
this.originalDescriptors = [];
|
|
1523
|
+
}
|
|
1524
|
+
};
|
|
1525
|
+
|
|
1526
|
+
// src/security/wasm-callback.ts
|
|
1527
|
+
function sanitizeUnknownError(error) {
|
|
1528
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1529
|
+
return sanitizeErrorMessage(message);
|
|
1530
|
+
}
|
|
1531
|
+
function wrapWasmCallback(component, phase, callback) {
|
|
1532
|
+
return (...args) => {
|
|
1533
|
+
try {
|
|
1534
|
+
return callback(...args);
|
|
1535
|
+
} catch (error) {
|
|
1536
|
+
const message = sanitizeUnknownError(error);
|
|
1537
|
+
throw new Error(`${component} ${phase} callback failed: ${message}`);
|
|
1538
|
+
}
|
|
1539
|
+
};
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
// src/security/trusted-globals.ts
|
|
1543
|
+
var _SharedArrayBuffer = globalThis.SharedArrayBuffer;
|
|
1544
|
+
var _Atomics = globalThis.Atomics;
|
|
1545
|
+
var _performanceNow = performance.now.bind(performance);
|
|
1546
|
+
var _Headers = globalThis.Headers;
|
|
1547
|
+
|
|
1548
|
+
// src/commands/worker-bridge/protocol.ts
|
|
1549
|
+
var OpCode = {
|
|
1550
|
+
NOOP: 0,
|
|
1551
|
+
READ_FILE: 1,
|
|
1552
|
+
WRITE_FILE: 2,
|
|
1553
|
+
STAT: 3,
|
|
1554
|
+
READDIR: 4,
|
|
1555
|
+
MKDIR: 5,
|
|
1556
|
+
RM: 6,
|
|
1557
|
+
EXISTS: 7,
|
|
1558
|
+
APPEND_FILE: 8,
|
|
1559
|
+
SYMLINK: 9,
|
|
1560
|
+
READLINK: 10,
|
|
1561
|
+
LSTAT: 11,
|
|
1562
|
+
CHMOD: 12,
|
|
1563
|
+
REALPATH: 13,
|
|
1564
|
+
RENAME: 14,
|
|
1565
|
+
COPY_FILE: 15,
|
|
1566
|
+
// Special operations for I/O
|
|
1567
|
+
WRITE_STDOUT: 100,
|
|
1568
|
+
WRITE_STDERR: 101,
|
|
1569
|
+
EXIT: 102,
|
|
1570
|
+
// HTTP operations
|
|
1571
|
+
HTTP_REQUEST: 200,
|
|
1572
|
+
// Sub-shell execution
|
|
1573
|
+
EXEC_COMMAND: 300,
|
|
1574
|
+
// Tool invocation (executor mode)
|
|
1575
|
+
INVOKE_TOOL: 400
|
|
1576
|
+
};
|
|
1577
|
+
var Status = {
|
|
1578
|
+
PENDING: 0,
|
|
1579
|
+
READY: 1,
|
|
1580
|
+
SUCCESS: 2,
|
|
1581
|
+
ERROR: 3
|
|
1582
|
+
};
|
|
1583
|
+
var ErrorCode = {
|
|
1584
|
+
NONE: 0,
|
|
1585
|
+
NOT_FOUND: 1,
|
|
1586
|
+
IS_DIRECTORY: 2,
|
|
1587
|
+
NOT_DIRECTORY: 3,
|
|
1588
|
+
EXISTS: 4,
|
|
1589
|
+
PERMISSION_DENIED: 5,
|
|
1590
|
+
INVALID_PATH: 6,
|
|
1591
|
+
IO_ERROR: 7,
|
|
1592
|
+
TIMEOUT: 8,
|
|
1593
|
+
NETWORK_ERROR: 9,
|
|
1594
|
+
NETWORK_NOT_CONFIGURED: 10
|
|
1595
|
+
};
|
|
1596
|
+
var Offset = {
|
|
1597
|
+
OP_CODE: 0,
|
|
1598
|
+
STATUS: 4,
|
|
1599
|
+
PATH_LENGTH: 8,
|
|
1600
|
+
DATA_LENGTH: 12,
|
|
1601
|
+
RESULT_LENGTH: 16,
|
|
1602
|
+
ERROR_CODE: 20,
|
|
1603
|
+
FLAGS: 24,
|
|
1604
|
+
MODE: 28,
|
|
1605
|
+
PATH_BUFFER: 32,
|
|
1606
|
+
DATA_BUFFER: 4128
|
|
1607
|
+
// 32 + 4096
|
|
1608
|
+
};
|
|
1609
|
+
var Size = {
|
|
1610
|
+
CONTROL_REGION: 32,
|
|
1611
|
+
PATH_BUFFER: 4096,
|
|
1612
|
+
// 8MB limit for FS read/write, HTTP responses, and tool invocation results.
|
|
1613
|
+
// Sized to handle typical OpenAPI/GraphQL responses (paginated lists, batch queries).
|
|
1614
|
+
// Still well under the 64MB QuickJS memory limit per execution.
|
|
1615
|
+
DATA_BUFFER: 8388608,
|
|
1616
|
+
TOTAL: 8392736
|
|
1617
|
+
// 32 + 4096 + 8MB
|
|
1618
|
+
};
|
|
1619
|
+
var Flags = {
|
|
1620
|
+
NONE: 0,
|
|
1621
|
+
RECURSIVE: 1,
|
|
1622
|
+
FORCE: 2,
|
|
1623
|
+
MKDIR_RECURSIVE: 1
|
|
1624
|
+
};
|
|
1625
|
+
var StatLayout = {
|
|
1626
|
+
IS_FILE: 0,
|
|
1627
|
+
IS_DIRECTORY: 1,
|
|
1628
|
+
IS_SYMLINK: 2,
|
|
1629
|
+
MODE: 4,
|
|
1630
|
+
SIZE: 8,
|
|
1631
|
+
MTIME: 16,
|
|
1632
|
+
TOTAL: 24
|
|
1633
|
+
};
|
|
1634
|
+
var ProtocolBuffer = class {
|
|
1635
|
+
int32View;
|
|
1636
|
+
uint8View;
|
|
1637
|
+
dataView;
|
|
1638
|
+
constructor(buffer) {
|
|
1639
|
+
this.int32View = new Int32Array(buffer);
|
|
1640
|
+
this.uint8View = new Uint8Array(buffer);
|
|
1641
|
+
this.dataView = new DataView(buffer);
|
|
1642
|
+
}
|
|
1643
|
+
getOpCode() {
|
|
1644
|
+
return _Atomics.load(this.int32View, Offset.OP_CODE / 4);
|
|
1645
|
+
}
|
|
1646
|
+
setOpCode(code) {
|
|
1647
|
+
_Atomics.store(this.int32View, Offset.OP_CODE / 4, code);
|
|
1648
|
+
}
|
|
1649
|
+
getStatus() {
|
|
1650
|
+
return _Atomics.load(this.int32View, Offset.STATUS / 4);
|
|
1651
|
+
}
|
|
1652
|
+
setStatus(status) {
|
|
1653
|
+
_Atomics.store(this.int32View, Offset.STATUS / 4, status);
|
|
1654
|
+
}
|
|
1655
|
+
getPathLength() {
|
|
1656
|
+
return _Atomics.load(this.int32View, Offset.PATH_LENGTH / 4);
|
|
1657
|
+
}
|
|
1658
|
+
setPathLength(length) {
|
|
1659
|
+
_Atomics.store(this.int32View, Offset.PATH_LENGTH / 4, length);
|
|
1660
|
+
}
|
|
1661
|
+
getDataLength() {
|
|
1662
|
+
return _Atomics.load(this.int32View, Offset.DATA_LENGTH / 4);
|
|
1663
|
+
}
|
|
1664
|
+
setDataLength(length) {
|
|
1665
|
+
_Atomics.store(this.int32View, Offset.DATA_LENGTH / 4, length);
|
|
1666
|
+
}
|
|
1667
|
+
getResultLength() {
|
|
1668
|
+
return _Atomics.load(this.int32View, Offset.RESULT_LENGTH / 4);
|
|
1669
|
+
}
|
|
1670
|
+
setResultLength(length) {
|
|
1671
|
+
_Atomics.store(this.int32View, Offset.RESULT_LENGTH / 4, length);
|
|
1672
|
+
}
|
|
1673
|
+
getErrorCode() {
|
|
1674
|
+
return _Atomics.load(
|
|
1675
|
+
this.int32View,
|
|
1676
|
+
Offset.ERROR_CODE / 4
|
|
1677
|
+
);
|
|
1678
|
+
}
|
|
1679
|
+
setErrorCode(code) {
|
|
1680
|
+
_Atomics.store(this.int32View, Offset.ERROR_CODE / 4, code);
|
|
1681
|
+
}
|
|
1682
|
+
getFlags() {
|
|
1683
|
+
return _Atomics.load(this.int32View, Offset.FLAGS / 4);
|
|
1684
|
+
}
|
|
1685
|
+
setFlags(flags) {
|
|
1686
|
+
_Atomics.store(this.int32View, Offset.FLAGS / 4, flags);
|
|
1687
|
+
}
|
|
1688
|
+
getMode() {
|
|
1689
|
+
return _Atomics.load(this.int32View, Offset.MODE / 4);
|
|
1690
|
+
}
|
|
1691
|
+
setMode(mode) {
|
|
1692
|
+
_Atomics.store(this.int32View, Offset.MODE / 4, mode);
|
|
1693
|
+
}
|
|
1694
|
+
getPath() {
|
|
1695
|
+
const length = this.getPathLength();
|
|
1696
|
+
const bytes = this.uint8View.slice(
|
|
1697
|
+
Offset.PATH_BUFFER,
|
|
1698
|
+
Offset.PATH_BUFFER + length
|
|
1699
|
+
);
|
|
1700
|
+
return new TextDecoder().decode(bytes);
|
|
1701
|
+
}
|
|
1702
|
+
setPath(path) {
|
|
1703
|
+
const encoded = new TextEncoder().encode(path);
|
|
1704
|
+
if (encoded.length > Size.PATH_BUFFER) {
|
|
1705
|
+
throw new Error(`Path too long: ${encoded.length} > ${Size.PATH_BUFFER}`);
|
|
1706
|
+
}
|
|
1707
|
+
this.uint8View.set(encoded, Offset.PATH_BUFFER);
|
|
1708
|
+
this.setPathLength(encoded.length);
|
|
1709
|
+
}
|
|
1710
|
+
getData() {
|
|
1711
|
+
const length = this.getDataLength();
|
|
1712
|
+
return this.uint8View.slice(
|
|
1713
|
+
Offset.DATA_BUFFER,
|
|
1714
|
+
Offset.DATA_BUFFER + length
|
|
1715
|
+
);
|
|
1716
|
+
}
|
|
1717
|
+
setData(data) {
|
|
1718
|
+
if (data.length > Size.DATA_BUFFER) {
|
|
1719
|
+
throw new Error(`Data too large: ${data.length} > ${Size.DATA_BUFFER}`);
|
|
1720
|
+
}
|
|
1721
|
+
this.uint8View.set(data, Offset.DATA_BUFFER);
|
|
1722
|
+
this.setDataLength(data.length);
|
|
1723
|
+
}
|
|
1724
|
+
getDataAsString() {
|
|
1725
|
+
const data = this.getData();
|
|
1726
|
+
return new TextDecoder().decode(data);
|
|
1727
|
+
}
|
|
1728
|
+
setDataFromString(str) {
|
|
1729
|
+
const encoded = new TextEncoder().encode(str);
|
|
1730
|
+
this.setData(encoded);
|
|
1731
|
+
}
|
|
1732
|
+
getResult() {
|
|
1733
|
+
const length = this.getResultLength();
|
|
1734
|
+
return this.uint8View.slice(
|
|
1735
|
+
Offset.DATA_BUFFER,
|
|
1736
|
+
Offset.DATA_BUFFER + length
|
|
1737
|
+
);
|
|
1738
|
+
}
|
|
1739
|
+
setResult(data) {
|
|
1740
|
+
if (data.length > Size.DATA_BUFFER) {
|
|
1741
|
+
throw new Error(`Result too large: ${data.length} > ${Size.DATA_BUFFER}`);
|
|
1742
|
+
}
|
|
1743
|
+
this.uint8View.set(data, Offset.DATA_BUFFER);
|
|
1744
|
+
this.setResultLength(data.length);
|
|
1745
|
+
}
|
|
1746
|
+
getResultAsString() {
|
|
1747
|
+
const result = this.getResult();
|
|
1748
|
+
return new TextDecoder().decode(result);
|
|
1749
|
+
}
|
|
1750
|
+
setResultFromString(str) {
|
|
1751
|
+
const encoded = new TextEncoder().encode(str);
|
|
1752
|
+
this.setResult(encoded);
|
|
1753
|
+
}
|
|
1754
|
+
encodeStat(stat) {
|
|
1755
|
+
this.uint8View[Offset.DATA_BUFFER + StatLayout.IS_FILE] = stat.isFile ? 1 : 0;
|
|
1756
|
+
this.uint8View[Offset.DATA_BUFFER + StatLayout.IS_DIRECTORY] = stat.isDirectory ? 1 : 0;
|
|
1757
|
+
this.uint8View[Offset.DATA_BUFFER + StatLayout.IS_SYMLINK] = stat.isSymbolicLink ? 1 : 0;
|
|
1758
|
+
this.dataView.setInt32(
|
|
1759
|
+
Offset.DATA_BUFFER + StatLayout.MODE,
|
|
1760
|
+
stat.mode,
|
|
1761
|
+
true
|
|
1762
|
+
);
|
|
1763
|
+
const size = Math.min(stat.size, Number.MAX_SAFE_INTEGER);
|
|
1764
|
+
this.dataView.setFloat64(Offset.DATA_BUFFER + StatLayout.SIZE, size, true);
|
|
1765
|
+
this.dataView.setFloat64(
|
|
1766
|
+
Offset.DATA_BUFFER + StatLayout.MTIME,
|
|
1767
|
+
stat.mtime.getTime(),
|
|
1768
|
+
true
|
|
1769
|
+
);
|
|
1770
|
+
this.setResultLength(StatLayout.TOTAL);
|
|
1771
|
+
}
|
|
1772
|
+
decodeStat() {
|
|
1773
|
+
return {
|
|
1774
|
+
isFile: this.uint8View[Offset.DATA_BUFFER + StatLayout.IS_FILE] === 1,
|
|
1775
|
+
isDirectory: this.uint8View[Offset.DATA_BUFFER + StatLayout.IS_DIRECTORY] === 1,
|
|
1776
|
+
isSymbolicLink: this.uint8View[Offset.DATA_BUFFER + StatLayout.IS_SYMLINK] === 1,
|
|
1777
|
+
mode: this.dataView.getInt32(Offset.DATA_BUFFER + StatLayout.MODE, true),
|
|
1778
|
+
size: this.dataView.getFloat64(
|
|
1779
|
+
Offset.DATA_BUFFER + StatLayout.SIZE,
|
|
1780
|
+
true
|
|
1781
|
+
),
|
|
1782
|
+
mtime: new Date(
|
|
1783
|
+
this.dataView.getFloat64(Offset.DATA_BUFFER + StatLayout.MTIME, true)
|
|
1784
|
+
)
|
|
1785
|
+
};
|
|
1786
|
+
}
|
|
1787
|
+
waitForReady(timeout) {
|
|
1788
|
+
return _Atomics.wait(
|
|
1789
|
+
this.int32View,
|
|
1790
|
+
Offset.STATUS / 4,
|
|
1791
|
+
Status.PENDING,
|
|
1792
|
+
timeout
|
|
1793
|
+
);
|
|
1794
|
+
}
|
|
1795
|
+
waitForReadyAsync(timeout) {
|
|
1796
|
+
return _Atomics.waitAsync(
|
|
1797
|
+
this.int32View,
|
|
1798
|
+
Offset.STATUS / 4,
|
|
1799
|
+
Status.PENDING,
|
|
1800
|
+
timeout
|
|
1801
|
+
);
|
|
1802
|
+
}
|
|
1803
|
+
/**
|
|
1804
|
+
* Wait for status to become READY.
|
|
1805
|
+
* Returns immediately if status is already READY, or waits until it changes.
|
|
1806
|
+
*/
|
|
1807
|
+
async waitUntilReady(timeout) {
|
|
1808
|
+
const startTime = Date.now();
|
|
1809
|
+
while (true) {
|
|
1810
|
+
const status = this.getStatus();
|
|
1811
|
+
if (status === Status.READY) {
|
|
1812
|
+
return true;
|
|
1813
|
+
}
|
|
1814
|
+
const elapsed = Date.now() - startTime;
|
|
1815
|
+
if (elapsed >= timeout) {
|
|
1816
|
+
return false;
|
|
1817
|
+
}
|
|
1818
|
+
const remainingMs = timeout - elapsed;
|
|
1819
|
+
const result = _Atomics.waitAsync(
|
|
1820
|
+
this.int32View,
|
|
1821
|
+
Offset.STATUS / 4,
|
|
1822
|
+
status,
|
|
1823
|
+
remainingMs
|
|
1824
|
+
);
|
|
1825
|
+
if (result.async) {
|
|
1826
|
+
const waitResult = await result.value;
|
|
1827
|
+
if (waitResult === "timed-out") {
|
|
1828
|
+
return false;
|
|
1829
|
+
}
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
}
|
|
1833
|
+
waitForResult(timeout) {
|
|
1834
|
+
return _Atomics.wait(
|
|
1835
|
+
this.int32View,
|
|
1836
|
+
Offset.STATUS / 4,
|
|
1837
|
+
Status.READY,
|
|
1838
|
+
timeout
|
|
1839
|
+
);
|
|
1840
|
+
}
|
|
1841
|
+
notify() {
|
|
1842
|
+
return _Atomics.notify(this.int32View, Offset.STATUS / 4);
|
|
1843
|
+
}
|
|
1844
|
+
reset() {
|
|
1845
|
+
this.setOpCode(OpCode.NOOP);
|
|
1846
|
+
this.setStatus(Status.PENDING);
|
|
1847
|
+
this.setPathLength(0);
|
|
1848
|
+
this.setDataLength(0);
|
|
1849
|
+
this.setResultLength(0);
|
|
1850
|
+
this.setErrorCode(ErrorCode.NONE);
|
|
1851
|
+
this.setFlags(Flags.NONE);
|
|
1852
|
+
this.setMode(0);
|
|
1853
|
+
}
|
|
1854
|
+
};
|
|
1855
|
+
|
|
1856
|
+
// src/commands/worker-bridge/sync-backend.ts
|
|
1857
|
+
var SyncBackend = class {
|
|
1858
|
+
protocol;
|
|
1859
|
+
operationTimeoutMs;
|
|
1860
|
+
constructor(sharedBuffer, operationTimeoutMs = 3e4) {
|
|
1861
|
+
this.protocol = new ProtocolBuffer(sharedBuffer);
|
|
1862
|
+
this.operationTimeoutMs = operationTimeoutMs;
|
|
1863
|
+
}
|
|
1864
|
+
execSync(opCode, path, data, flags = 0, mode = 0) {
|
|
1865
|
+
this.protocol.reset();
|
|
1866
|
+
this.protocol.setOpCode(opCode);
|
|
1867
|
+
this.protocol.setPath(path);
|
|
1868
|
+
this.protocol.setFlags(flags);
|
|
1869
|
+
this.protocol.setMode(mode);
|
|
1870
|
+
if (data) {
|
|
1871
|
+
this.protocol.setData(data);
|
|
1872
|
+
}
|
|
1873
|
+
this.protocol.setStatus(Status.READY);
|
|
1874
|
+
this.protocol.notify();
|
|
1875
|
+
const waitResult = this.protocol.waitForResult(this.operationTimeoutMs);
|
|
1876
|
+
if (waitResult === "timed-out") {
|
|
1877
|
+
return { success: false, error: "Operation timed out" };
|
|
1878
|
+
}
|
|
1879
|
+
const status = this.protocol.getStatus();
|
|
1880
|
+
if (status === Status.SUCCESS) {
|
|
1881
|
+
return { success: true, result: this.protocol.getResult() };
|
|
1882
|
+
}
|
|
1883
|
+
return {
|
|
1884
|
+
success: false,
|
|
1885
|
+
error: this.protocol.getResultAsString() || `Error code: ${this.protocol.getErrorCode()}`
|
|
1886
|
+
};
|
|
1887
|
+
}
|
|
1888
|
+
readFile(path) {
|
|
1889
|
+
const result = this.execSync(OpCode.READ_FILE, path);
|
|
1890
|
+
if (!result.success) {
|
|
1891
|
+
throw new Error(result.error || "Failed to read file");
|
|
1892
|
+
}
|
|
1893
|
+
return result.result ?? new Uint8Array(0);
|
|
1894
|
+
}
|
|
1895
|
+
writeFile(path, data) {
|
|
1896
|
+
const result = this.execSync(OpCode.WRITE_FILE, path, data);
|
|
1897
|
+
if (!result.success) {
|
|
1898
|
+
throw new Error(result.error || "Failed to write file");
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
stat(path) {
|
|
1902
|
+
const result = this.execSync(OpCode.STAT, path);
|
|
1903
|
+
if (!result.success) {
|
|
1904
|
+
throw new Error(result.error || "Failed to stat");
|
|
1905
|
+
}
|
|
1906
|
+
return this.protocol.decodeStat();
|
|
1907
|
+
}
|
|
1908
|
+
lstat(path) {
|
|
1909
|
+
const result = this.execSync(OpCode.LSTAT, path);
|
|
1910
|
+
if (!result.success) {
|
|
1911
|
+
throw new Error(result.error || "Failed to lstat");
|
|
1912
|
+
}
|
|
1913
|
+
return this.protocol.decodeStat();
|
|
1914
|
+
}
|
|
1915
|
+
readdir(path) {
|
|
1916
|
+
const result = this.execSync(OpCode.READDIR, path);
|
|
1917
|
+
if (!result.success) {
|
|
1918
|
+
throw new Error(result.error || "Failed to readdir");
|
|
1919
|
+
}
|
|
1920
|
+
return JSON.parse(this.protocol.getResultAsString());
|
|
1921
|
+
}
|
|
1922
|
+
mkdir(path, recursive = false) {
|
|
1923
|
+
const flags = recursive ? Flags.MKDIR_RECURSIVE : 0;
|
|
1924
|
+
const result = this.execSync(OpCode.MKDIR, path, void 0, flags);
|
|
1925
|
+
if (!result.success) {
|
|
1926
|
+
throw new Error(result.error || "Failed to mkdir");
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
rm(path, recursive = false, force = false) {
|
|
1930
|
+
let flags = 0;
|
|
1931
|
+
if (recursive) flags |= Flags.RECURSIVE;
|
|
1932
|
+
if (force) flags |= Flags.FORCE;
|
|
1933
|
+
const result = this.execSync(OpCode.RM, path, void 0, flags);
|
|
1934
|
+
if (!result.success) {
|
|
1935
|
+
throw new Error(result.error || "Failed to rm");
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1938
|
+
exists(path) {
|
|
1939
|
+
const result = this.execSync(OpCode.EXISTS, path);
|
|
1940
|
+
if (!result.success) {
|
|
1941
|
+
return false;
|
|
1942
|
+
}
|
|
1943
|
+
return result.result?.[0] === 1;
|
|
1944
|
+
}
|
|
1945
|
+
appendFile(path, data) {
|
|
1946
|
+
const result = this.execSync(OpCode.APPEND_FILE, path, data);
|
|
1947
|
+
if (!result.success) {
|
|
1948
|
+
throw new Error(result.error || "Failed to append file");
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
symlink(target, linkPath) {
|
|
1952
|
+
const targetData = new TextEncoder().encode(target);
|
|
1953
|
+
const result = this.execSync(OpCode.SYMLINK, linkPath, targetData);
|
|
1954
|
+
if (!result.success) {
|
|
1955
|
+
throw new Error(result.error || "Failed to symlink");
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
readlink(path) {
|
|
1959
|
+
const result = this.execSync(OpCode.READLINK, path);
|
|
1960
|
+
if (!result.success) {
|
|
1961
|
+
throw new Error(result.error || "Failed to readlink");
|
|
1962
|
+
}
|
|
1963
|
+
return this.protocol.getResultAsString();
|
|
1964
|
+
}
|
|
1965
|
+
chmod(path, mode) {
|
|
1966
|
+
const result = this.execSync(OpCode.CHMOD, path, void 0, 0, mode);
|
|
1967
|
+
if (!result.success) {
|
|
1968
|
+
throw new Error(result.error || "Failed to chmod");
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
realpath(path) {
|
|
1972
|
+
const result = this.execSync(OpCode.REALPATH, path);
|
|
1973
|
+
if (!result.success) {
|
|
1974
|
+
throw new Error(result.error || "Failed to realpath");
|
|
1975
|
+
}
|
|
1976
|
+
return this.protocol.getResultAsString();
|
|
1977
|
+
}
|
|
1978
|
+
rename(oldPath, newPath) {
|
|
1979
|
+
const newPathData = new TextEncoder().encode(newPath);
|
|
1980
|
+
const result = this.execSync(OpCode.RENAME, oldPath, newPathData);
|
|
1981
|
+
if (!result.success) {
|
|
1982
|
+
throw new Error(result.error || "Failed to rename");
|
|
1983
|
+
}
|
|
1984
|
+
}
|
|
1985
|
+
copyFile(src, dest) {
|
|
1986
|
+
const destData = new TextEncoder().encode(dest);
|
|
1987
|
+
const result = this.execSync(OpCode.COPY_FILE, src, destData);
|
|
1988
|
+
if (!result.success) {
|
|
1989
|
+
throw new Error(result.error || "Failed to copyFile");
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1992
|
+
writeStdout(data) {
|
|
1993
|
+
const encoded = new TextEncoder().encode(data);
|
|
1994
|
+
const result = this.execSync(OpCode.WRITE_STDOUT, "", encoded);
|
|
1995
|
+
if (!result.success) {
|
|
1996
|
+
throw new Error(result.error || "Failed to write stdout");
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
writeStderr(data) {
|
|
2000
|
+
const encoded = new TextEncoder().encode(data);
|
|
2001
|
+
const result = this.execSync(OpCode.WRITE_STDERR, "", encoded);
|
|
2002
|
+
if (!result.success) {
|
|
2003
|
+
throw new Error(result.error || "Failed to write stderr");
|
|
2004
|
+
}
|
|
2005
|
+
}
|
|
2006
|
+
exit(code) {
|
|
2007
|
+
this.execSync(OpCode.EXIT, "", void 0, code);
|
|
2008
|
+
}
|
|
2009
|
+
/**
|
|
2010
|
+
* Make an HTTP request through the main thread's secureFetch.
|
|
2011
|
+
* Returns the response as a parsed object.
|
|
2012
|
+
*/
|
|
2013
|
+
httpRequest(url, options) {
|
|
2014
|
+
const requestData = options ? new TextEncoder().encode(JSON.stringify(options)) : void 0;
|
|
2015
|
+
const result = this.execSync(OpCode.HTTP_REQUEST, url, requestData);
|
|
2016
|
+
if (!result.success) {
|
|
2017
|
+
throw new Error(result.error || "HTTP request failed");
|
|
2018
|
+
}
|
|
2019
|
+
const responseJson = new TextDecoder().decode(result.result);
|
|
2020
|
+
const parsed = JSON.parse(responseJson);
|
|
2021
|
+
const bodyBase64 = parsed.bodyBase64 ?? "";
|
|
2022
|
+
const body = atob(bodyBase64);
|
|
2023
|
+
return {
|
|
2024
|
+
status: parsed.status,
|
|
2025
|
+
statusText: parsed.statusText,
|
|
2026
|
+
headers: parsed.headers,
|
|
2027
|
+
url: parsed.url,
|
|
2028
|
+
body,
|
|
2029
|
+
bodyBase64
|
|
2030
|
+
};
|
|
2031
|
+
}
|
|
2032
|
+
/**
|
|
2033
|
+
* Execute a shell command through the main thread's exec function.
|
|
2034
|
+
* Returns the result as { stdout, stderr, exitCode }.
|
|
2035
|
+
*/
|
|
2036
|
+
execCommand(command, stdin) {
|
|
2037
|
+
const requestData = stdin ? new TextEncoder().encode(JSON.stringify({ stdin })) : void 0;
|
|
2038
|
+
const result = this.execSync(OpCode.EXEC_COMMAND, command, requestData);
|
|
2039
|
+
if (!result.success) {
|
|
2040
|
+
throw new Error(result.error || "Command execution failed");
|
|
2041
|
+
}
|
|
2042
|
+
const responseJson = new TextDecoder().decode(result.result);
|
|
2043
|
+
return JSON.parse(responseJson);
|
|
2044
|
+
}
|
|
2045
|
+
/**
|
|
2046
|
+
* Execute a shell command with structured args (shell-escaped on the main thread).
|
|
2047
|
+
* Prevents command injection from unsanitized args.
|
|
2048
|
+
*/
|
|
2049
|
+
execCommandArgs(command, args) {
|
|
2050
|
+
const requestData = new TextEncoder().encode(JSON.stringify({ args }));
|
|
2051
|
+
const result = this.execSync(OpCode.EXEC_COMMAND, command, requestData);
|
|
2052
|
+
if (!result.success) {
|
|
2053
|
+
throw new Error(result.error || "Command execution failed");
|
|
2054
|
+
}
|
|
2055
|
+
const responseJson = new TextDecoder().decode(result.result);
|
|
2056
|
+
return JSON.parse(responseJson);
|
|
2057
|
+
}
|
|
2058
|
+
/**
|
|
2059
|
+
* Invoke a tool through the main thread's invokeTool hook.
|
|
2060
|
+
* Returns the JSON-serialized result.
|
|
2061
|
+
*/
|
|
2062
|
+
invokeTool(path, argsJson) {
|
|
2063
|
+
const requestData = argsJson ? new TextEncoder().encode(argsJson) : void 0;
|
|
2064
|
+
const result = this.execSync(OpCode.INVOKE_TOOL, path, requestData);
|
|
2065
|
+
if (!result.success) {
|
|
2066
|
+
throw new Error(result.error || "Tool invocation failed");
|
|
2067
|
+
}
|
|
2068
|
+
return new TextDecoder().decode(result.result);
|
|
2069
|
+
}
|
|
2070
|
+
};
|
|
2071
|
+
|
|
2072
|
+
// src/commands/python3/worker.ts
|
|
2073
|
+
import { readFileSync } from "node:fs";
|
|
2074
|
+
var require2 = createRequire(import.meta.url);
|
|
2075
|
+
var CPYTHON_ENTRY_BASENAME = "/vendor/cpython-emscripten/python.cjs";
|
|
2076
|
+
var CPYTHON_STDLIB_BASENAME = "/vendor/cpython-emscripten/python313.zip";
|
|
2077
|
+
var moduleLoadGuardInstalled = false;
|
|
2078
|
+
function normalizePath(path) {
|
|
2079
|
+
return path.replace(/\\/g, "/");
|
|
2080
|
+
}
|
|
2081
|
+
function isApprovedCpythonEntryPath(path) {
|
|
2082
|
+
return normalizePath(path).endsWith(CPYTHON_ENTRY_BASENAME);
|
|
2083
|
+
}
|
|
2084
|
+
function isApprovedStdlibZipPath(path) {
|
|
2085
|
+
return normalizePath(path).endsWith(CPYTHON_STDLIB_BASENAME);
|
|
2086
|
+
}
|
|
2087
|
+
function assertApprovedPath(path, kind) {
|
|
2088
|
+
const ok = kind === "cpython-entry" ? isApprovedCpythonEntryPath(path) : isApprovedStdlibZipPath(path);
|
|
2089
|
+
if (!ok) {
|
|
2090
|
+
throw new Error(
|
|
2091
|
+
`[Defense-in-depth] rejected ${kind} path outside approved vendor bundle: ${path}`
|
|
2092
|
+
);
|
|
2093
|
+
}
|
|
2094
|
+
}
|
|
2095
|
+
try {
|
|
2096
|
+
const NodeModule = require2("node:module");
|
|
2097
|
+
if (typeof NodeModule._load === "function") {
|
|
2098
|
+
const originalLoad = NodeModule._load;
|
|
2099
|
+
const blockedModules = /* @__PURE__ */ new Set([
|
|
2100
|
+
"child_process",
|
|
2101
|
+
"node:child_process",
|
|
2102
|
+
"cluster",
|
|
2103
|
+
"node:cluster",
|
|
2104
|
+
"dgram",
|
|
2105
|
+
"node:dgram",
|
|
2106
|
+
"dns",
|
|
2107
|
+
"node:dns",
|
|
2108
|
+
"net",
|
|
2109
|
+
"node:net",
|
|
2110
|
+
"tls",
|
|
2111
|
+
"node:tls",
|
|
2112
|
+
"vm",
|
|
2113
|
+
"node:vm",
|
|
2114
|
+
"v8",
|
|
2115
|
+
"node:v8",
|
|
2116
|
+
"inspector",
|
|
2117
|
+
"node:inspector",
|
|
2118
|
+
"inspector/promises",
|
|
2119
|
+
"node:inspector/promises",
|
|
2120
|
+
"trace_events",
|
|
2121
|
+
"node:trace_events",
|
|
2122
|
+
"perf_hooks",
|
|
2123
|
+
"node:perf_hooks",
|
|
2124
|
+
"worker_threads",
|
|
2125
|
+
"node:worker_threads"
|
|
2126
|
+
]);
|
|
2127
|
+
NodeModule._load = function(request, ...rest) {
|
|
2128
|
+
if (blockedModules.has(request)) {
|
|
2129
|
+
throw new Error(
|
|
2130
|
+
`[Defense-in-depth] require('${request}') is blocked in worker context`
|
|
2131
|
+
);
|
|
2132
|
+
}
|
|
2133
|
+
return originalLoad.apply(this, [request, ...rest]);
|
|
2134
|
+
};
|
|
2135
|
+
moduleLoadGuardInstalled = true;
|
|
2136
|
+
}
|
|
2137
|
+
} catch {
|
|
2138
|
+
}
|
|
2139
|
+
var cpythonEntryPath;
|
|
2140
|
+
try {
|
|
2141
|
+
cpythonEntryPath = require2.resolve(
|
|
2142
|
+
"../../../vendor/cpython-emscripten/python.cjs"
|
|
2143
|
+
);
|
|
2144
|
+
} catch (_e) {
|
|
2145
|
+
cpythonEntryPath = dirname(import.meta.url).replace("file://", "") + "/../../../vendor/cpython-emscripten/python.cjs";
|
|
2146
|
+
}
|
|
2147
|
+
assertApprovedPath(cpythonEntryPath, "cpython-entry");
|
|
2148
|
+
var cpythonDir = dirname(cpythonEntryPath);
|
|
2149
|
+
var stdlibZipPath = `${cpythonDir}/python313.zip`;
|
|
2150
|
+
assertApprovedPath(stdlibZipPath, "cpython-stdlib");
|
|
2151
|
+
function createHOSTFS(backend, FS, PATH) {
|
|
2152
|
+
const ERRNO_CODES = Object.assign(
|
|
2153
|
+
/* @__PURE__ */ Object.create(null),
|
|
2154
|
+
{
|
|
2155
|
+
EPERM: 63,
|
|
2156
|
+
ENOENT: 44,
|
|
2157
|
+
EIO: 29,
|
|
2158
|
+
EBADF: 8,
|
|
2159
|
+
EAGAIN: 6,
|
|
2160
|
+
EACCES: 2,
|
|
2161
|
+
EBUSY: 10,
|
|
2162
|
+
EEXIST: 20,
|
|
2163
|
+
ENOTDIR: 54,
|
|
2164
|
+
EISDIR: 31,
|
|
2165
|
+
EINVAL: 28,
|
|
2166
|
+
EMFILE: 33,
|
|
2167
|
+
ENOSPC: 51,
|
|
2168
|
+
ESPIPE: 70,
|
|
2169
|
+
EROFS: 69,
|
|
2170
|
+
ENOTEMPTY: 55,
|
|
2171
|
+
ENOSYS: 52,
|
|
2172
|
+
ENOTSUP: 138,
|
|
2173
|
+
ENODATA: 42
|
|
2174
|
+
}
|
|
2175
|
+
);
|
|
2176
|
+
function realPath(node) {
|
|
2177
|
+
const parts = [];
|
|
2178
|
+
while (node.parent !== node) {
|
|
2179
|
+
parts.push(node.name);
|
|
2180
|
+
node = node.parent;
|
|
2181
|
+
}
|
|
2182
|
+
parts.push(node.mount.opts.root);
|
|
2183
|
+
parts.reverse();
|
|
2184
|
+
return PATH.join(...parts);
|
|
2185
|
+
}
|
|
2186
|
+
function tryFSOperation(f) {
|
|
2187
|
+
try {
|
|
2188
|
+
return f();
|
|
2189
|
+
} catch (e) {
|
|
2190
|
+
const msg = e?.message?.toLowerCase() || (typeof e === "string" ? e.toLowerCase() : "");
|
|
2191
|
+
let code = ERRNO_CODES.EIO;
|
|
2192
|
+
if (msg.includes("no such file") || msg.includes("not found")) {
|
|
2193
|
+
code = ERRNO_CODES.ENOENT;
|
|
2194
|
+
} else if (msg.includes("is a directory")) {
|
|
2195
|
+
code = ERRNO_CODES.EISDIR;
|
|
2196
|
+
} else if (msg.includes("not a directory")) {
|
|
2197
|
+
code = ERRNO_CODES.ENOTDIR;
|
|
2198
|
+
} else if (msg.includes("already exists")) {
|
|
2199
|
+
code = ERRNO_CODES.EEXIST;
|
|
2200
|
+
} else if (msg.includes("permission")) {
|
|
2201
|
+
code = ERRNO_CODES.EACCES;
|
|
2202
|
+
} else if (msg.includes("not empty")) {
|
|
2203
|
+
code = ERRNO_CODES.ENOTEMPTY;
|
|
2204
|
+
}
|
|
2205
|
+
throw new FS.ErrnoError(code);
|
|
2206
|
+
}
|
|
2207
|
+
}
|
|
2208
|
+
function getMode(path) {
|
|
2209
|
+
return tryFSOperation(() => {
|
|
2210
|
+
const stat = backend.stat(path);
|
|
2211
|
+
let mode = stat.mode & 511;
|
|
2212
|
+
if (stat.isDirectory) {
|
|
2213
|
+
mode |= 16384;
|
|
2214
|
+
} else if (stat.isSymbolicLink) {
|
|
2215
|
+
mode |= 40960;
|
|
2216
|
+
} else {
|
|
2217
|
+
mode |= 32768;
|
|
2218
|
+
}
|
|
2219
|
+
return mode;
|
|
2220
|
+
});
|
|
2221
|
+
}
|
|
2222
|
+
const HOSTFS = {
|
|
2223
|
+
mount(_mount) {
|
|
2224
|
+
return HOSTFS.createNode(null, "/", 16877, 0);
|
|
2225
|
+
},
|
|
2226
|
+
createNode(parent, name, mode, dev) {
|
|
2227
|
+
if (!FS.isDir(mode) && !FS.isFile(mode) && !FS.isLink(mode)) {
|
|
2228
|
+
throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
|
|
2229
|
+
}
|
|
2230
|
+
const node = FS.createNode(parent, name, mode, dev);
|
|
2231
|
+
node.node_ops = HOSTFS.node_ops;
|
|
2232
|
+
node.stream_ops = HOSTFS.stream_ops;
|
|
2233
|
+
return node;
|
|
2234
|
+
},
|
|
2235
|
+
node_ops: {
|
|
2236
|
+
getattr(node) {
|
|
2237
|
+
const path = realPath(node);
|
|
2238
|
+
return tryFSOperation(() => {
|
|
2239
|
+
const stat = backend.stat(path);
|
|
2240
|
+
let mode = stat.mode & 511;
|
|
2241
|
+
if (stat.isDirectory) {
|
|
2242
|
+
mode |= 16384;
|
|
2243
|
+
} else if (stat.isSymbolicLink) {
|
|
2244
|
+
mode |= 40960;
|
|
2245
|
+
} else {
|
|
2246
|
+
mode |= 32768;
|
|
2247
|
+
}
|
|
2248
|
+
return {
|
|
2249
|
+
dev: 1,
|
|
2250
|
+
ino: node.id,
|
|
2251
|
+
mode,
|
|
2252
|
+
nlink: 1,
|
|
2253
|
+
uid: 0,
|
|
2254
|
+
gid: 0,
|
|
2255
|
+
rdev: 0,
|
|
2256
|
+
size: stat.size,
|
|
2257
|
+
atime: stat.mtime,
|
|
2258
|
+
mtime: stat.mtime,
|
|
2259
|
+
ctime: stat.mtime,
|
|
2260
|
+
blksize: 4096,
|
|
2261
|
+
blocks: Math.ceil(stat.size / 512)
|
|
2262
|
+
};
|
|
2263
|
+
});
|
|
2264
|
+
},
|
|
2265
|
+
setattr(node, attr) {
|
|
2266
|
+
const path = realPath(node);
|
|
2267
|
+
const mode = attr.mode;
|
|
2268
|
+
if (mode !== void 0) {
|
|
2269
|
+
tryFSOperation(() => backend.chmod(path, mode));
|
|
2270
|
+
node.mode = mode;
|
|
2271
|
+
}
|
|
2272
|
+
if (attr.size !== void 0) {
|
|
2273
|
+
tryFSOperation(() => {
|
|
2274
|
+
const content = backend.readFile(path);
|
|
2275
|
+
const newContent = content.slice(0, attr.size);
|
|
2276
|
+
backend.writeFile(path, newContent);
|
|
2277
|
+
});
|
|
2278
|
+
}
|
|
2279
|
+
},
|
|
2280
|
+
lookup(parent, name) {
|
|
2281
|
+
const path = PATH.join2(realPath(parent), name);
|
|
2282
|
+
const mode = getMode(path);
|
|
2283
|
+
return HOSTFS.createNode(parent, name, mode);
|
|
2284
|
+
},
|
|
2285
|
+
mknod(parent, name, mode, _dev) {
|
|
2286
|
+
const node = HOSTFS.createNode(parent, name, mode, _dev);
|
|
2287
|
+
const path = realPath(node);
|
|
2288
|
+
tryFSOperation(() => {
|
|
2289
|
+
if (FS.isDir(node.mode)) {
|
|
2290
|
+
backend.mkdir(path, false);
|
|
2291
|
+
} else {
|
|
2292
|
+
backend.writeFile(path, new Uint8Array(0));
|
|
2293
|
+
}
|
|
2294
|
+
});
|
|
2295
|
+
return node;
|
|
2296
|
+
},
|
|
2297
|
+
rename(oldNode, newDir, newName) {
|
|
2298
|
+
const oldPath = realPath(oldNode);
|
|
2299
|
+
const newPath = PATH.join2(realPath(newDir), newName);
|
|
2300
|
+
tryFSOperation(() => {
|
|
2301
|
+
const content = backend.readFile(oldPath);
|
|
2302
|
+
backend.writeFile(newPath, content);
|
|
2303
|
+
backend.rm(oldPath, false, false);
|
|
2304
|
+
});
|
|
2305
|
+
oldNode.name = newName;
|
|
2306
|
+
},
|
|
2307
|
+
unlink(parent, name) {
|
|
2308
|
+
const path = PATH.join2(realPath(parent), name);
|
|
2309
|
+
tryFSOperation(() => backend.rm(path, false, false));
|
|
2310
|
+
},
|
|
2311
|
+
rmdir(parent, name) {
|
|
2312
|
+
const path = PATH.join2(realPath(parent), name);
|
|
2313
|
+
tryFSOperation(() => backend.rm(path, false, false));
|
|
2314
|
+
},
|
|
2315
|
+
readdir(node) {
|
|
2316
|
+
const path = realPath(node);
|
|
2317
|
+
return tryFSOperation(() => backend.readdir(path));
|
|
2318
|
+
},
|
|
2319
|
+
symlink(parent, newName, oldPath) {
|
|
2320
|
+
const newPath = PATH.join2(realPath(parent), newName);
|
|
2321
|
+
tryFSOperation(() => backend.symlink(oldPath, newPath));
|
|
2322
|
+
},
|
|
2323
|
+
readlink(node) {
|
|
2324
|
+
const path = realPath(node);
|
|
2325
|
+
return tryFSOperation(() => backend.readlink(path));
|
|
2326
|
+
}
|
|
2327
|
+
},
|
|
2328
|
+
stream_ops: {
|
|
2329
|
+
open(stream) {
|
|
2330
|
+
const path = realPath(stream.node);
|
|
2331
|
+
const flags = stream.flags;
|
|
2332
|
+
const O_WRONLY = 1;
|
|
2333
|
+
const O_RDWR = 2;
|
|
2334
|
+
const O_CREAT = 64;
|
|
2335
|
+
const O_TRUNC = 512;
|
|
2336
|
+
const O_APPEND = 1024;
|
|
2337
|
+
const accessMode = flags & 3;
|
|
2338
|
+
const isWrite = accessMode === O_WRONLY || accessMode === O_RDWR;
|
|
2339
|
+
const isCreate = (flags & O_CREAT) !== 0;
|
|
2340
|
+
const isTruncate = (flags & O_TRUNC) !== 0;
|
|
2341
|
+
const isAppend = (flags & O_APPEND) !== 0;
|
|
2342
|
+
if (FS.isDir(stream.node.mode)) {
|
|
2343
|
+
return;
|
|
2344
|
+
}
|
|
2345
|
+
let content;
|
|
2346
|
+
try {
|
|
2347
|
+
if (isTruncate && isWrite) {
|
|
2348
|
+
content = new Uint8Array(0);
|
|
2349
|
+
} else {
|
|
2350
|
+
content = backend.readFile(path);
|
|
2351
|
+
}
|
|
2352
|
+
} catch (_e) {
|
|
2353
|
+
if (isCreate && isWrite) {
|
|
2354
|
+
content = new Uint8Array(0);
|
|
2355
|
+
} else {
|
|
2356
|
+
throw new FS.ErrnoError(ERRNO_CODES.ENOENT);
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2359
|
+
stream.hostContent = content;
|
|
2360
|
+
stream.hostModified = isTruncate && isWrite;
|
|
2361
|
+
stream.hostPath = path;
|
|
2362
|
+
if (isAppend) {
|
|
2363
|
+
stream.position = content.length;
|
|
2364
|
+
}
|
|
2365
|
+
},
|
|
2366
|
+
close(stream) {
|
|
2367
|
+
const hostPath = stream.hostPath;
|
|
2368
|
+
const hostContent = stream.hostContent;
|
|
2369
|
+
if (stream.hostModified && hostContent && hostPath) {
|
|
2370
|
+
tryFSOperation(() => backend.writeFile(hostPath, hostContent));
|
|
2371
|
+
}
|
|
2372
|
+
delete stream.hostContent;
|
|
2373
|
+
delete stream.hostModified;
|
|
2374
|
+
delete stream.hostPath;
|
|
2375
|
+
},
|
|
2376
|
+
read(stream, buffer, offset, length, position) {
|
|
2377
|
+
const content = stream.hostContent;
|
|
2378
|
+
if (!content) return 0;
|
|
2379
|
+
const size = content.length;
|
|
2380
|
+
if (position >= size) return 0;
|
|
2381
|
+
const bytesToRead = Math.min(length, size - position);
|
|
2382
|
+
buffer.set(content.subarray(position, position + bytesToRead), offset);
|
|
2383
|
+
return bytesToRead;
|
|
2384
|
+
},
|
|
2385
|
+
write(stream, buffer, offset, length, position) {
|
|
2386
|
+
let content = stream.hostContent || new Uint8Array(0);
|
|
2387
|
+
const newSize = Math.max(content.length, position + length);
|
|
2388
|
+
if (newSize > content.length) {
|
|
2389
|
+
const newContent = new Uint8Array(newSize);
|
|
2390
|
+
newContent.set(content);
|
|
2391
|
+
content = newContent;
|
|
2392
|
+
stream.hostContent = content;
|
|
2393
|
+
}
|
|
2394
|
+
content.set(buffer.subarray(offset, offset + length), position);
|
|
2395
|
+
stream.hostModified = true;
|
|
2396
|
+
return length;
|
|
2397
|
+
},
|
|
2398
|
+
llseek(stream, offset, whence) {
|
|
2399
|
+
const SEEK_CUR = 1;
|
|
2400
|
+
const SEEK_END = 2;
|
|
2401
|
+
let position = offset;
|
|
2402
|
+
if (whence === SEEK_CUR) {
|
|
2403
|
+
position += stream.position;
|
|
2404
|
+
} else if (whence === SEEK_END) {
|
|
2405
|
+
if (FS.isFile(stream.node.mode)) {
|
|
2406
|
+
const content = stream.hostContent;
|
|
2407
|
+
position += content ? content.length : 0;
|
|
2408
|
+
}
|
|
2409
|
+
}
|
|
2410
|
+
if (position < 0) {
|
|
2411
|
+
throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
|
|
2412
|
+
}
|
|
2413
|
+
return position;
|
|
2414
|
+
}
|
|
2415
|
+
}
|
|
2416
|
+
};
|
|
2417
|
+
return HOSTFS;
|
|
2418
|
+
}
|
|
2419
|
+
function generateSetupCode(input) {
|
|
2420
|
+
const envSetup = Object.entries(input.env).map(([key, value]) => {
|
|
2421
|
+
return `os.environ[${JSON.stringify(key)}] = ${JSON.stringify(value)}`;
|
|
2422
|
+
}).join("\n");
|
|
2423
|
+
const argv0 = input.scriptPath || "python3";
|
|
2424
|
+
const argvList = [argv0, ...input.args].map((arg) => JSON.stringify(arg)).join(", ");
|
|
2425
|
+
return `
|
|
2426
|
+
import os
|
|
2427
|
+
import sys
|
|
2428
|
+
import json
|
|
2429
|
+
|
|
2430
|
+
${envSetup}
|
|
2431
|
+
|
|
2432
|
+
sys.argv = [${argvList}]
|
|
2433
|
+
|
|
2434
|
+
# Path redirection: redirect /absolute paths to /host mount
|
|
2435
|
+
def _should_redirect(path):
|
|
2436
|
+
return (isinstance(path, str) and
|
|
2437
|
+
path.startswith('/') and
|
|
2438
|
+
not path.startswith('/lib') and
|
|
2439
|
+
not path.startswith('/proc') and
|
|
2440
|
+
not path.startswith('/host') and
|
|
2441
|
+
not path.startswith('/_jb_http'))
|
|
2442
|
+
|
|
2443
|
+
# builtins.open
|
|
2444
|
+
import builtins
|
|
2445
|
+
_orig_open = builtins.open
|
|
2446
|
+
def _redir_open(path, mode='r', *args, **kwargs):
|
|
2447
|
+
if _should_redirect(path):
|
|
2448
|
+
path = '/host' + path
|
|
2449
|
+
return _orig_open(path, mode, *args, **kwargs)
|
|
2450
|
+
builtins.open = _redir_open
|
|
2451
|
+
|
|
2452
|
+
# os file operations
|
|
2453
|
+
_orig_listdir = os.listdir
|
|
2454
|
+
def _redir_listdir(path='.'):
|
|
2455
|
+
if _should_redirect(path):
|
|
2456
|
+
path = '/host' + path
|
|
2457
|
+
return _orig_listdir(path)
|
|
2458
|
+
os.listdir = _redir_listdir
|
|
2459
|
+
|
|
2460
|
+
_orig_exists = os.path.exists
|
|
2461
|
+
def _redir_exists(path):
|
|
2462
|
+
if _should_redirect(path):
|
|
2463
|
+
path = '/host' + path
|
|
2464
|
+
return _orig_exists(path)
|
|
2465
|
+
os.path.exists = _redir_exists
|
|
2466
|
+
|
|
2467
|
+
_orig_isfile = os.path.isfile
|
|
2468
|
+
def _redir_isfile(path):
|
|
2469
|
+
if _should_redirect(path):
|
|
2470
|
+
path = '/host' + path
|
|
2471
|
+
return _orig_isfile(path)
|
|
2472
|
+
os.path.isfile = _redir_isfile
|
|
2473
|
+
|
|
2474
|
+
_orig_isdir = os.path.isdir
|
|
2475
|
+
def _redir_isdir(path):
|
|
2476
|
+
if _should_redirect(path):
|
|
2477
|
+
path = '/host' + path
|
|
2478
|
+
return _orig_isdir(path)
|
|
2479
|
+
os.path.isdir = _redir_isdir
|
|
2480
|
+
|
|
2481
|
+
_orig_stat = os.stat
|
|
2482
|
+
def _redir_stat(path, *args, **kwargs):
|
|
2483
|
+
if _should_redirect(path):
|
|
2484
|
+
path = '/host' + path
|
|
2485
|
+
return _orig_stat(path, *args, **kwargs)
|
|
2486
|
+
os.stat = _redir_stat
|
|
2487
|
+
|
|
2488
|
+
_orig_mkdir = os.mkdir
|
|
2489
|
+
def _redir_mkdir(path, *args, **kwargs):
|
|
2490
|
+
if _should_redirect(path):
|
|
2491
|
+
path = '/host' + path
|
|
2492
|
+
return _orig_mkdir(path, *args, **kwargs)
|
|
2493
|
+
os.mkdir = _redir_mkdir
|
|
2494
|
+
|
|
2495
|
+
_orig_makedirs = os.makedirs
|
|
2496
|
+
def _redir_makedirs(path, *args, **kwargs):
|
|
2497
|
+
if _should_redirect(path):
|
|
2498
|
+
path = '/host' + path
|
|
2499
|
+
return _orig_makedirs(path, *args, **kwargs)
|
|
2500
|
+
os.makedirs = _redir_makedirs
|
|
2501
|
+
|
|
2502
|
+
_orig_remove = os.remove
|
|
2503
|
+
def _redir_remove(path, *args, **kwargs):
|
|
2504
|
+
if _should_redirect(path):
|
|
2505
|
+
path = '/host' + path
|
|
2506
|
+
return _orig_remove(path, *args, **kwargs)
|
|
2507
|
+
os.remove = _redir_remove
|
|
2508
|
+
|
|
2509
|
+
_orig_rmdir = os.rmdir
|
|
2510
|
+
def _redir_rmdir(path, *args, **kwargs):
|
|
2511
|
+
if _should_redirect(path):
|
|
2512
|
+
path = '/host' + path
|
|
2513
|
+
return _orig_rmdir(path, *args, **kwargs)
|
|
2514
|
+
os.rmdir = _redir_rmdir
|
|
2515
|
+
|
|
2516
|
+
_orig_getcwd = os.getcwd
|
|
2517
|
+
def _redir_getcwd():
|
|
2518
|
+
cwd = _orig_getcwd()
|
|
2519
|
+
if cwd.startswith('/host'):
|
|
2520
|
+
return cwd[5:]
|
|
2521
|
+
return cwd
|
|
2522
|
+
os.getcwd = _redir_getcwd
|
|
2523
|
+
|
|
2524
|
+
_orig_chdir = os.chdir
|
|
2525
|
+
def _redir_chdir(path):
|
|
2526
|
+
if _should_redirect(path):
|
|
2527
|
+
path = '/host' + path
|
|
2528
|
+
return _orig_chdir(path)
|
|
2529
|
+
os.chdir = _redir_chdir
|
|
2530
|
+
|
|
2531
|
+
# glob
|
|
2532
|
+
import glob as _glob_module
|
|
2533
|
+
_orig_glob = _glob_module.glob
|
|
2534
|
+
def _redir_glob(pathname, *args, **kwargs):
|
|
2535
|
+
if _should_redirect(pathname):
|
|
2536
|
+
pathname = '/host' + pathname
|
|
2537
|
+
return _orig_glob(pathname, *args, **kwargs)
|
|
2538
|
+
_glob_module.glob = _redir_glob
|
|
2539
|
+
|
|
2540
|
+
_orig_iglob = _glob_module.iglob
|
|
2541
|
+
def _redir_iglob(pathname, *args, **kwargs):
|
|
2542
|
+
if _should_redirect(pathname):
|
|
2543
|
+
pathname = '/host' + pathname
|
|
2544
|
+
return _orig_iglob(pathname, *args, **kwargs)
|
|
2545
|
+
_glob_module.iglob = _redir_iglob
|
|
2546
|
+
|
|
2547
|
+
# os.walk
|
|
2548
|
+
_orig_walk = os.walk
|
|
2549
|
+
def _redir_walk(top, *args, **kwargs):
|
|
2550
|
+
redirected = False
|
|
2551
|
+
if _should_redirect(top):
|
|
2552
|
+
top = '/host' + top
|
|
2553
|
+
redirected = True
|
|
2554
|
+
for dirpath, dirnames, filenames in _orig_walk(top, *args, **kwargs):
|
|
2555
|
+
if redirected and dirpath.startswith('/host'):
|
|
2556
|
+
dirpath = dirpath[5:] if len(dirpath) > 5 else '/'
|
|
2557
|
+
yield dirpath, dirnames, filenames
|
|
2558
|
+
os.walk = _redir_walk
|
|
2559
|
+
|
|
2560
|
+
# os.scandir
|
|
2561
|
+
_orig_scandir = os.scandir
|
|
2562
|
+
def _redir_scandir(path='.'):
|
|
2563
|
+
if _should_redirect(path):
|
|
2564
|
+
path = '/host' + path
|
|
2565
|
+
return _orig_scandir(path)
|
|
2566
|
+
os.scandir = _redir_scandir
|
|
2567
|
+
|
|
2568
|
+
# io.open
|
|
2569
|
+
import io as _io_module
|
|
2570
|
+
_io_module.open = builtins.open
|
|
2571
|
+
|
|
2572
|
+
# shutil
|
|
2573
|
+
import shutil as _shutil_module
|
|
2574
|
+
|
|
2575
|
+
_orig_shutil_copy = _shutil_module.copy
|
|
2576
|
+
def _redir_shutil_copy(src, dst, *args, **kwargs):
|
|
2577
|
+
if _should_redirect(src): src = '/host' + src
|
|
2578
|
+
if _should_redirect(dst): dst = '/host' + dst
|
|
2579
|
+
return _orig_shutil_copy(src, dst, *args, **kwargs)
|
|
2580
|
+
_shutil_module.copy = _redir_shutil_copy
|
|
2581
|
+
|
|
2582
|
+
_orig_shutil_copy2 = _shutil_module.copy2
|
|
2583
|
+
def _redir_shutil_copy2(src, dst, *args, **kwargs):
|
|
2584
|
+
if _should_redirect(src): src = '/host' + src
|
|
2585
|
+
if _should_redirect(dst): dst = '/host' + dst
|
|
2586
|
+
return _orig_shutil_copy2(src, dst, *args, **kwargs)
|
|
2587
|
+
_shutil_module.copy2 = _redir_shutil_copy2
|
|
2588
|
+
|
|
2589
|
+
_orig_shutil_copyfile = _shutil_module.copyfile
|
|
2590
|
+
def _redir_shutil_copyfile(src, dst, *args, **kwargs):
|
|
2591
|
+
if _should_redirect(src): src = '/host' + src
|
|
2592
|
+
if _should_redirect(dst): dst = '/host' + dst
|
|
2593
|
+
return _orig_shutil_copyfile(src, dst, *args, **kwargs)
|
|
2594
|
+
_shutil_module.copyfile = _redir_shutil_copyfile
|
|
2595
|
+
|
|
2596
|
+
_orig_shutil_copytree = _shutil_module.copytree
|
|
2597
|
+
def _redir_shutil_copytree(src, dst, *args, **kwargs):
|
|
2598
|
+
if _should_redirect(src): src = '/host' + src
|
|
2599
|
+
if _should_redirect(dst): dst = '/host' + dst
|
|
2600
|
+
return _orig_shutil_copytree(src, dst, *args, **kwargs)
|
|
2601
|
+
_shutil_module.copytree = _redir_shutil_copytree
|
|
2602
|
+
|
|
2603
|
+
_orig_shutil_move = _shutil_module.move
|
|
2604
|
+
def _redir_shutil_move(src, dst, *args, **kwargs):
|
|
2605
|
+
if _should_redirect(src): src = '/host' + src
|
|
2606
|
+
if _should_redirect(dst): dst = '/host' + dst
|
|
2607
|
+
return _orig_shutil_move(src, dst, *args, **kwargs)
|
|
2608
|
+
_shutil_module.move = _redir_shutil_move
|
|
2609
|
+
|
|
2610
|
+
_orig_shutil_rmtree = _shutil_module.rmtree
|
|
2611
|
+
def _redir_shutil_rmtree(path, *args, **kwargs):
|
|
2612
|
+
if _should_redirect(path): path = '/host' + path
|
|
2613
|
+
return _orig_shutil_rmtree(path, *args, **kwargs)
|
|
2614
|
+
_shutil_module.rmtree = _redir_shutil_rmtree
|
|
2615
|
+
|
|
2616
|
+
# pathlib.Path
|
|
2617
|
+
from pathlib import Path
|
|
2618
|
+
|
|
2619
|
+
def _redirect_path(p):
|
|
2620
|
+
s = str(p)
|
|
2621
|
+
if _should_redirect(s):
|
|
2622
|
+
return Path('/host' + s)
|
|
2623
|
+
return p
|
|
2624
|
+
|
|
2625
|
+
Path._orig_stat = Path.stat
|
|
2626
|
+
def _path_stat(self, *args, **kwargs):
|
|
2627
|
+
return _redirect_path(self)._orig_stat(*args, **kwargs)
|
|
2628
|
+
Path.stat = _path_stat
|
|
2629
|
+
|
|
2630
|
+
Path._orig_exists = Path.exists
|
|
2631
|
+
def _path_exists(self):
|
|
2632
|
+
return _redirect_path(self)._orig_exists()
|
|
2633
|
+
Path.exists = _path_exists
|
|
2634
|
+
|
|
2635
|
+
Path._orig_is_file = Path.is_file
|
|
2636
|
+
def _path_is_file(self):
|
|
2637
|
+
return _redirect_path(self)._orig_is_file()
|
|
2638
|
+
Path.is_file = _path_is_file
|
|
2639
|
+
|
|
2640
|
+
Path._orig_is_dir = Path.is_dir
|
|
2641
|
+
def _path_is_dir(self):
|
|
2642
|
+
return _redirect_path(self)._orig_is_dir()
|
|
2643
|
+
Path.is_dir = _path_is_dir
|
|
2644
|
+
|
|
2645
|
+
Path._orig_open = Path.open
|
|
2646
|
+
def _path_open(self, *args, **kwargs):
|
|
2647
|
+
return _redirect_path(self)._orig_open(*args, **kwargs)
|
|
2648
|
+
Path.open = _path_open
|
|
2649
|
+
|
|
2650
|
+
Path._orig_read_text = Path.read_text
|
|
2651
|
+
def _path_read_text(self, *args, **kwargs):
|
|
2652
|
+
return _redirect_path(self)._orig_read_text(*args, **kwargs)
|
|
2653
|
+
Path.read_text = _path_read_text
|
|
2654
|
+
|
|
2655
|
+
Path._orig_read_bytes = Path.read_bytes
|
|
2656
|
+
def _path_read_bytes(self):
|
|
2657
|
+
return _redirect_path(self)._orig_read_bytes()
|
|
2658
|
+
Path.read_bytes = _path_read_bytes
|
|
2659
|
+
|
|
2660
|
+
Path._orig_write_text = Path.write_text
|
|
2661
|
+
def _path_write_text(self, *args, **kwargs):
|
|
2662
|
+
return _redirect_path(self)._orig_write_text(*args, **kwargs)
|
|
2663
|
+
Path.write_text = _path_write_text
|
|
2664
|
+
|
|
2665
|
+
Path._orig_write_bytes = Path.write_bytes
|
|
2666
|
+
def _path_write_bytes(self, data):
|
|
2667
|
+
return _redirect_path(self)._orig_write_bytes(data)
|
|
2668
|
+
Path.write_bytes = _path_write_bytes
|
|
2669
|
+
|
|
2670
|
+
Path._orig_mkdir = Path.mkdir
|
|
2671
|
+
def _path_mkdir(self, *args, **kwargs):
|
|
2672
|
+
return _redirect_path(self)._orig_mkdir(*args, **kwargs)
|
|
2673
|
+
Path.mkdir = _path_mkdir
|
|
2674
|
+
|
|
2675
|
+
Path._orig_rmdir = Path.rmdir
|
|
2676
|
+
def _path_rmdir(self):
|
|
2677
|
+
return _redirect_path(self)._orig_rmdir()
|
|
2678
|
+
Path.rmdir = _path_rmdir
|
|
2679
|
+
|
|
2680
|
+
Path._orig_unlink = Path.unlink
|
|
2681
|
+
def _path_unlink(self, *args, **kwargs):
|
|
2682
|
+
return _redirect_path(self)._orig_unlink(*args, **kwargs)
|
|
2683
|
+
Path.unlink = _path_unlink
|
|
2684
|
+
|
|
2685
|
+
Path._orig_iterdir = Path.iterdir
|
|
2686
|
+
def _path_iterdir(self):
|
|
2687
|
+
redirected = _redirect_path(self)
|
|
2688
|
+
for p in redirected._orig_iterdir():
|
|
2689
|
+
s = str(p)
|
|
2690
|
+
if s.startswith('/host'):
|
|
2691
|
+
yield Path(s[5:])
|
|
2692
|
+
else:
|
|
2693
|
+
yield p
|
|
2694
|
+
Path.iterdir = _path_iterdir
|
|
2695
|
+
|
|
2696
|
+
Path._orig_glob = Path.glob
|
|
2697
|
+
def _path_glob(self, pattern):
|
|
2698
|
+
redirected = _redirect_path(self)
|
|
2699
|
+
for p in redirected._orig_glob(pattern):
|
|
2700
|
+
s = str(p)
|
|
2701
|
+
if s.startswith('/host'):
|
|
2702
|
+
yield Path(s[5:])
|
|
2703
|
+
else:
|
|
2704
|
+
yield p
|
|
2705
|
+
Path.glob = _path_glob
|
|
2706
|
+
|
|
2707
|
+
Path._orig_rglob = Path.rglob
|
|
2708
|
+
def _path_rglob(self, pattern):
|
|
2709
|
+
redirected = _redirect_path(self)
|
|
2710
|
+
for p in redirected._orig_rglob(pattern):
|
|
2711
|
+
s = str(p)
|
|
2712
|
+
if s.startswith('/host'):
|
|
2713
|
+
yield Path(s[5:])
|
|
2714
|
+
else:
|
|
2715
|
+
yield p
|
|
2716
|
+
Path.rglob = _path_rglob
|
|
2717
|
+
|
|
2718
|
+
# Set cwd to host mount
|
|
2719
|
+
os.chdir('/host' + ${JSON.stringify(input.cwd)})
|
|
2720
|
+
`;
|
|
2721
|
+
}
|
|
2722
|
+
function createHTTPFS(backend, FS) {
|
|
2723
|
+
let lastResponse = null;
|
|
2724
|
+
const encoder = new TextEncoder();
|
|
2725
|
+
const decoder = new TextDecoder();
|
|
2726
|
+
const HTTPFS = {
|
|
2727
|
+
mount(_mount) {
|
|
2728
|
+
return HTTPFS.createNode(null, "/", 16877, 0);
|
|
2729
|
+
},
|
|
2730
|
+
createNode(parent, name, mode, dev) {
|
|
2731
|
+
const node = FS.createNode(parent, name, mode, dev);
|
|
2732
|
+
node.node_ops = HTTPFS.node_ops;
|
|
2733
|
+
node.stream_ops = HTTPFS.stream_ops;
|
|
2734
|
+
return node;
|
|
2735
|
+
},
|
|
2736
|
+
node_ops: {
|
|
2737
|
+
getattr(node) {
|
|
2738
|
+
const isDir = node.name === "/" || node.parent === node;
|
|
2739
|
+
return {
|
|
2740
|
+
dev: 1,
|
|
2741
|
+
ino: node.id,
|
|
2742
|
+
mode: isDir ? 16877 : 33206,
|
|
2743
|
+
nlink: 1,
|
|
2744
|
+
uid: 0,
|
|
2745
|
+
gid: 0,
|
|
2746
|
+
rdev: 0,
|
|
2747
|
+
size: lastResponse ? lastResponse.length : 0,
|
|
2748
|
+
atime: /* @__PURE__ */ new Date(),
|
|
2749
|
+
mtime: /* @__PURE__ */ new Date(),
|
|
2750
|
+
ctime: /* @__PURE__ */ new Date(),
|
|
2751
|
+
blksize: 4096,
|
|
2752
|
+
blocks: 0
|
|
2753
|
+
};
|
|
2754
|
+
},
|
|
2755
|
+
setattr(_node, _attr) {
|
|
2756
|
+
},
|
|
2757
|
+
lookup(parent, name) {
|
|
2758
|
+
return HTTPFS.createNode(parent, name, 33206);
|
|
2759
|
+
},
|
|
2760
|
+
mknod(parent, name, mode, _dev) {
|
|
2761
|
+
return HTTPFS.createNode(parent, name, mode);
|
|
2762
|
+
},
|
|
2763
|
+
rename() {
|
|
2764
|
+
},
|
|
2765
|
+
unlink() {
|
|
2766
|
+
},
|
|
2767
|
+
rmdir() {
|
|
2768
|
+
},
|
|
2769
|
+
readdir(_node) {
|
|
2770
|
+
return ["request"];
|
|
2771
|
+
},
|
|
2772
|
+
symlink() {
|
|
2773
|
+
},
|
|
2774
|
+
readlink(_node) {
|
|
2775
|
+
return "";
|
|
2776
|
+
}
|
|
2777
|
+
},
|
|
2778
|
+
stream_ops: {
|
|
2779
|
+
open(stream) {
|
|
2780
|
+
delete stream.hostContent;
|
|
2781
|
+
stream.hostModified = false;
|
|
2782
|
+
const accessMode = stream.flags & 3;
|
|
2783
|
+
const isRead = accessMode === 0;
|
|
2784
|
+
if (isRead && lastResponse) {
|
|
2785
|
+
stream.hostContent = lastResponse;
|
|
2786
|
+
}
|
|
2787
|
+
},
|
|
2788
|
+
close(stream) {
|
|
2789
|
+
if (stream.hostModified && stream.hostContent) {
|
|
2790
|
+
const reqJson = decoder.decode(stream.hostContent);
|
|
2791
|
+
try {
|
|
2792
|
+
const req = JSON.parse(reqJson);
|
|
2793
|
+
const result = backend.httpRequest(req.url, {
|
|
2794
|
+
method: req.method || "GET",
|
|
2795
|
+
headers: req.headers || void 0,
|
|
2796
|
+
body: req.body || void 0
|
|
2797
|
+
});
|
|
2798
|
+
lastResponse = encoder.encode(JSON.stringify(result));
|
|
2799
|
+
} catch (e) {
|
|
2800
|
+
const message = sanitizeHostErrorMessage(e.message);
|
|
2801
|
+
lastResponse = encoder.encode(JSON.stringify({ error: message }));
|
|
2802
|
+
}
|
|
2803
|
+
}
|
|
2804
|
+
delete stream.hostContent;
|
|
2805
|
+
delete stream.hostModified;
|
|
2806
|
+
},
|
|
2807
|
+
read(stream, buffer, offset, length, position) {
|
|
2808
|
+
const content = stream.hostContent;
|
|
2809
|
+
if (!content) return 0;
|
|
2810
|
+
const size = content.length;
|
|
2811
|
+
if (position >= size) return 0;
|
|
2812
|
+
const bytesToRead = Math.min(length, size - position);
|
|
2813
|
+
buffer.set(content.subarray(position, position + bytesToRead), offset);
|
|
2814
|
+
return bytesToRead;
|
|
2815
|
+
},
|
|
2816
|
+
write(stream, buffer, offset, length, position) {
|
|
2817
|
+
let content = stream.hostContent || new Uint8Array(0);
|
|
2818
|
+
const newSize = Math.max(content.length, position + length);
|
|
2819
|
+
if (newSize > content.length) {
|
|
2820
|
+
const newContent = new Uint8Array(newSize);
|
|
2821
|
+
newContent.set(content);
|
|
2822
|
+
content = newContent;
|
|
2823
|
+
stream.hostContent = content;
|
|
2824
|
+
}
|
|
2825
|
+
content.set(buffer.subarray(offset, offset + length), position);
|
|
2826
|
+
stream.hostModified = true;
|
|
2827
|
+
return length;
|
|
2828
|
+
},
|
|
2829
|
+
llseek(stream, offset, whence) {
|
|
2830
|
+
let position = offset;
|
|
2831
|
+
if (whence === 1)
|
|
2832
|
+
position += stream.position;
|
|
2833
|
+
else if (whence === 2) {
|
|
2834
|
+
const content = stream.hostContent;
|
|
2835
|
+
position += content ? content.length : 0;
|
|
2836
|
+
}
|
|
2837
|
+
if (position < 0) throw new FS.ErrnoError(28);
|
|
2838
|
+
return position;
|
|
2839
|
+
}
|
|
2840
|
+
}
|
|
2841
|
+
};
|
|
2842
|
+
return HTTPFS;
|
|
2843
|
+
}
|
|
2844
|
+
function generateHttpBridgeCode() {
|
|
2845
|
+
return `
|
|
2846
|
+
# HTTP bridge: jb_http module
|
|
2847
|
+
# Write request JSON to /_jb_http/request (custom FS triggers HTTP via SharedArrayBuffer)
|
|
2848
|
+
# Then read response JSON from same path.
|
|
2849
|
+
|
|
2850
|
+
import base64 as _base64
|
|
2851
|
+
|
|
2852
|
+
class _JbHttpResponse:
|
|
2853
|
+
"""HTTP response object similar to requests.Response"""
|
|
2854
|
+
def __init__(self, data):
|
|
2855
|
+
self.status_code = data.get('status', 0)
|
|
2856
|
+
self.reason = data.get('statusText', '')
|
|
2857
|
+
# @banned-pattern-ignore: Python code, not JavaScript
|
|
2858
|
+
self.headers = data.get('headers', {})
|
|
2859
|
+
self.url = data.get('url', '')
|
|
2860
|
+
self._error = data.get('error')
|
|
2861
|
+
b64 = data.get('bodyBase64')
|
|
2862
|
+
if b64 is not None:
|
|
2863
|
+
self.content = _base64.b64decode(b64)
|
|
2864
|
+
self.text = self.content.decode('utf-8', errors='replace')
|
|
2865
|
+
else:
|
|
2866
|
+
self.content = b''
|
|
2867
|
+
self.text = data.get('body', '')
|
|
2868
|
+
|
|
2869
|
+
@property
|
|
2870
|
+
def ok(self):
|
|
2871
|
+
return 200 <= self.status_code < 300
|
|
2872
|
+
|
|
2873
|
+
def json(self):
|
|
2874
|
+
return json.loads(self.text)
|
|
2875
|
+
|
|
2876
|
+
def raise_for_status(self):
|
|
2877
|
+
if self._error:
|
|
2878
|
+
raise Exception(self._error)
|
|
2879
|
+
if not self.ok:
|
|
2880
|
+
raise Exception(f"HTTP {self.status_code}: {self.reason}")
|
|
2881
|
+
|
|
2882
|
+
class _JbHttp:
|
|
2883
|
+
"""HTTP client that bridges to just-bash's secureFetch via custom FS"""
|
|
2884
|
+
def _do_request(self, method, url, headers=None, body=None):
|
|
2885
|
+
import json as _json
|
|
2886
|
+
req = _json.dumps({'url': url, 'method': method, 'headers': headers, 'body': body})
|
|
2887
|
+
# Write request to HTTPFS \u2014 close triggers the HTTP call synchronously
|
|
2888
|
+
with _orig_open('/_jb_http/request', 'w') as f:
|
|
2889
|
+
f.write(req)
|
|
2890
|
+
# Read response (cached by HTTPFS from the HTTP call above)
|
|
2891
|
+
with _orig_open('/_jb_http/request', 'r') as f:
|
|
2892
|
+
return _json.loads(f.read())
|
|
2893
|
+
|
|
2894
|
+
def request(self, method, url, headers=None, data=None, json_data=None):
|
|
2895
|
+
if json_data is not None:
|
|
2896
|
+
data = json.dumps(json_data)
|
|
2897
|
+
headers = headers or {}
|
|
2898
|
+
headers['Content-Type'] = 'application/json'
|
|
2899
|
+
result = self._do_request(method, url, headers, data)
|
|
2900
|
+
if 'error' in result and result.get('status') is None:
|
|
2901
|
+
raise Exception(result['error'])
|
|
2902
|
+
return _JbHttpResponse(result)
|
|
2903
|
+
|
|
2904
|
+
def get(self, url, headers=None, **kwargs):
|
|
2905
|
+
return self.request('GET', url, headers=headers, **kwargs)
|
|
2906
|
+
|
|
2907
|
+
def post(self, url, headers=None, data=None, json=None, **kwargs):
|
|
2908
|
+
return self.request('POST', url, headers=headers, data=data, json_data=json, **kwargs)
|
|
2909
|
+
|
|
2910
|
+
def put(self, url, headers=None, data=None, json=None, **kwargs):
|
|
2911
|
+
return self.request('PUT', url, headers=headers, data=data, json_data=json, **kwargs)
|
|
2912
|
+
|
|
2913
|
+
def delete(self, url, headers=None, **kwargs):
|
|
2914
|
+
return self.request('DELETE', url, headers=headers, **kwargs)
|
|
2915
|
+
|
|
2916
|
+
def head(self, url, headers=None, **kwargs):
|
|
2917
|
+
return self.request('HEAD', url, headers=headers, **kwargs)
|
|
2918
|
+
|
|
2919
|
+
def patch(self, url, headers=None, data=None, json=None, **kwargs):
|
|
2920
|
+
return self.request('PATCH', url, headers=headers, data=data, json_data=json, **kwargs)
|
|
2921
|
+
|
|
2922
|
+
import types
|
|
2923
|
+
jb_http = types.ModuleType('jb_http')
|
|
2924
|
+
jb_http._client = _JbHttp()
|
|
2925
|
+
jb_http.get = jb_http._client.get
|
|
2926
|
+
jb_http.post = jb_http._client.post
|
|
2927
|
+
jb_http.put = jb_http._client.put
|
|
2928
|
+
jb_http.delete = jb_http._client.delete
|
|
2929
|
+
jb_http.head = jb_http._client.head
|
|
2930
|
+
jb_http.patch = jb_http._client.patch
|
|
2931
|
+
jb_http.request = jb_http._client.request
|
|
2932
|
+
jb_http.Response = _JbHttpResponse
|
|
2933
|
+
sys.modules['jb_http'] = jb_http
|
|
2934
|
+
`;
|
|
2935
|
+
}
|
|
2936
|
+
var cachedStdlibZip = new Uint8Array(readFileSync(stdlibZipPath));
|
|
2937
|
+
function wrapWorkerMessage(protocolToken, message) {
|
|
2938
|
+
const wrapped = /* @__PURE__ */ Object.create(null);
|
|
2939
|
+
if (!message || typeof message !== "object") {
|
|
2940
|
+
wrapped.success = false;
|
|
2941
|
+
wrapped.error = "Worker attempted to post non-object message";
|
|
2942
|
+
wrapped.protocolToken = protocolToken;
|
|
2943
|
+
return wrapped;
|
|
2944
|
+
}
|
|
2945
|
+
for (const [key, value] of Object.entries(message))
|
|
2946
|
+
wrapped[key] = value;
|
|
2947
|
+
wrapped.protocolToken = protocolToken;
|
|
2948
|
+
return wrapped;
|
|
2949
|
+
}
|
|
2950
|
+
function postWorkerMessage(protocolToken, message) {
|
|
2951
|
+
try {
|
|
2952
|
+
parentPort?.postMessage(wrapWorkerMessage(protocolToken, message));
|
|
2953
|
+
} catch (error) {
|
|
2954
|
+
console.debug(
|
|
2955
|
+
"[python3-worker] failed to post worker message:",
|
|
2956
|
+
sanitizeUnknownError(error)
|
|
2957
|
+
);
|
|
2958
|
+
}
|
|
2959
|
+
}
|
|
2960
|
+
async function runPython(input) {
|
|
2961
|
+
if (!moduleLoadGuardInstalled) {
|
|
2962
|
+
return {
|
|
2963
|
+
success: false,
|
|
2964
|
+
error: "Defense-in-depth module-loader guard failed to initialize; refusing to execute Python worker"
|
|
2965
|
+
};
|
|
2966
|
+
}
|
|
2967
|
+
const backend = new SyncBackend(input.sharedBuffer, input.timeoutMs);
|
|
2968
|
+
assertApprovedPath(cpythonEntryPath, "cpython-entry");
|
|
2969
|
+
const createPythonModule = require2(cpythonEntryPath);
|
|
2970
|
+
let moduleReady = false;
|
|
2971
|
+
const pendingStdout = [];
|
|
2972
|
+
const pendingStderr = [];
|
|
2973
|
+
let Module;
|
|
2974
|
+
try {
|
|
2975
|
+
const onPreRun = wrapWasmCallback(
|
|
2976
|
+
"python3-worker",
|
|
2977
|
+
"preRun",
|
|
2978
|
+
(mod) => {
|
|
2979
|
+
mod.FS.mkdirTree("/lib");
|
|
2980
|
+
mod.FS.writeFile("/lib/python313.zip", cachedStdlibZip);
|
|
2981
|
+
mod.ENV.PYTHONHOME = "/";
|
|
2982
|
+
mod.ENV.PYTHONPATH = "/lib/python313.zip";
|
|
2983
|
+
}
|
|
2984
|
+
);
|
|
2985
|
+
const onPrint = wrapWasmCallback(
|
|
2986
|
+
"python3-worker",
|
|
2987
|
+
"print",
|
|
2988
|
+
(text) => {
|
|
2989
|
+
if (moduleReady) {
|
|
2990
|
+
backend.writeStdout(`${text}
|
|
2991
|
+
`);
|
|
2992
|
+
} else {
|
|
2993
|
+
pendingStdout.push(`${text}
|
|
2994
|
+
`);
|
|
2995
|
+
}
|
|
2996
|
+
}
|
|
2997
|
+
);
|
|
2998
|
+
const onPrintErr = wrapWasmCallback(
|
|
2999
|
+
"python3-worker",
|
|
3000
|
+
"printErr",
|
|
3001
|
+
(text) => {
|
|
3002
|
+
if (typeof text === "string" && (text.includes("Could not find platform") || text.includes("LLVM Profile Error"))) {
|
|
3003
|
+
return;
|
|
3004
|
+
}
|
|
3005
|
+
if (moduleReady) {
|
|
3006
|
+
backend.writeStderr(`${text}
|
|
3007
|
+
`);
|
|
3008
|
+
} else {
|
|
3009
|
+
pendingStderr.push(`${text}
|
|
3010
|
+
`);
|
|
3011
|
+
}
|
|
3012
|
+
}
|
|
3013
|
+
);
|
|
3014
|
+
Module = await createPythonModule({
|
|
3015
|
+
noInitialRun: true,
|
|
3016
|
+
preRun: [onPreRun],
|
|
3017
|
+
print: onPrint,
|
|
3018
|
+
printErr: onPrintErr
|
|
3019
|
+
});
|
|
3020
|
+
} catch (e) {
|
|
3021
|
+
const message = sanitizeHostErrorMessage(e.message);
|
|
3022
|
+
return {
|
|
3023
|
+
success: false,
|
|
3024
|
+
error: `Failed to load CPython: ${message}`
|
|
3025
|
+
};
|
|
3026
|
+
}
|
|
3027
|
+
activateDefense(input.protocolToken);
|
|
3028
|
+
moduleReady = true;
|
|
3029
|
+
for (const text of pendingStdout) backend.writeStdout(text);
|
|
3030
|
+
for (const text of pendingStderr) backend.writeStderr(text);
|
|
3031
|
+
const HOSTFS = createHOSTFS(backend, Module.FS, Module.PATH);
|
|
3032
|
+
try {
|
|
3033
|
+
Module.FS.mkdir("/host");
|
|
3034
|
+
Module.FS.mount(HOSTFS, { root: "/" }, "/host");
|
|
3035
|
+
} catch (e) {
|
|
3036
|
+
const message = sanitizeHostErrorMessage(e.message);
|
|
3037
|
+
return {
|
|
3038
|
+
success: false,
|
|
3039
|
+
error: `Failed to mount HOSTFS: ${message}`
|
|
3040
|
+
};
|
|
3041
|
+
}
|
|
3042
|
+
const HTTPFS = createHTTPFS(backend, Module.FS);
|
|
3043
|
+
try {
|
|
3044
|
+
Module.FS.mkdir("/_jb_http");
|
|
3045
|
+
Module.FS.mount(HTTPFS, { root: "/" }, "/_jb_http");
|
|
3046
|
+
} catch (e) {
|
|
3047
|
+
const message = sanitizeHostErrorMessage(e.message);
|
|
3048
|
+
return {
|
|
3049
|
+
success: false,
|
|
3050
|
+
error: `Failed to mount HTTPFS: ${message}`
|
|
3051
|
+
};
|
|
3052
|
+
}
|
|
3053
|
+
const setupCode = generateSetupCode(input);
|
|
3054
|
+
const httpBridgeCode = generateHttpBridgeCode();
|
|
3055
|
+
const wrappedCode = `
|
|
3056
|
+
import sys
|
|
3057
|
+
_jb_exit_code = 0
|
|
3058
|
+
try:
|
|
3059
|
+
${setupCode.split("\n").map((line) => ` ${line}`).join("\n")}
|
|
3060
|
+
${httpBridgeCode.split("\n").map((line) => ` ${line}`).join("\n")}
|
|
3061
|
+
${input.pythonCode.split("\n").map((line) => ` ${line}`).join("\n")}
|
|
3062
|
+
except SystemExit as e:
|
|
3063
|
+
_jb_exit_code = e.code if isinstance(e.code, int) else (1 if e.code else 0)
|
|
3064
|
+
except Exception as e:
|
|
3065
|
+
import traceback
|
|
3066
|
+
traceback.print_exc()
|
|
3067
|
+
_jb_exit_code = 1
|
|
3068
|
+
sys.exit(_jb_exit_code)
|
|
3069
|
+
`;
|
|
3070
|
+
try {
|
|
3071
|
+
Module.FS.mkdir("/tmp");
|
|
3072
|
+
} catch (_e) {
|
|
3073
|
+
}
|
|
3074
|
+
const encoder = new TextEncoder();
|
|
3075
|
+
const scriptPath = "/tmp/_jb_script.py";
|
|
3076
|
+
const scriptData = encoder.encode(wrappedCode);
|
|
3077
|
+
Module.FS.writeFile(scriptPath, scriptData);
|
|
3078
|
+
try {
|
|
3079
|
+
const ret = Module.callMain([scriptPath]);
|
|
3080
|
+
const exitCode = (typeof ret === "number" ? ret : 0) || process.exitCode || 0;
|
|
3081
|
+
backend.exit(exitCode);
|
|
3082
|
+
return { success: true };
|
|
3083
|
+
} catch (e) {
|
|
3084
|
+
const error = e;
|
|
3085
|
+
const exitCode = error.status ?? process.exitCode ?? 1;
|
|
3086
|
+
backend.exit(exitCode);
|
|
3087
|
+
return { success: true };
|
|
3088
|
+
}
|
|
3089
|
+
}
|
|
3090
|
+
var defense = null;
|
|
3091
|
+
function activateDefense(protocolToken) {
|
|
3092
|
+
if (defense) return;
|
|
3093
|
+
const _DateNow = Date.now;
|
|
3094
|
+
const degraded = { now: () => _DateNow(), timeOrigin: _DateNow() };
|
|
3095
|
+
Object.defineProperty(globalThis, "performance", {
|
|
3096
|
+
value: degraded,
|
|
3097
|
+
writable: true,
|
|
3098
|
+
configurable: true
|
|
3099
|
+
});
|
|
3100
|
+
const onViolation = wrapWasmCallback(
|
|
3101
|
+
"python3-worker",
|
|
3102
|
+
"onViolation",
|
|
3103
|
+
(v) => {
|
|
3104
|
+
postWorkerMessage(protocolToken, {
|
|
3105
|
+
type: "security-violation",
|
|
3106
|
+
violation: v
|
|
3107
|
+
});
|
|
3108
|
+
}
|
|
3109
|
+
);
|
|
3110
|
+
defense = new WorkerDefenseInDepth({
|
|
3111
|
+
excludeViolationTypes: [
|
|
3112
|
+
// SharedArrayBuffer/Atomics: Used by sync-fs-backend.ts for synchronous
|
|
3113
|
+
// filesystem communication between the WASM thread and the main thread.
|
|
3114
|
+
"shared_array_buffer",
|
|
3115
|
+
"atomics",
|
|
3116
|
+
// performance: Excluded because we replaced it above with a ms-precision
|
|
3117
|
+
// stub. Defense doesn't need to block it — it's already degraded.
|
|
3118
|
+
"performance_timing"
|
|
3119
|
+
],
|
|
3120
|
+
onViolation
|
|
3121
|
+
});
|
|
3122
|
+
}
|
|
3123
|
+
process.on("uncaughtException", (e) => {
|
|
3124
|
+
if (!activeProtocolToken) {
|
|
3125
|
+
return;
|
|
3126
|
+
}
|
|
3127
|
+
const message = sanitizeHostErrorMessage(e.message);
|
|
3128
|
+
postWorkerMessage(activeProtocolToken, {
|
|
3129
|
+
success: false,
|
|
3130
|
+
error: `Worker uncaught exception: ${message}`
|
|
3131
|
+
});
|
|
3132
|
+
});
|
|
3133
|
+
var activeProtocolToken = null;
|
|
3134
|
+
if (parentPort) {
|
|
3135
|
+
if (workerData) {
|
|
3136
|
+
const input = workerData;
|
|
3137
|
+
activeProtocolToken = input.protocolToken;
|
|
3138
|
+
runPython(input).then((result) => {
|
|
3139
|
+
result.defenseStats = defense?.getStats();
|
|
3140
|
+
postWorkerMessage(input.protocolToken, result);
|
|
3141
|
+
}).catch((e) => {
|
|
3142
|
+
const message = sanitizeUnknownError(e);
|
|
3143
|
+
postWorkerMessage(input.protocolToken, {
|
|
3144
|
+
success: false,
|
|
3145
|
+
error: message,
|
|
3146
|
+
defenseStats: defense?.getStats()
|
|
3147
|
+
});
|
|
3148
|
+
});
|
|
3149
|
+
}
|
|
3150
|
+
}
|