just-binary 2.9.8
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/LICENSE +201 -0
- package/README.md +458 -0
- package/dist/AGENTS.md +323 -0
- package/dist/Bash.d.ts +179 -0
- package/dist/ast/types.d.ts +615 -0
- package/dist/banned-patterns-test.d.ts +8 -0
- package/dist/bin/chunks/alias-23G4Q2RS.js +2 -0
- package/dist/bin/chunks/awk2-Z6VRXKAK.js +2 -0
- package/dist/bin/chunks/base64-DNX4WCIO.js +2 -0
- package/dist/bin/chunks/basename-MPQ7M4RF.js +2 -0
- package/dist/bin/chunks/bash-OQ32Y5I6.js +2 -0
- package/dist/bin/chunks/bytes-6YUZMX3P.js +2 -0
- package/dist/bin/chunks/cat-CL5ISR5P.js +2 -0
- package/dist/bin/chunks/chmod-R6IWRSKZ.js +2 -0
- package/dist/bin/chunks/chunk-227L3ACM.js +23 -0
- package/dist/bin/chunks/chunk-2QA4P6HI.js +12 -0
- package/dist/bin/chunks/chunk-3MFM4GSH.js +36 -0
- package/dist/bin/chunks/chunk-3UP5LXDO.js +3 -0
- package/dist/bin/chunks/chunk-47P7JSQI.js +2 -0
- package/dist/bin/chunks/chunk-4KBTPDQB.js +3 -0
- package/dist/bin/chunks/chunk-4UK2MV3F.js +13 -0
- package/dist/bin/chunks/chunk-4VDEBYW7.js +2 -0
- package/dist/bin/chunks/chunk-563AO4OL.js +7 -0
- package/dist/bin/chunks/chunk-5HDWUXRX.js +7 -0
- package/dist/bin/chunks/chunk-5MCFI6LE.js +5 -0
- package/dist/bin/chunks/chunk-6CZOPIZD.js +6 -0
- package/dist/bin/chunks/chunk-6FNFX5GG.js +5 -0
- package/dist/bin/chunks/chunk-6NYIHYDY.js +7 -0
- package/dist/bin/chunks/chunk-6Y4TKR73.js +16 -0
- package/dist/bin/chunks/chunk-7C7WEK46.js +23 -0
- package/dist/bin/chunks/chunk-7TNGQWY6.js +6 -0
- package/dist/bin/chunks/chunk-7UAWRBQS.js +9 -0
- package/dist/bin/chunks/chunk-ARGU3OIG.js +17 -0
- package/dist/bin/chunks/chunk-BA3A5BYZ.js +3 -0
- package/dist/bin/chunks/chunk-BB7T22CF.js +140 -0
- package/dist/bin/chunks/chunk-BY24LKGP.js +8 -0
- package/dist/bin/chunks/chunk-CRHN4WNQ.js +63 -0
- package/dist/bin/chunks/chunk-ELZHJGI7.js +10 -0
- package/dist/bin/chunks/chunk-F46CSMUF.js +2 -0
- package/dist/bin/chunks/chunk-FQX4G5RH.js +7 -0
- package/dist/bin/chunks/chunk-G43H2WGH.js +17 -0
- package/dist/bin/chunks/chunk-GIFF636B.js +2 -0
- package/dist/bin/chunks/chunk-GMJWC3MC.js +12 -0
- package/dist/bin/chunks/chunk-HVDU57EV.js +16 -0
- package/dist/bin/chunks/chunk-HWGK3XW7.js +6 -0
- package/dist/bin/chunks/chunk-HYR7G7KS.js +3 -0
- package/dist/bin/chunks/chunk-I2225JSU.js +14 -0
- package/dist/bin/chunks/chunk-I2FUQZXU.js +11 -0
- package/dist/bin/chunks/chunk-IBHPKKIT.js +10 -0
- package/dist/bin/chunks/chunk-IKNNFJNZ.js +14 -0
- package/dist/bin/chunks/chunk-INPUJM7Y.js +8 -0
- package/dist/bin/chunks/chunk-IOBKPMWJ.js +9 -0
- package/dist/bin/chunks/chunk-IYSA2L6A.js +13 -0
- package/dist/bin/chunks/chunk-JMLNX7GE.js +287 -0
- package/dist/bin/chunks/chunk-K2K4KPOQ.js +3 -0
- package/dist/bin/chunks/chunk-K6DD7NH3.js +9 -0
- package/dist/bin/chunks/chunk-KFLJ4EMB.js +4 -0
- package/dist/bin/chunks/chunk-KOMDAXHM.js +7 -0
- package/dist/bin/chunks/chunk-KV7ZTM2R.js +11 -0
- package/dist/bin/chunks/chunk-LCCVVEJA.js +10 -0
- package/dist/bin/chunks/chunk-LUPJK5US.js +84 -0
- package/dist/bin/chunks/chunk-LWF3XDOC.js +32 -0
- package/dist/bin/chunks/chunk-LXNARM2C.js +9 -0
- package/dist/bin/chunks/chunk-LXZS3X5T.js +9 -0
- package/dist/bin/chunks/chunk-M4ICSCXT.js +100 -0
- package/dist/bin/chunks/chunk-MEBZXRGE.js +5 -0
- package/dist/bin/chunks/chunk-MSPSS36S.js +16 -0
- package/dist/bin/chunks/chunk-N335RIGZ.js +20 -0
- package/dist/bin/chunks/chunk-N5KGQWJH.js +5 -0
- package/dist/bin/chunks/chunk-NDHTQE5T.js +8 -0
- package/dist/bin/chunks/chunk-NF5G7X3O.js +7 -0
- package/dist/bin/chunks/chunk-NGKNJ6V2.js +11 -0
- package/dist/bin/chunks/chunk-OBH7XN5N.js +1 -0
- package/dist/bin/chunks/chunk-OKQ6RACF.js +73 -0
- package/dist/bin/chunks/chunk-PBY7XGZ6.js +8 -0
- package/dist/bin/chunks/chunk-PHHNNFRS.js +6 -0
- package/dist/bin/chunks/chunk-PO6Y7TWQ.js +6 -0
- package/dist/bin/chunks/chunk-Q4TLKLIZ.js +12 -0
- package/dist/bin/chunks/chunk-QS6LP3E3.js +6 -0
- package/dist/bin/chunks/chunk-QT2GMJRJ.js +8 -0
- package/dist/bin/chunks/chunk-QUVW3R4I.js +5 -0
- package/dist/bin/chunks/chunk-QUYWT2TY.js +21 -0
- package/dist/bin/chunks/chunk-QWUII542.js +2 -0
- package/dist/bin/chunks/chunk-R5EQDD5Y.js +13 -0
- package/dist/bin/chunks/chunk-RQSPCXDR.js +2 -0
- package/dist/bin/chunks/chunk-RTC6C5QW.js +2 -0
- package/dist/bin/chunks/chunk-S5W2KVHC.js +2 -0
- package/dist/bin/chunks/chunk-SDXDICI4.js +2 -0
- package/dist/bin/chunks/chunk-SE4C7FJY.js +33 -0
- package/dist/bin/chunks/chunk-SX7TI7Q2.js +3 -0
- package/dist/bin/chunks/chunk-TDJ55L4A.js +16 -0
- package/dist/bin/chunks/chunk-TNPUAMV3.js +8 -0
- package/dist/bin/chunks/chunk-TSGSFBQI.js +14 -0
- package/dist/bin/chunks/chunk-U5ZE562V.js +2 -0
- package/dist/bin/chunks/chunk-UIMH6I3G.js +33 -0
- package/dist/bin/chunks/chunk-UXPY5T2P.js +9 -0
- package/dist/bin/chunks/chunk-UYBH3FNE.js +2 -0
- package/dist/bin/chunks/chunk-V5I6PHN2.js +14 -0
- package/dist/bin/chunks/chunk-VOTJNR36.js +5 -0
- package/dist/bin/chunks/chunk-W5XFREQC.js +3 -0
- package/dist/bin/chunks/chunk-X2MOXVGO.js +26 -0
- package/dist/bin/chunks/chunk-XOGQUO62.js +2 -0
- package/dist/bin/chunks/chunk-Y57BDPQ5.js +6 -0
- package/dist/bin/chunks/chunk-YE6KXFFU.js +2 -0
- package/dist/bin/chunks/chunk-YEPWKN4F.js +3 -0
- package/dist/bin/chunks/chunk-ZEDWVSUZ.js +19 -0
- package/dist/bin/chunks/chunk-ZI4TTZL5.js +21 -0
- package/dist/bin/chunks/chunk-ZZVIGHYS.js +7 -0
- package/dist/bin/chunks/clear-27OP2FQZ.js +2 -0
- package/dist/bin/chunks/column-FJNKONCJ.js +2 -0
- package/dist/bin/chunks/comm-5FNEJE7X.js +2 -0
- package/dist/bin/chunks/cp-LVKHKFHQ.js +2 -0
- package/dist/bin/chunks/curl-S4FJSZA5.js +26 -0
- package/dist/bin/chunks/cut-UXU6PNTT.js +2 -0
- package/dist/bin/chunks/date-GGPTXVUT.js +2 -0
- package/dist/bin/chunks/diff-3V3FOITV.js +2 -0
- package/dist/bin/chunks/dirname-455JDV2M.js +2 -0
- package/dist/bin/chunks/du-WUEAQO2W.js +2 -0
- package/dist/bin/chunks/echo-HBXOI5TQ.js +2 -0
- package/dist/bin/chunks/env-MXFHTVHS.js +2 -0
- package/dist/bin/chunks/expand-F4FM4ML2.js +2 -0
- package/dist/bin/chunks/expansion-7AYBVOIQ.js +2 -0
- package/dist/bin/chunks/expr-5ZKR5ER5.js +2 -0
- package/dist/bin/chunks/file-BFN7BKUR.js +2 -0
- package/dist/bin/chunks/find-W4BCEJEC.js +2 -0
- package/dist/bin/chunks/flag-coverage-DBKGNLJO.js +2 -0
- package/dist/bin/chunks/fold-AE57YLOS.js +2 -0
- package/dist/bin/chunks/grep-I63BWUKL.js +2 -0
- package/dist/bin/chunks/gzip-X5IDXWZE.js +2 -0
- package/dist/bin/chunks/head-TBQETLQX.js +2 -0
- package/dist/bin/chunks/help-HGMKZ2GW.js +2 -0
- package/dist/bin/chunks/history-2DYRIL3U.js +2 -0
- package/dist/bin/chunks/hostname-RWEPTCXH.js +2 -0
- package/dist/bin/chunks/html-to-markdown-2VQWCEKU.js +2 -0
- package/dist/bin/chunks/join-TRRWQBEU.js +2 -0
- package/dist/bin/chunks/jq-NFKKH27D.js +2 -0
- package/dist/bin/chunks/ln-BSEVUP2J.js +2 -0
- package/dist/bin/chunks/ls-IJLTWVOI.js +2 -0
- package/dist/bin/chunks/md5sum-ZIQHOC4K.js +2 -0
- package/dist/bin/chunks/mkdir-KYFAO2SF.js +2 -0
- package/dist/bin/chunks/mv-TWM2PA7Q.js +2 -0
- package/dist/bin/chunks/nl-XLF2HFST.js +2 -0
- package/dist/bin/chunks/od-BOM6JPTH.js +2 -0
- package/dist/bin/chunks/paste-FUGXVGJX.js +2 -0
- package/dist/bin/chunks/printf-XUGNJ3QM.js +2 -0
- package/dist/bin/chunks/pwd-RZG6GZEU.js +2 -0
- package/dist/bin/chunks/python3-PIXJS3YM.js +14 -0
- package/dist/bin/chunks/readlink-4SOSIDHE.js +2 -0
- package/dist/bin/chunks/rev-5E5UGSUZ.js +2 -0
- package/dist/bin/chunks/rg-4YJSQZN7.js +2 -0
- package/dist/bin/chunks/rm-3PFOF4E3.js +2 -0
- package/dist/bin/chunks/rmdir-CSK7CGH5.js +2 -0
- package/dist/bin/chunks/sed-XBCUZMEP.js +2 -0
- package/dist/bin/chunks/seq-H7ID4VMK.js +2 -0
- package/dist/bin/chunks/sha1sum-EDQNYXXH.js +2 -0
- package/dist/bin/chunks/sha256sum-APTG6DO2.js +2 -0
- package/dist/bin/chunks/sleep-PNT7KILS.js +2 -0
- package/dist/bin/chunks/sort-ELAGZUES.js +2 -0
- package/dist/bin/chunks/split-QGXYUWBC.js +2 -0
- package/dist/bin/chunks/sqlite3-ELLMKNNJ.js +2 -0
- package/dist/bin/chunks/stat-Q2TZRKO3.js +2 -0
- package/dist/bin/chunks/strings-IGEGP5QX.js +2 -0
- package/dist/bin/chunks/tac-VOEDJLLG.js +2 -0
- package/dist/bin/chunks/tail-JOQASWMV.js +2 -0
- package/dist/bin/chunks/tar-2UVSVD3P.js +2 -0
- package/dist/bin/chunks/tee-IQLEDZOQ.js +2 -0
- package/dist/bin/chunks/time-VRCJK2LI.js +2 -0
- package/dist/bin/chunks/timeout-A36YWZWR.js +2 -0
- package/dist/bin/chunks/touch-5ECNQNBP.js +2 -0
- package/dist/bin/chunks/tr-AVALLN54.js +2 -0
- package/dist/bin/chunks/tree-UFM5EDXS.js +2 -0
- package/dist/bin/chunks/true-BU5JSAAW.js +2 -0
- package/dist/bin/chunks/unexpand-TDRWZW5F.js +2 -0
- package/dist/bin/chunks/uniq-IKBUNAMN.js +2 -0
- package/dist/bin/chunks/wc-2R4RS2SX.js +2 -0
- package/dist/bin/chunks/which-6UVGMXDF.js +2 -0
- package/dist/bin/chunks/whoami-N6TLTETT.js +2 -0
- package/dist/bin/chunks/worker.js +2260 -0
- package/dist/bin/chunks/xan-JX5QUK32.js +2 -0
- package/dist/bin/chunks/xan-view-NFMUMJ7Z.js +2 -0
- package/dist/bin/chunks/xargs-4MYN4U3C.js +2 -0
- package/dist/bin/chunks/yq-EHDQVD7S.js +2 -0
- package/dist/bin/just-bash.js +732 -0
- package/dist/bin/shell/chunks/alias-23G4Q2RS.js +2 -0
- package/dist/bin/shell/chunks/awk2-Z6VRXKAK.js +2 -0
- package/dist/bin/shell/chunks/base64-DNX4WCIO.js +2 -0
- package/dist/bin/shell/chunks/basename-MPQ7M4RF.js +2 -0
- package/dist/bin/shell/chunks/bash-OQ32Y5I6.js +2 -0
- package/dist/bin/shell/chunks/bytes-6YUZMX3P.js +2 -0
- package/dist/bin/shell/chunks/cat-CL5ISR5P.js +2 -0
- package/dist/bin/shell/chunks/chmod-R6IWRSKZ.js +2 -0
- package/dist/bin/shell/chunks/chunk-227L3ACM.js +23 -0
- package/dist/bin/shell/chunks/chunk-2QA4P6HI.js +12 -0
- package/dist/bin/shell/chunks/chunk-3MFM4GSH.js +36 -0
- package/dist/bin/shell/chunks/chunk-3UP5LXDO.js +3 -0
- package/dist/bin/shell/chunks/chunk-47P7JSQI.js +2 -0
- package/dist/bin/shell/chunks/chunk-4KBTPDQB.js +3 -0
- package/dist/bin/shell/chunks/chunk-4UK2MV3F.js +13 -0
- package/dist/bin/shell/chunks/chunk-4VDEBYW7.js +2 -0
- package/dist/bin/shell/chunks/chunk-563AO4OL.js +7 -0
- package/dist/bin/shell/chunks/chunk-5HDWUXRX.js +7 -0
- package/dist/bin/shell/chunks/chunk-5MCFI6LE.js +5 -0
- package/dist/bin/shell/chunks/chunk-6CZOPIZD.js +6 -0
- package/dist/bin/shell/chunks/chunk-6FNFX5GG.js +5 -0
- package/dist/bin/shell/chunks/chunk-6NYIHYDY.js +7 -0
- package/dist/bin/shell/chunks/chunk-6Y4TKR73.js +16 -0
- package/dist/bin/shell/chunks/chunk-7C7WEK46.js +23 -0
- package/dist/bin/shell/chunks/chunk-7TNGQWY6.js +6 -0
- package/dist/bin/shell/chunks/chunk-7UAWRBQS.js +9 -0
- package/dist/bin/shell/chunks/chunk-ARGU3OIG.js +17 -0
- package/dist/bin/shell/chunks/chunk-BA3A5BYZ.js +3 -0
- package/dist/bin/shell/chunks/chunk-BB7T22CF.js +140 -0
- package/dist/bin/shell/chunks/chunk-BY24LKGP.js +8 -0
- package/dist/bin/shell/chunks/chunk-CRHN4WNQ.js +63 -0
- package/dist/bin/shell/chunks/chunk-ELZHJGI7.js +10 -0
- package/dist/bin/shell/chunks/chunk-F46CSMUF.js +2 -0
- package/dist/bin/shell/chunks/chunk-FQX4G5RH.js +7 -0
- package/dist/bin/shell/chunks/chunk-G43H2WGH.js +17 -0
- package/dist/bin/shell/chunks/chunk-GIFF636B.js +2 -0
- package/dist/bin/shell/chunks/chunk-GMJWC3MC.js +12 -0
- package/dist/bin/shell/chunks/chunk-HVDU57EV.js +16 -0
- package/dist/bin/shell/chunks/chunk-HWGK3XW7.js +6 -0
- package/dist/bin/shell/chunks/chunk-HYR7G7KS.js +3 -0
- package/dist/bin/shell/chunks/chunk-I2225JSU.js +14 -0
- package/dist/bin/shell/chunks/chunk-I2FUQZXU.js +11 -0
- package/dist/bin/shell/chunks/chunk-IBHPKKIT.js +10 -0
- package/dist/bin/shell/chunks/chunk-IKNNFJNZ.js +14 -0
- package/dist/bin/shell/chunks/chunk-INPUJM7Y.js +8 -0
- package/dist/bin/shell/chunks/chunk-IOBKPMWJ.js +9 -0
- package/dist/bin/shell/chunks/chunk-IYSA2L6A.js +13 -0
- package/dist/bin/shell/chunks/chunk-JMLNX7GE.js +287 -0
- package/dist/bin/shell/chunks/chunk-K2K4KPOQ.js +3 -0
- package/dist/bin/shell/chunks/chunk-K6DD7NH3.js +9 -0
- package/dist/bin/shell/chunks/chunk-KFLJ4EMB.js +4 -0
- package/dist/bin/shell/chunks/chunk-KOMDAXHM.js +7 -0
- package/dist/bin/shell/chunks/chunk-KV7ZTM2R.js +11 -0
- package/dist/bin/shell/chunks/chunk-LCCVVEJA.js +10 -0
- package/dist/bin/shell/chunks/chunk-LUPJK5US.js +84 -0
- package/dist/bin/shell/chunks/chunk-LWF3XDOC.js +32 -0
- package/dist/bin/shell/chunks/chunk-LXNARM2C.js +9 -0
- package/dist/bin/shell/chunks/chunk-LXZS3X5T.js +9 -0
- package/dist/bin/shell/chunks/chunk-M4ICSCXT.js +100 -0
- package/dist/bin/shell/chunks/chunk-MEBZXRGE.js +5 -0
- package/dist/bin/shell/chunks/chunk-MSPSS36S.js +16 -0
- package/dist/bin/shell/chunks/chunk-N335RIGZ.js +20 -0
- package/dist/bin/shell/chunks/chunk-N5KGQWJH.js +5 -0
- package/dist/bin/shell/chunks/chunk-NDHTQE5T.js +8 -0
- package/dist/bin/shell/chunks/chunk-NF5G7X3O.js +7 -0
- package/dist/bin/shell/chunks/chunk-NGKNJ6V2.js +11 -0
- package/dist/bin/shell/chunks/chunk-OBH7XN5N.js +1 -0
- package/dist/bin/shell/chunks/chunk-OKQ6RACF.js +73 -0
- package/dist/bin/shell/chunks/chunk-PBY7XGZ6.js +8 -0
- package/dist/bin/shell/chunks/chunk-PHHNNFRS.js +6 -0
- package/dist/bin/shell/chunks/chunk-PO6Y7TWQ.js +6 -0
- package/dist/bin/shell/chunks/chunk-Q4TLKLIZ.js +12 -0
- package/dist/bin/shell/chunks/chunk-QS6LP3E3.js +6 -0
- package/dist/bin/shell/chunks/chunk-QT2GMJRJ.js +8 -0
- package/dist/bin/shell/chunks/chunk-QUVW3R4I.js +5 -0
- package/dist/bin/shell/chunks/chunk-QUYWT2TY.js +21 -0
- package/dist/bin/shell/chunks/chunk-QWUII542.js +2 -0
- package/dist/bin/shell/chunks/chunk-R5EQDD5Y.js +13 -0
- package/dist/bin/shell/chunks/chunk-RQSPCXDR.js +2 -0
- package/dist/bin/shell/chunks/chunk-RTC6C5QW.js +2 -0
- package/dist/bin/shell/chunks/chunk-S5W2KVHC.js +2 -0
- package/dist/bin/shell/chunks/chunk-SDXDICI4.js +2 -0
- package/dist/bin/shell/chunks/chunk-SE4C7FJY.js +33 -0
- package/dist/bin/shell/chunks/chunk-SX7TI7Q2.js +3 -0
- package/dist/bin/shell/chunks/chunk-TDJ55L4A.js +16 -0
- package/dist/bin/shell/chunks/chunk-TNPUAMV3.js +8 -0
- package/dist/bin/shell/chunks/chunk-TSGSFBQI.js +14 -0
- package/dist/bin/shell/chunks/chunk-U5ZE562V.js +2 -0
- package/dist/bin/shell/chunks/chunk-UIMH6I3G.js +33 -0
- package/dist/bin/shell/chunks/chunk-UXPY5T2P.js +9 -0
- package/dist/bin/shell/chunks/chunk-UYBH3FNE.js +2 -0
- package/dist/bin/shell/chunks/chunk-V5I6PHN2.js +14 -0
- package/dist/bin/shell/chunks/chunk-VOTJNR36.js +5 -0
- package/dist/bin/shell/chunks/chunk-W5XFREQC.js +3 -0
- package/dist/bin/shell/chunks/chunk-X2MOXVGO.js +26 -0
- package/dist/bin/shell/chunks/chunk-XOGQUO62.js +2 -0
- package/dist/bin/shell/chunks/chunk-Y57BDPQ5.js +6 -0
- package/dist/bin/shell/chunks/chunk-YE6KXFFU.js +2 -0
- package/dist/bin/shell/chunks/chunk-YEPWKN4F.js +3 -0
- package/dist/bin/shell/chunks/chunk-ZEDWVSUZ.js +19 -0
- package/dist/bin/shell/chunks/chunk-ZI4TTZL5.js +21 -0
- package/dist/bin/shell/chunks/chunk-ZZVIGHYS.js +7 -0
- package/dist/bin/shell/chunks/clear-27OP2FQZ.js +2 -0
- package/dist/bin/shell/chunks/column-FJNKONCJ.js +2 -0
- package/dist/bin/shell/chunks/comm-5FNEJE7X.js +2 -0
- package/dist/bin/shell/chunks/cp-LVKHKFHQ.js +2 -0
- package/dist/bin/shell/chunks/curl-S4FJSZA5.js +26 -0
- package/dist/bin/shell/chunks/cut-UXU6PNTT.js +2 -0
- package/dist/bin/shell/chunks/date-GGPTXVUT.js +2 -0
- package/dist/bin/shell/chunks/diff-3V3FOITV.js +2 -0
- package/dist/bin/shell/chunks/dirname-455JDV2M.js +2 -0
- package/dist/bin/shell/chunks/du-WUEAQO2W.js +2 -0
- package/dist/bin/shell/chunks/echo-HBXOI5TQ.js +2 -0
- package/dist/bin/shell/chunks/env-MXFHTVHS.js +2 -0
- package/dist/bin/shell/chunks/expand-F4FM4ML2.js +2 -0
- package/dist/bin/shell/chunks/expansion-7AYBVOIQ.js +2 -0
- package/dist/bin/shell/chunks/expr-5ZKR5ER5.js +2 -0
- package/dist/bin/shell/chunks/file-BFN7BKUR.js +2 -0
- package/dist/bin/shell/chunks/find-W4BCEJEC.js +2 -0
- package/dist/bin/shell/chunks/flag-coverage-DBKGNLJO.js +2 -0
- package/dist/bin/shell/chunks/fold-AE57YLOS.js +2 -0
- package/dist/bin/shell/chunks/grep-I63BWUKL.js +2 -0
- package/dist/bin/shell/chunks/gzip-X5IDXWZE.js +2 -0
- package/dist/bin/shell/chunks/head-TBQETLQX.js +2 -0
- package/dist/bin/shell/chunks/help-HGMKZ2GW.js +2 -0
- package/dist/bin/shell/chunks/history-2DYRIL3U.js +2 -0
- package/dist/bin/shell/chunks/hostname-RWEPTCXH.js +2 -0
- package/dist/bin/shell/chunks/html-to-markdown-2VQWCEKU.js +2 -0
- package/dist/bin/shell/chunks/join-TRRWQBEU.js +2 -0
- package/dist/bin/shell/chunks/jq-NFKKH27D.js +2 -0
- package/dist/bin/shell/chunks/ln-BSEVUP2J.js +2 -0
- package/dist/bin/shell/chunks/ls-IJLTWVOI.js +2 -0
- package/dist/bin/shell/chunks/md5sum-ZIQHOC4K.js +2 -0
- package/dist/bin/shell/chunks/mkdir-KYFAO2SF.js +2 -0
- package/dist/bin/shell/chunks/mv-TWM2PA7Q.js +2 -0
- package/dist/bin/shell/chunks/nl-XLF2HFST.js +2 -0
- package/dist/bin/shell/chunks/od-BOM6JPTH.js +2 -0
- package/dist/bin/shell/chunks/paste-FUGXVGJX.js +2 -0
- package/dist/bin/shell/chunks/printf-XUGNJ3QM.js +2 -0
- package/dist/bin/shell/chunks/pwd-RZG6GZEU.js +2 -0
- package/dist/bin/shell/chunks/python3-PIXJS3YM.js +14 -0
- package/dist/bin/shell/chunks/readlink-4SOSIDHE.js +2 -0
- package/dist/bin/shell/chunks/rev-5E5UGSUZ.js +2 -0
- package/dist/bin/shell/chunks/rg-4YJSQZN7.js +2 -0
- package/dist/bin/shell/chunks/rm-3PFOF4E3.js +2 -0
- package/dist/bin/shell/chunks/rmdir-CSK7CGH5.js +2 -0
- package/dist/bin/shell/chunks/sed-XBCUZMEP.js +2 -0
- package/dist/bin/shell/chunks/seq-H7ID4VMK.js +2 -0
- package/dist/bin/shell/chunks/sha1sum-EDQNYXXH.js +2 -0
- package/dist/bin/shell/chunks/sha256sum-APTG6DO2.js +2 -0
- package/dist/bin/shell/chunks/sleep-PNT7KILS.js +2 -0
- package/dist/bin/shell/chunks/sort-ELAGZUES.js +2 -0
- package/dist/bin/shell/chunks/split-QGXYUWBC.js +2 -0
- package/dist/bin/shell/chunks/sqlite3-ELLMKNNJ.js +2 -0
- package/dist/bin/shell/chunks/stat-Q2TZRKO3.js +2 -0
- package/dist/bin/shell/chunks/strings-IGEGP5QX.js +2 -0
- package/dist/bin/shell/chunks/tac-VOEDJLLG.js +2 -0
- package/dist/bin/shell/chunks/tail-JOQASWMV.js +2 -0
- package/dist/bin/shell/chunks/tar-2UVSVD3P.js +2 -0
- package/dist/bin/shell/chunks/tee-IQLEDZOQ.js +2 -0
- package/dist/bin/shell/chunks/time-VRCJK2LI.js +2 -0
- package/dist/bin/shell/chunks/timeout-A36YWZWR.js +2 -0
- package/dist/bin/shell/chunks/touch-5ECNQNBP.js +2 -0
- package/dist/bin/shell/chunks/tr-AVALLN54.js +2 -0
- package/dist/bin/shell/chunks/tree-UFM5EDXS.js +2 -0
- package/dist/bin/shell/chunks/true-BU5JSAAW.js +2 -0
- package/dist/bin/shell/chunks/unexpand-TDRWZW5F.js +2 -0
- package/dist/bin/shell/chunks/uniq-IKBUNAMN.js +2 -0
- package/dist/bin/shell/chunks/wc-2R4RS2SX.js +2 -0
- package/dist/bin/shell/chunks/which-6UVGMXDF.js +2 -0
- package/dist/bin/shell/chunks/whoami-N6TLTETT.js +2 -0
- package/dist/bin/shell/chunks/xan-JX5QUK32.js +2 -0
- package/dist/bin/shell/chunks/xan-view-NFMUMJ7Z.js +2 -0
- package/dist/bin/shell/chunks/xargs-4MYN4U3C.js +2 -0
- package/dist/bin/shell/chunks/yq-EHDQVD7S.js +2 -0
- package/dist/bin/shell/shell.js +711 -0
- package/dist/browser.d.ts +22 -0
- package/dist/bundle/browser.js +1481 -0
- package/dist/bundle/chunks/alias-T2KDAHDL.js +1 -0
- package/dist/bundle/chunks/awk2-UIH6CPHX.js +1 -0
- package/dist/bundle/chunks/base64-RY5JPAQL.js +1 -0
- package/dist/bundle/chunks/basename-QT55QR7O.js +1 -0
- package/dist/bundle/chunks/bash-BZZ6TUGW.js +1 -0
- package/dist/bundle/chunks/bytes-W6ESHQ7F.js +1 -0
- package/dist/bundle/chunks/cat-WUR2OJUG.js +1 -0
- package/dist/bundle/chunks/chmod-LTQYKUUW.js +1 -0
- package/dist/bundle/chunks/chunk-24BT6QUB.js +11 -0
- package/dist/bundle/chunks/chunk-274QVGRQ.js +2 -0
- package/dist/bundle/chunks/chunk-2IKXAFP4.js +11 -0
- package/dist/bundle/chunks/chunk-2IO54DPD.js +1 -0
- package/dist/bundle/chunks/chunk-2VAJD54D.js +13 -0
- package/dist/bundle/chunks/chunk-34P4G5H7.js +5 -0
- package/dist/bundle/chunks/chunk-3OY3UJDR.js +62 -0
- package/dist/bundle/chunks/chunk-3R6EWKMD.js +13 -0
- package/dist/bundle/chunks/chunk-3SPSXVPQ.js +2 -0
- package/dist/bundle/chunks/chunk-43RXAZRC.js +7 -0
- package/dist/bundle/chunks/chunk-44UOCSGV.js +1 -0
- package/dist/bundle/chunks/chunk-47LWQIG6.js +15 -0
- package/dist/bundle/chunks/chunk-4L3Y4LKT.js +5 -0
- package/dist/bundle/chunks/chunk-4LYDOEQ6.js +4 -0
- package/dist/bundle/chunks/chunk-4Q5DFBVQ.js +6 -0
- package/dist/bundle/chunks/chunk-4R5AUIZ4.js +6 -0
- package/dist/bundle/chunks/chunk-4UTZCT3W.js +2 -0
- package/dist/bundle/chunks/chunk-5FDLF2FN.js +5 -0
- package/dist/bundle/chunks/chunk-5HJSZMTG.js +1 -0
- package/dist/bundle/chunks/chunk-5NR6JZM4.js +12 -0
- package/dist/bundle/chunks/chunk-5PL72KVW.js +7 -0
- package/dist/bundle/chunks/chunk-6BM2WKUH.js +23 -0
- package/dist/bundle/chunks/chunk-6HLDZZOT.js +4 -0
- package/dist/bundle/chunks/chunk-7MKBHGLS.js +1 -0
- package/dist/bundle/chunks/chunk-7VHVF5PX.js +20 -0
- package/dist/bundle/chunks/chunk-A3YV3X3J.js +6 -0
- package/dist/bundle/chunks/chunk-AJNR4FJT.js +8 -0
- package/dist/bundle/chunks/chunk-AMQM5ZPF.js +1 -0
- package/dist/bundle/chunks/chunk-BCDE2QUY.js +1 -0
- package/dist/bundle/chunks/chunk-BMKJMOWP.js +2 -0
- package/dist/bundle/chunks/chunk-BVFIC7R6.js +4 -0
- package/dist/bundle/chunks/chunk-CC4HUWHZ.js +4 -0
- package/dist/bundle/chunks/chunk-CNCKROJZ.js +10 -0
- package/dist/bundle/chunks/chunk-CSFZQCAK.js +139 -0
- package/dist/bundle/chunks/chunk-CU7G2LMR.js +1 -0
- package/dist/bundle/chunks/chunk-CZP7PMAG.js +4 -0
- package/dist/bundle/chunks/chunk-D2OUCFAU.js +8 -0
- package/dist/bundle/chunks/chunk-DQXLKPVQ.js +7 -0
- package/dist/bundle/chunks/chunk-E6IR6BWV.js +286 -0
- package/dist/bundle/chunks/chunk-ELZ2RVIZ.js +11 -0
- package/dist/bundle/chunks/chunk-EVNUXIEZ.js +2 -0
- package/dist/bundle/chunks/chunk-F6FQRFZU.js +6 -0
- package/dist/bundle/chunks/chunk-FAECBHMR.js +2 -0
- package/dist/bundle/chunks/chunk-FBOLGXN4.js +16 -0
- package/dist/bundle/chunks/chunk-FNIOXBJW.js +9 -0
- package/dist/bundle/chunks/chunk-GD5SDRL7.js +5 -0
- package/dist/bundle/chunks/chunk-GEAGCSIY.js +31 -0
- package/dist/bundle/chunks/chunk-GI2KN5IL.js +22 -0
- package/dist/bundle/chunks/chunk-GOG2LNAH.js +9 -0
- package/dist/bundle/chunks/chunk-H2ENJVUI.js +10 -0
- package/dist/bundle/chunks/chunk-HDNR2KMO.js +13 -0
- package/dist/bundle/chunks/chunk-HJ37IXKX.js +12 -0
- package/dist/bundle/chunks/chunk-I36BZMR3.js +1 -0
- package/dist/bundle/chunks/chunk-I6YSZMB6.js +15 -0
- package/dist/bundle/chunks/chunk-IJXFPKNC.js +1 -0
- package/dist/bundle/chunks/chunk-IXD4Z54Z.js +8 -0
- package/dist/bundle/chunks/chunk-J44PYBAW.js +2 -0
- package/dist/bundle/chunks/chunk-JDREUEBG.js +9 -0
- package/dist/bundle/chunks/chunk-KA244HSE.js +5 -0
- package/dist/bundle/chunks/chunk-KKZJ6K7R.js +8 -0
- package/dist/bundle/chunks/chunk-KZ3P3SVS.js +22 -0
- package/dist/bundle/chunks/chunk-LIVSDOY2.js +1 -0
- package/dist/bundle/chunks/chunk-LX7SQKLW.js +15 -0
- package/dist/bundle/chunks/chunk-M5O5DYR7.js +1 -0
- package/dist/bundle/chunks/chunk-MML7K3J2.js +6 -0
- package/dist/bundle/chunks/chunk-N4GRDEVJ.js +5 -0
- package/dist/bundle/chunks/chunk-NPZMNEW5.js +6 -0
- package/dist/bundle/chunks/chunk-NUFRM6SI.js +0 -0
- package/dist/bundle/chunks/chunk-O7N2RCS7.js +1 -0
- package/dist/bundle/chunks/chunk-OSYLT4VG.js +4 -0
- package/dist/bundle/chunks/chunk-OXRHP7HO.js +3 -0
- package/dist/bundle/chunks/chunk-OZOS3R6K.js +99 -0
- package/dist/bundle/chunks/chunk-OZQ4AW5X.js +8 -0
- package/dist/bundle/chunks/chunk-PNGAWBIZ.js +10 -0
- package/dist/bundle/chunks/chunk-PPUKM2B7.js +13 -0
- package/dist/bundle/chunks/chunk-PTELGM2J.js +7 -0
- package/dist/bundle/chunks/chunk-Q3TLRYBC.js +72 -0
- package/dist/bundle/chunks/chunk-Q5AOYNOX.js +6 -0
- package/dist/bundle/chunks/chunk-QEKGAAIL.js +1 -0
- package/dist/bundle/chunks/chunk-QIL3FXIC.js +6 -0
- package/dist/bundle/chunks/chunk-QNZEO23C.js +8 -0
- package/dist/bundle/chunks/chunk-R4IVADTA.js +7 -0
- package/dist/bundle/chunks/chunk-RK57WTFF.js +12 -0
- package/dist/bundle/chunks/chunk-RU5M6ZRS.js +4 -0
- package/dist/bundle/chunks/chunk-SBVBPPEQ.js +5 -0
- package/dist/bundle/chunks/chunk-SP22LBKJ.js +20 -0
- package/dist/bundle/chunks/chunk-UKS3AEEA.js +32 -0
- package/dist/bundle/chunks/chunk-UYR5HJI6.js +7 -0
- package/dist/bundle/chunks/chunk-V6ANTLBA.js +15 -0
- package/dist/bundle/chunks/chunk-VLGZJRPG.js +16 -0
- package/dist/bundle/chunks/chunk-VZUQMDOT.js +2 -0
- package/dist/bundle/chunks/chunk-XDQU6V6S.js +19 -0
- package/dist/bundle/chunks/chunk-XRVUJRYI.js +35 -0
- package/dist/bundle/chunks/chunk-YNYSPYQ5.js +32 -0
- package/dist/bundle/chunks/clear-NLKZY76S.js +1 -0
- package/dist/bundle/chunks/column-S7P64XRJ.js +1 -0
- package/dist/bundle/chunks/comm-FPLN4BYY.js +1 -0
- package/dist/bundle/chunks/cp-W5HXJH5J.js +1 -0
- package/dist/bundle/chunks/curl-UFR6W4B6.js +25 -0
- package/dist/bundle/chunks/cut-VNFQFCA7.js +1 -0
- package/dist/bundle/chunks/date-EDSSFONA.js +1 -0
- package/dist/bundle/chunks/diff-RR5VJXIT.js +1 -0
- package/dist/bundle/chunks/dirname-V7Z24BGZ.js +1 -0
- package/dist/bundle/chunks/du-QKRPQIMY.js +1 -0
- package/dist/bundle/chunks/echo-TR3BM2AJ.js +1 -0
- package/dist/bundle/chunks/env-SVQBHVZF.js +1 -0
- package/dist/bundle/chunks/expand-ZVCJ72RF.js +1 -0
- package/dist/bundle/chunks/expansion-OBOJBZTH.js +1 -0
- package/dist/bundle/chunks/expr-QRA5KFYV.js +1 -0
- package/dist/bundle/chunks/file-TORG4IVZ.js +1 -0
- package/dist/bundle/chunks/find-NAGPRRQ7.js +1 -0
- package/dist/bundle/chunks/flag-coverage-FMTW4YWD.js +1 -0
- package/dist/bundle/chunks/fold-L4U6GS2N.js +1 -0
- package/dist/bundle/chunks/grep-D6AI423Z.js +1 -0
- package/dist/bundle/chunks/gzip-4EFUBHN7.js +1 -0
- package/dist/bundle/chunks/head-KBQT2JAC.js +1 -0
- package/dist/bundle/chunks/help-F3TJS3LS.js +1 -0
- package/dist/bundle/chunks/history-OKEAINJD.js +1 -0
- package/dist/bundle/chunks/hostname-AGIPNJOC.js +1 -0
- package/dist/bundle/chunks/html-to-markdown-P2LSCPVF.js +1 -0
- package/dist/bundle/chunks/join-FTSZAZYU.js +1 -0
- package/dist/bundle/chunks/jq-TNIKCGGT.js +1 -0
- package/dist/bundle/chunks/ln-BWYUCELO.js +1 -0
- package/dist/bundle/chunks/ls-6BM6G675.js +1 -0
- package/dist/bundle/chunks/md5sum-ALFVDB3W.js +1 -0
- package/dist/bundle/chunks/mkdir-I3BZBLTZ.js +1 -0
- package/dist/bundle/chunks/mv-76WRD5SE.js +1 -0
- package/dist/bundle/chunks/nl-77Q7V2GV.js +1 -0
- package/dist/bundle/chunks/od-AA6TIC6A.js +1 -0
- package/dist/bundle/chunks/paste-C6JKQOHO.js +1 -0
- package/dist/bundle/chunks/printf-WOYMDX2I.js +1 -0
- package/dist/bundle/chunks/pwd-BE3B3ZPG.js +1 -0
- package/dist/bundle/chunks/python3-QFUFNW7I.js +13 -0
- package/dist/bundle/chunks/readlink-QI6K7ZZX.js +1 -0
- package/dist/bundle/chunks/rev-2FZQEIQG.js +1 -0
- package/dist/bundle/chunks/rg-CNS6SD3V.js +1 -0
- package/dist/bundle/chunks/rm-JMWEKCU4.js +1 -0
- package/dist/bundle/chunks/rmdir-5HDB4IQ7.js +1 -0
- package/dist/bundle/chunks/sed-CSUGXVBJ.js +1 -0
- package/dist/bundle/chunks/seq-UP62NDEL.js +1 -0
- package/dist/bundle/chunks/sha1sum-XXYTWQIW.js +1 -0
- package/dist/bundle/chunks/sha256sum-GD6AFWG3.js +1 -0
- package/dist/bundle/chunks/sleep-225KIGXI.js +1 -0
- package/dist/bundle/chunks/sort-BIWEEIVX.js +1 -0
- package/dist/bundle/chunks/split-QUFGLTTX.js +1 -0
- package/dist/bundle/chunks/sqlite3-3ZFEGTQ7.js +1 -0
- package/dist/bundle/chunks/stat-DIMPSC6S.js +1 -0
- package/dist/bundle/chunks/strings-LECMRXOT.js +1 -0
- package/dist/bundle/chunks/tac-A6JKZKWL.js +1 -0
- package/dist/bundle/chunks/tail-YGDXZZGG.js +1 -0
- package/dist/bundle/chunks/tar-7KN7KZ6S.js +1 -0
- package/dist/bundle/chunks/tee-J4MBDQJZ.js +1 -0
- package/dist/bundle/chunks/time-CVS7ESWV.js +1 -0
- package/dist/bundle/chunks/timeout-UX2PSLYJ.js +1 -0
- package/dist/bundle/chunks/touch-ATQADRUQ.js +1 -0
- package/dist/bundle/chunks/tr-QVFN4YWH.js +1 -0
- package/dist/bundle/chunks/tree-IY7WNFVF.js +1 -0
- package/dist/bundle/chunks/true-AKKYE7WM.js +1 -0
- package/dist/bundle/chunks/unexpand-2WTX7UPB.js +1 -0
- package/dist/bundle/chunks/uniq-XS6VGRO2.js +1 -0
- package/dist/bundle/chunks/wc-22EISCPD.js +1 -0
- package/dist/bundle/chunks/which-IWHCX6SW.js +1 -0
- package/dist/bundle/chunks/whoami-HCON4D7C.js +1 -0
- package/dist/bundle/chunks/worker.js +2260 -0
- package/dist/bundle/chunks/xan-XDECJHII.js +1 -0
- package/dist/bundle/chunks/xan-view-IJ4EABH7.js +1 -0
- package/dist/bundle/chunks/xargs-5MMN7C6P.js +1 -0
- package/dist/bundle/chunks/yq-LQX5YIGM.js +1 -0
- package/dist/bundle/index.js +688 -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 +73 -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 +52 -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 +31 -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/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/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/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 +31 -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/fs-bridge-handler.d.ts +50 -0
- package/dist/commands/python3/protocol.d.ts +138 -0
- package/dist/commands/python3/python3.d.ts +11 -0
- package/dist/commands/python3/sync-fs-backend.d.ts +59 -0
- package/dist/commands/python3/worker.d.ts +22 -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 +37 -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 +59 -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 +45 -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 +60 -0
- package/dist/commands/search-engine/regex.d.ts +33 -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 +219 -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 +16 -0
- package/dist/commands/sqlite3/worker.d.ts +44 -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 +107 -0
- package/dist/commands/tar/tar-options.d.ts +36 -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/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 +61 -0
- package/dist/fs/encoding.d.ts +17 -0
- package/dist/fs/in-memory-fs/in-memory-fs.d.ts +63 -0
- package/dist/fs/in-memory-fs/index.d.ts +1 -0
- package/dist/fs/init.d.ts +12 -0
- package/dist/fs/interface.d.ts +219 -0
- package/dist/fs/mountable-fs/index.d.ts +1 -0
- package/dist/fs/mountable-fs/mountable-fs.d.ts +120 -0
- package/dist/fs/overlay-fs/index.d.ts +1 -0
- package/dist/fs/overlay-fs/overlay-fs.d.ts +126 -0
- package/dist/fs/read-write-fs/index.d.ts +1 -0
- package/dist/fs/read-write-fs/read-write-fs.d.ts +69 -0
- package/dist/index.d.ts +19 -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/errors.d.ts +150 -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 +43 -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 +57 -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 +18 -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 +62 -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 +29 -0
- package/dist/interpreter/helpers/xtrace.d.ts +18 -0
- package/dist/interpreter/index.d.ts +3 -0
- package/dist/interpreter/interpreter.d.ts +65 -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 +317 -0
- package/dist/limits.d.ts +42 -0
- package/dist/network/allow-list/shared.d.ts +45 -0
- package/dist/network/allow-list.d.ts +51 -0
- package/dist/network/fetch.d.ts +25 -0
- package/dist/network/index.d.ts +7 -0
- package/dist/network/types.d.ts +96 -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 +192 -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 +28 -0
- package/dist/sandbox/Sandbox.d.ts +60 -0
- package/dist/sandbox/index.d.ts +2 -0
- package/dist/shell-metadata.d.ts +28 -0
- package/dist/test-utils.d.ts +15 -0
- package/dist/types.d.ts +148 -0
- package/dist/utils/args.d.ts +55 -0
- package/dist/utils/bytes.d.ts +39 -0
- package/dist/utils/constants.d.ts +15 -0
- package/dist/utils/file-reader.d.ts +67 -0
- package/dist/utils/glob.d.ts +25 -0
- package/package.json +115 -0
|
@@ -0,0 +1,2260 @@
|
|
|
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
|
+
import { loadPyodide } from "pyodide";
|
|
13
|
+
|
|
14
|
+
// src/security/blocked-globals.ts
|
|
15
|
+
function getBlockedGlobals() {
|
|
16
|
+
const globals = [
|
|
17
|
+
// Direct code execution vectors
|
|
18
|
+
{
|
|
19
|
+
prop: "Function",
|
|
20
|
+
target: globalThis,
|
|
21
|
+
violationType: "function_constructor",
|
|
22
|
+
strategy: "throw",
|
|
23
|
+
reason: "Function constructor allows arbitrary code execution"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
prop: "eval",
|
|
27
|
+
target: globalThis,
|
|
28
|
+
violationType: "eval",
|
|
29
|
+
strategy: "throw",
|
|
30
|
+
reason: "eval() allows arbitrary code execution"
|
|
31
|
+
},
|
|
32
|
+
// Timer functions with string argument allow code execution
|
|
33
|
+
{
|
|
34
|
+
prop: "setTimeout",
|
|
35
|
+
target: globalThis,
|
|
36
|
+
violationType: "setTimeout",
|
|
37
|
+
strategy: "throw",
|
|
38
|
+
reason: "setTimeout with string argument allows code execution"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
prop: "setInterval",
|
|
42
|
+
target: globalThis,
|
|
43
|
+
violationType: "setInterval",
|
|
44
|
+
strategy: "throw",
|
|
45
|
+
reason: "setInterval with string argument allows code execution"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
prop: "setImmediate",
|
|
49
|
+
target: globalThis,
|
|
50
|
+
violationType: "setImmediate",
|
|
51
|
+
strategy: "throw",
|
|
52
|
+
reason: "setImmediate could be used to escape sandbox context"
|
|
53
|
+
},
|
|
54
|
+
// Note: We intentionally do NOT block `process` entirely because:
|
|
55
|
+
// 1. Node.js internals (Promise resolution, etc.) use process.nextTick
|
|
56
|
+
// 2. Blocking process entirely breaks normal async operation
|
|
57
|
+
// 3. The primary code execution vectors (Function, eval) are already blocked
|
|
58
|
+
// However, we DO block specific dangerous process properties.
|
|
59
|
+
{
|
|
60
|
+
prop: "env",
|
|
61
|
+
target: process,
|
|
62
|
+
violationType: "process_env",
|
|
63
|
+
strategy: "throw",
|
|
64
|
+
reason: "process.env could leak sensitive environment variables"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
prop: "binding",
|
|
68
|
+
target: process,
|
|
69
|
+
violationType: "process_binding",
|
|
70
|
+
strategy: "throw",
|
|
71
|
+
reason: "process.binding provides access to native Node.js modules"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
prop: "_linkedBinding",
|
|
75
|
+
target: process,
|
|
76
|
+
violationType: "process_binding",
|
|
77
|
+
strategy: "throw",
|
|
78
|
+
reason: "process._linkedBinding provides access to native Node.js modules"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
prop: "dlopen",
|
|
82
|
+
target: process,
|
|
83
|
+
violationType: "process_dlopen",
|
|
84
|
+
strategy: "throw",
|
|
85
|
+
reason: "process.dlopen allows loading native addons"
|
|
86
|
+
},
|
|
87
|
+
// Note: process.mainModule is handled specially in defense-in-depth-box.ts
|
|
88
|
+
// and worker-defense-in-depth.ts because it may be undefined in ESM contexts
|
|
89
|
+
// but we still want to block both reading and setting it.
|
|
90
|
+
// We also don't block `require` because:
|
|
91
|
+
// 1. It may not exist in all environments (ESM)
|
|
92
|
+
// 2. import() is the modern escape vector and can't be blocked this way
|
|
93
|
+
// Reference leak vectors
|
|
94
|
+
{
|
|
95
|
+
prop: "WeakRef",
|
|
96
|
+
target: globalThis,
|
|
97
|
+
violationType: "weak_ref",
|
|
98
|
+
strategy: "throw",
|
|
99
|
+
reason: "WeakRef could be used to leak references outside sandbox"
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
prop: "FinalizationRegistry",
|
|
103
|
+
target: globalThis,
|
|
104
|
+
violationType: "finalization_registry",
|
|
105
|
+
strategy: "throw",
|
|
106
|
+
reason: "FinalizationRegistry could be used to leak references outside sandbox"
|
|
107
|
+
},
|
|
108
|
+
// Introspection/interception vectors (freeze instead of throw)
|
|
109
|
+
{
|
|
110
|
+
prop: "Reflect",
|
|
111
|
+
target: globalThis,
|
|
112
|
+
violationType: "reflect",
|
|
113
|
+
strategy: "freeze",
|
|
114
|
+
reason: "Reflect provides introspection capabilities"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
prop: "Proxy",
|
|
118
|
+
target: globalThis,
|
|
119
|
+
violationType: "proxy",
|
|
120
|
+
strategy: "throw",
|
|
121
|
+
reason: "Proxy allows intercepting and modifying object behavior"
|
|
122
|
+
},
|
|
123
|
+
// WebAssembly allows arbitrary code execution
|
|
124
|
+
{
|
|
125
|
+
prop: "WebAssembly",
|
|
126
|
+
target: globalThis,
|
|
127
|
+
violationType: "webassembly",
|
|
128
|
+
strategy: "throw",
|
|
129
|
+
reason: "WebAssembly allows executing arbitrary compiled code"
|
|
130
|
+
},
|
|
131
|
+
// SharedArrayBuffer and Atomics can enable side-channel attacks
|
|
132
|
+
{
|
|
133
|
+
prop: "SharedArrayBuffer",
|
|
134
|
+
target: globalThis,
|
|
135
|
+
violationType: "shared_array_buffer",
|
|
136
|
+
strategy: "throw",
|
|
137
|
+
reason: "SharedArrayBuffer could enable side-channel communication or timing attacks"
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
prop: "Atomics",
|
|
141
|
+
target: globalThis,
|
|
142
|
+
violationType: "atomics",
|
|
143
|
+
strategy: "throw",
|
|
144
|
+
reason: "Atomics could enable side-channel communication or timing attacks"
|
|
145
|
+
}
|
|
146
|
+
// Note: Error.prepareStackTrace is handled specially in defense-in-depth-box.ts
|
|
147
|
+
// because we only want to block SETTING it, not reading (V8 reads it internally)
|
|
148
|
+
];
|
|
149
|
+
try {
|
|
150
|
+
const AsyncFunction = Object.getPrototypeOf(async () => {
|
|
151
|
+
}).constructor;
|
|
152
|
+
if (AsyncFunction && AsyncFunction !== Function) {
|
|
153
|
+
globals.push({
|
|
154
|
+
prop: "constructor",
|
|
155
|
+
target: Object.getPrototypeOf(async () => {
|
|
156
|
+
}),
|
|
157
|
+
violationType: "async_function_constructor",
|
|
158
|
+
strategy: "throw",
|
|
159
|
+
reason: "AsyncFunction constructor allows arbitrary async code execution"
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
} catch {
|
|
163
|
+
}
|
|
164
|
+
try {
|
|
165
|
+
const GeneratorFunction = Object.getPrototypeOf(
|
|
166
|
+
function* () {
|
|
167
|
+
}
|
|
168
|
+
).constructor;
|
|
169
|
+
if (GeneratorFunction && GeneratorFunction !== Function) {
|
|
170
|
+
globals.push({
|
|
171
|
+
prop: "constructor",
|
|
172
|
+
target: Object.getPrototypeOf(function* () {
|
|
173
|
+
}),
|
|
174
|
+
violationType: "generator_function_constructor",
|
|
175
|
+
strategy: "throw",
|
|
176
|
+
reason: "GeneratorFunction constructor allows arbitrary generator code execution"
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
} catch {
|
|
180
|
+
}
|
|
181
|
+
try {
|
|
182
|
+
const AsyncGeneratorFunction = Object.getPrototypeOf(
|
|
183
|
+
async function* () {
|
|
184
|
+
}
|
|
185
|
+
).constructor;
|
|
186
|
+
if (AsyncGeneratorFunction && AsyncGeneratorFunction !== Function && AsyncGeneratorFunction !== Object.getPrototypeOf(async () => {
|
|
187
|
+
}).constructor) {
|
|
188
|
+
globals.push({
|
|
189
|
+
prop: "constructor",
|
|
190
|
+
target: Object.getPrototypeOf(async function* () {
|
|
191
|
+
}),
|
|
192
|
+
violationType: "async_generator_function_constructor",
|
|
193
|
+
strategy: "throw",
|
|
194
|
+
reason: "AsyncGeneratorFunction constructor allows arbitrary async generator code execution"
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
} catch {
|
|
198
|
+
}
|
|
199
|
+
return globals.filter((g) => {
|
|
200
|
+
try {
|
|
201
|
+
return g.target[g.prop] !== void 0;
|
|
202
|
+
} catch {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// src/security/defense-in-depth-box.ts
|
|
209
|
+
var IS_BROWSER = typeof __BROWSER__ !== "undefined" && __BROWSER__;
|
|
210
|
+
var AsyncLocalStorageClass = null;
|
|
211
|
+
if (!IS_BROWSER) {
|
|
212
|
+
try {
|
|
213
|
+
const { createRequire: createRequire2 } = await import("node:module");
|
|
214
|
+
const require3 = createRequire2(import.meta.url);
|
|
215
|
+
const asyncHooks = require3("node:async_hooks");
|
|
216
|
+
AsyncLocalStorageClass = asyncHooks.AsyncLocalStorage;
|
|
217
|
+
} catch (e) {
|
|
218
|
+
console.debug(
|
|
219
|
+
"[DefenseInDepthBox] AsyncLocalStorage not available, defense-in-depth disabled:",
|
|
220
|
+
e instanceof Error ? e.message : e
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
var executionContext = !IS_BROWSER && AsyncLocalStorageClass ? new AsyncLocalStorageClass() : null;
|
|
225
|
+
|
|
226
|
+
// src/security/worker-defense-in-depth.ts
|
|
227
|
+
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";
|
|
228
|
+
var WorkerSecurityViolationError = class extends Error {
|
|
229
|
+
constructor(message, violation) {
|
|
230
|
+
super(message + DEFENSE_IN_DEPTH_NOTICE);
|
|
231
|
+
this.violation = violation;
|
|
232
|
+
this.name = "WorkerSecurityViolationError";
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
var MAX_STORED_VIOLATIONS = 1e3;
|
|
236
|
+
function generateExecutionId() {
|
|
237
|
+
if (typeof crypto !== "undefined" && crypto.randomUUID) {
|
|
238
|
+
return crypto.randomUUID();
|
|
239
|
+
}
|
|
240
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
241
|
+
const r = Math.random() * 16 | 0;
|
|
242
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
243
|
+
return v.toString(16);
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
var WorkerDefenseInDepth = class {
|
|
247
|
+
config;
|
|
248
|
+
isActivated = false;
|
|
249
|
+
originalDescriptors = [];
|
|
250
|
+
violations = [];
|
|
251
|
+
executionId;
|
|
252
|
+
/**
|
|
253
|
+
* Original Proxy constructor, captured before patching.
|
|
254
|
+
* This is captured at instance creation time to ensure we get the unpatched version.
|
|
255
|
+
*/
|
|
256
|
+
originalProxy;
|
|
257
|
+
/**
|
|
258
|
+
* Recursion guard to prevent infinite loops when proxy traps trigger
|
|
259
|
+
* code that accesses the same proxied object (e.g., process.env).
|
|
260
|
+
*/
|
|
261
|
+
inTrap = false;
|
|
262
|
+
/**
|
|
263
|
+
* Create and activate the worker defense layer.
|
|
264
|
+
*
|
|
265
|
+
* @param config - Configuration for the defense layer
|
|
266
|
+
*/
|
|
267
|
+
constructor(config) {
|
|
268
|
+
this.originalProxy = Proxy;
|
|
269
|
+
this.config = config;
|
|
270
|
+
this.executionId = generateExecutionId();
|
|
271
|
+
if (config.enabled !== false) {
|
|
272
|
+
this.activate();
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Get statistics about the defense layer.
|
|
277
|
+
*/
|
|
278
|
+
getStats() {
|
|
279
|
+
return {
|
|
280
|
+
violationsBlocked: this.violations.length,
|
|
281
|
+
violations: [...this.violations],
|
|
282
|
+
isActive: this.isActivated
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Clear stored violations. Useful for testing.
|
|
287
|
+
*/
|
|
288
|
+
clearViolations() {
|
|
289
|
+
this.violations = [];
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Get the execution ID for this worker.
|
|
293
|
+
*/
|
|
294
|
+
getExecutionId() {
|
|
295
|
+
return this.executionId;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Deactivate the defense layer and restore original globals.
|
|
299
|
+
* Typically only needed for testing.
|
|
300
|
+
*/
|
|
301
|
+
deactivate() {
|
|
302
|
+
if (!this.isActivated) {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
this.restorePatches();
|
|
306
|
+
this.isActivated = false;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Activate the defense layer by applying patches.
|
|
310
|
+
*/
|
|
311
|
+
activate() {
|
|
312
|
+
if (this.isActivated) {
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
this.applyPatches();
|
|
316
|
+
this.isActivated = true;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Get a human-readable path for a target object and property.
|
|
320
|
+
*/
|
|
321
|
+
getPathForTarget(target, prop) {
|
|
322
|
+
if (target === globalThis) {
|
|
323
|
+
return `globalThis.${prop}`;
|
|
324
|
+
}
|
|
325
|
+
if (typeof process !== "undefined" && target === process) {
|
|
326
|
+
return `process.${prop}`;
|
|
327
|
+
}
|
|
328
|
+
if (target === Error) {
|
|
329
|
+
return `Error.${prop}`;
|
|
330
|
+
}
|
|
331
|
+
if (target === Function.prototype) {
|
|
332
|
+
return `Function.prototype.${prop}`;
|
|
333
|
+
}
|
|
334
|
+
if (target === Object.prototype) {
|
|
335
|
+
return `Object.prototype.${prop}`;
|
|
336
|
+
}
|
|
337
|
+
return `<object>.${prop}`;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Record a violation and invoke the callback.
|
|
341
|
+
* In worker context, blocking always happens (no audit mode context check).
|
|
342
|
+
*/
|
|
343
|
+
recordViolation(type, path, message) {
|
|
344
|
+
const violation = {
|
|
345
|
+
timestamp: Date.now(),
|
|
346
|
+
type,
|
|
347
|
+
message,
|
|
348
|
+
path,
|
|
349
|
+
stack: new Error().stack,
|
|
350
|
+
executionId: this.executionId
|
|
351
|
+
};
|
|
352
|
+
if (this.violations.length < MAX_STORED_VIOLATIONS) {
|
|
353
|
+
this.violations.push(violation);
|
|
354
|
+
}
|
|
355
|
+
if (this.config.onViolation) {
|
|
356
|
+
try {
|
|
357
|
+
this.config.onViolation(violation);
|
|
358
|
+
} catch (e) {
|
|
359
|
+
console.debug(
|
|
360
|
+
"[WorkerDefenseInDepth] onViolation callback threw:",
|
|
361
|
+
e instanceof Error ? e.message : e
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
return violation;
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Create a blocking proxy for a function.
|
|
369
|
+
* In worker context, always blocks (no context check needed).
|
|
370
|
+
*/
|
|
371
|
+
// @banned-pattern-ignore: intentional use of Function type for security proxy
|
|
372
|
+
createBlockingProxy(original, path, violationType) {
|
|
373
|
+
const self = this;
|
|
374
|
+
const auditMode = this.config.auditMode;
|
|
375
|
+
return new this.originalProxy(original, {
|
|
376
|
+
apply(target, thisArg, args) {
|
|
377
|
+
const message = `${path} is blocked in worker context`;
|
|
378
|
+
const violation = self.recordViolation(violationType, path, message);
|
|
379
|
+
if (!auditMode) {
|
|
380
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
381
|
+
}
|
|
382
|
+
return Reflect.apply(target, thisArg, args);
|
|
383
|
+
},
|
|
384
|
+
construct(target, args, newTarget) {
|
|
385
|
+
const message = `${path} constructor is blocked in worker context`;
|
|
386
|
+
const violation = self.recordViolation(violationType, path, message);
|
|
387
|
+
if (!auditMode) {
|
|
388
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
389
|
+
}
|
|
390
|
+
return Reflect.construct(target, args, newTarget);
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Create a blocking proxy for an object (blocks all property access).
|
|
396
|
+
*/
|
|
397
|
+
createBlockingObjectProxy(original, path, violationType) {
|
|
398
|
+
const self = this;
|
|
399
|
+
const auditMode = this.config.auditMode;
|
|
400
|
+
return new this.originalProxy(original, {
|
|
401
|
+
get(target, prop, receiver) {
|
|
402
|
+
if (self.inTrap) {
|
|
403
|
+
return Reflect.get(target, prop, receiver);
|
|
404
|
+
}
|
|
405
|
+
self.inTrap = true;
|
|
406
|
+
try {
|
|
407
|
+
const fullPath = `${path}.${String(prop)}`;
|
|
408
|
+
const message = `${fullPath} is blocked in worker context`;
|
|
409
|
+
const violation = self.recordViolation(
|
|
410
|
+
violationType,
|
|
411
|
+
fullPath,
|
|
412
|
+
message
|
|
413
|
+
);
|
|
414
|
+
if (!auditMode) {
|
|
415
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
416
|
+
}
|
|
417
|
+
return Reflect.get(target, prop, receiver);
|
|
418
|
+
} finally {
|
|
419
|
+
self.inTrap = false;
|
|
420
|
+
}
|
|
421
|
+
},
|
|
422
|
+
set(target, prop, value, receiver) {
|
|
423
|
+
if (self.inTrap) {
|
|
424
|
+
return Reflect.set(target, prop, value, receiver);
|
|
425
|
+
}
|
|
426
|
+
self.inTrap = true;
|
|
427
|
+
try {
|
|
428
|
+
const fullPath = `${path}.${String(prop)}`;
|
|
429
|
+
const message = `${fullPath} modification is blocked in worker context`;
|
|
430
|
+
const violation = self.recordViolation(
|
|
431
|
+
violationType,
|
|
432
|
+
fullPath,
|
|
433
|
+
message
|
|
434
|
+
);
|
|
435
|
+
if (!auditMode) {
|
|
436
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
437
|
+
}
|
|
438
|
+
return Reflect.set(target, prop, value, receiver);
|
|
439
|
+
} finally {
|
|
440
|
+
self.inTrap = false;
|
|
441
|
+
}
|
|
442
|
+
},
|
|
443
|
+
ownKeys(target) {
|
|
444
|
+
if (self.inTrap) {
|
|
445
|
+
return Reflect.ownKeys(target);
|
|
446
|
+
}
|
|
447
|
+
self.inTrap = true;
|
|
448
|
+
try {
|
|
449
|
+
const message = `${path} enumeration is blocked in worker context`;
|
|
450
|
+
const violation = self.recordViolation(violationType, path, message);
|
|
451
|
+
if (!auditMode) {
|
|
452
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
453
|
+
}
|
|
454
|
+
return Reflect.ownKeys(target);
|
|
455
|
+
} finally {
|
|
456
|
+
self.inTrap = false;
|
|
457
|
+
}
|
|
458
|
+
},
|
|
459
|
+
getOwnPropertyDescriptor(target, prop) {
|
|
460
|
+
if (self.inTrap) {
|
|
461
|
+
return Reflect.getOwnPropertyDescriptor(target, prop);
|
|
462
|
+
}
|
|
463
|
+
self.inTrap = true;
|
|
464
|
+
try {
|
|
465
|
+
const fullPath = `${path}.${String(prop)}`;
|
|
466
|
+
const message = `${fullPath} descriptor access is blocked in worker context`;
|
|
467
|
+
const violation = self.recordViolation(
|
|
468
|
+
violationType,
|
|
469
|
+
fullPath,
|
|
470
|
+
message
|
|
471
|
+
);
|
|
472
|
+
if (!auditMode) {
|
|
473
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
474
|
+
}
|
|
475
|
+
return Reflect.getOwnPropertyDescriptor(target, prop);
|
|
476
|
+
} finally {
|
|
477
|
+
self.inTrap = false;
|
|
478
|
+
}
|
|
479
|
+
},
|
|
480
|
+
has(target, prop) {
|
|
481
|
+
if (self.inTrap) {
|
|
482
|
+
return Reflect.has(target, prop);
|
|
483
|
+
}
|
|
484
|
+
self.inTrap = true;
|
|
485
|
+
try {
|
|
486
|
+
const fullPath = `${path}.${String(prop)}`;
|
|
487
|
+
const message = `${fullPath} existence check is blocked in worker context`;
|
|
488
|
+
const violation = self.recordViolation(
|
|
489
|
+
violationType,
|
|
490
|
+
fullPath,
|
|
491
|
+
message
|
|
492
|
+
);
|
|
493
|
+
if (!auditMode) {
|
|
494
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
495
|
+
}
|
|
496
|
+
return Reflect.has(target, prop);
|
|
497
|
+
} finally {
|
|
498
|
+
self.inTrap = false;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Apply security patches to dangerous globals.
|
|
505
|
+
*/
|
|
506
|
+
applyPatches() {
|
|
507
|
+
const blockedGlobals = getBlockedGlobals();
|
|
508
|
+
const excludeTypes = new Set(this.config.excludeViolationTypes ?? []);
|
|
509
|
+
for (const blocked of blockedGlobals) {
|
|
510
|
+
if (excludeTypes.has(blocked.violationType)) {
|
|
511
|
+
continue;
|
|
512
|
+
}
|
|
513
|
+
this.applyPatch(blocked);
|
|
514
|
+
}
|
|
515
|
+
if (!excludeTypes.has("function_constructor")) {
|
|
516
|
+
this.protectConstructorChain(excludeTypes);
|
|
517
|
+
}
|
|
518
|
+
if (!excludeTypes.has("error_prepare_stack_trace")) {
|
|
519
|
+
this.protectErrorPrepareStackTrace();
|
|
520
|
+
}
|
|
521
|
+
if (!excludeTypes.has("module_load")) {
|
|
522
|
+
this.protectModuleLoad();
|
|
523
|
+
}
|
|
524
|
+
if (!excludeTypes.has("process_main_module")) {
|
|
525
|
+
this.protectProcessMainModule();
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Protect against .constructor.constructor escape vector.
|
|
530
|
+
* @param excludeTypes - Set of violation types to skip
|
|
531
|
+
*/
|
|
532
|
+
protectConstructorChain(excludeTypes) {
|
|
533
|
+
let AsyncFunction = null;
|
|
534
|
+
let GeneratorFunction = null;
|
|
535
|
+
let AsyncGeneratorFunction = null;
|
|
536
|
+
try {
|
|
537
|
+
AsyncFunction = Object.getPrototypeOf(async () => {
|
|
538
|
+
}).constructor;
|
|
539
|
+
} catch {
|
|
540
|
+
}
|
|
541
|
+
try {
|
|
542
|
+
GeneratorFunction = Object.getPrototypeOf(function* () {
|
|
543
|
+
}).constructor;
|
|
544
|
+
} catch {
|
|
545
|
+
}
|
|
546
|
+
try {
|
|
547
|
+
AsyncGeneratorFunction = Object.getPrototypeOf(
|
|
548
|
+
async function* () {
|
|
549
|
+
}
|
|
550
|
+
).constructor;
|
|
551
|
+
} catch {
|
|
552
|
+
}
|
|
553
|
+
this.patchPrototypeConstructor(
|
|
554
|
+
Function.prototype,
|
|
555
|
+
"Function.prototype.constructor",
|
|
556
|
+
"function_constructor"
|
|
557
|
+
);
|
|
558
|
+
if (!excludeTypes.has("async_function_constructor") && AsyncFunction && AsyncFunction !== Function) {
|
|
559
|
+
this.patchPrototypeConstructor(
|
|
560
|
+
AsyncFunction.prototype,
|
|
561
|
+
"AsyncFunction.prototype.constructor",
|
|
562
|
+
"async_function_constructor"
|
|
563
|
+
);
|
|
564
|
+
}
|
|
565
|
+
if (!excludeTypes.has("generator_function_constructor") && GeneratorFunction && GeneratorFunction !== Function) {
|
|
566
|
+
this.patchPrototypeConstructor(
|
|
567
|
+
GeneratorFunction.prototype,
|
|
568
|
+
"GeneratorFunction.prototype.constructor",
|
|
569
|
+
"generator_function_constructor"
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
if (!excludeTypes.has("async_generator_function_constructor") && AsyncGeneratorFunction && AsyncGeneratorFunction !== Function && AsyncGeneratorFunction !== AsyncFunction) {
|
|
573
|
+
this.patchPrototypeConstructor(
|
|
574
|
+
AsyncGeneratorFunction.prototype,
|
|
575
|
+
"AsyncGeneratorFunction.prototype.constructor",
|
|
576
|
+
"async_generator_function_constructor"
|
|
577
|
+
);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Protect Error.prepareStackTrace from being set.
|
|
582
|
+
*/
|
|
583
|
+
protectErrorPrepareStackTrace() {
|
|
584
|
+
const self = this;
|
|
585
|
+
const auditMode = this.config.auditMode;
|
|
586
|
+
try {
|
|
587
|
+
const originalDescriptor = Object.getOwnPropertyDescriptor(
|
|
588
|
+
Error,
|
|
589
|
+
"prepareStackTrace"
|
|
590
|
+
);
|
|
591
|
+
this.originalDescriptors.push({
|
|
592
|
+
target: Error,
|
|
593
|
+
prop: "prepareStackTrace",
|
|
594
|
+
descriptor: originalDescriptor
|
|
595
|
+
});
|
|
596
|
+
let currentValue = originalDescriptor?.value;
|
|
597
|
+
Object.defineProperty(Error, "prepareStackTrace", {
|
|
598
|
+
get() {
|
|
599
|
+
return currentValue;
|
|
600
|
+
},
|
|
601
|
+
set(value) {
|
|
602
|
+
const message = "Error.prepareStackTrace modification is blocked in worker context";
|
|
603
|
+
const violation = self.recordViolation(
|
|
604
|
+
"error_prepare_stack_trace",
|
|
605
|
+
"Error.prepareStackTrace",
|
|
606
|
+
message
|
|
607
|
+
);
|
|
608
|
+
if (!auditMode) {
|
|
609
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
610
|
+
}
|
|
611
|
+
currentValue = value;
|
|
612
|
+
},
|
|
613
|
+
configurable: true
|
|
614
|
+
});
|
|
615
|
+
} catch {
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* Patch a prototype's constructor property.
|
|
620
|
+
*
|
|
621
|
+
* Returns a proxy that allows reading properties (like .name) but blocks
|
|
622
|
+
* calling the constructor as a function (which would allow code execution).
|
|
623
|
+
*/
|
|
624
|
+
patchPrototypeConstructor(prototype, path, violationType) {
|
|
625
|
+
const self = this;
|
|
626
|
+
const auditMode = this.config.auditMode;
|
|
627
|
+
try {
|
|
628
|
+
const originalDescriptor = Object.getOwnPropertyDescriptor(
|
|
629
|
+
prototype,
|
|
630
|
+
"constructor"
|
|
631
|
+
);
|
|
632
|
+
this.originalDescriptors.push({
|
|
633
|
+
target: prototype,
|
|
634
|
+
prop: "constructor",
|
|
635
|
+
descriptor: originalDescriptor
|
|
636
|
+
});
|
|
637
|
+
const originalValue = originalDescriptor?.value;
|
|
638
|
+
const constructorProxy = originalValue && typeof originalValue === "function" ? new this.originalProxy(originalValue, {
|
|
639
|
+
apply(_target, _thisArg, _args) {
|
|
640
|
+
const message = `${path} invocation is blocked in worker context`;
|
|
641
|
+
const violation = self.recordViolation(
|
|
642
|
+
violationType,
|
|
643
|
+
path,
|
|
644
|
+
message
|
|
645
|
+
);
|
|
646
|
+
if (!auditMode) {
|
|
647
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
648
|
+
}
|
|
649
|
+
return void 0;
|
|
650
|
+
},
|
|
651
|
+
construct(_target, _args, _newTarget) {
|
|
652
|
+
const message = `${path} construction is blocked in worker context`;
|
|
653
|
+
const violation = self.recordViolation(
|
|
654
|
+
violationType,
|
|
655
|
+
path,
|
|
656
|
+
message
|
|
657
|
+
);
|
|
658
|
+
if (!auditMode) {
|
|
659
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
660
|
+
}
|
|
661
|
+
return {};
|
|
662
|
+
},
|
|
663
|
+
// Allow all property access (like .name, .prototype, etc.)
|
|
664
|
+
get(target, prop, receiver) {
|
|
665
|
+
return Reflect.get(target, prop, receiver);
|
|
666
|
+
},
|
|
667
|
+
getPrototypeOf(target) {
|
|
668
|
+
return Reflect.getPrototypeOf(target);
|
|
669
|
+
},
|
|
670
|
+
has(target, prop) {
|
|
671
|
+
return Reflect.has(target, prop);
|
|
672
|
+
},
|
|
673
|
+
ownKeys(target) {
|
|
674
|
+
return Reflect.ownKeys(target);
|
|
675
|
+
},
|
|
676
|
+
getOwnPropertyDescriptor(target, prop) {
|
|
677
|
+
return Reflect.getOwnPropertyDescriptor(target, prop);
|
|
678
|
+
}
|
|
679
|
+
}) : originalValue;
|
|
680
|
+
Object.defineProperty(prototype, "constructor", {
|
|
681
|
+
get() {
|
|
682
|
+
return constructorProxy;
|
|
683
|
+
},
|
|
684
|
+
set(value) {
|
|
685
|
+
const message = `${path} modification is blocked in worker context`;
|
|
686
|
+
const violation = self.recordViolation(violationType, path, message);
|
|
687
|
+
if (!auditMode) {
|
|
688
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
689
|
+
}
|
|
690
|
+
Object.defineProperty(this, "constructor", {
|
|
691
|
+
value,
|
|
692
|
+
writable: true,
|
|
693
|
+
configurable: true
|
|
694
|
+
});
|
|
695
|
+
},
|
|
696
|
+
configurable: true
|
|
697
|
+
});
|
|
698
|
+
} catch {
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* Protect process.mainModule from being accessed or set.
|
|
703
|
+
*
|
|
704
|
+
* The attack vector is:
|
|
705
|
+
* ```
|
|
706
|
+
* process.mainModule.require('child_process').execSync('whoami')
|
|
707
|
+
* process.mainModule.constructor._load('vm')
|
|
708
|
+
* ```
|
|
709
|
+
*
|
|
710
|
+
* process.mainModule may be undefined in ESM contexts but could exist in
|
|
711
|
+
* CommonJS workers. We block both reading and setting.
|
|
712
|
+
*/
|
|
713
|
+
protectProcessMainModule() {
|
|
714
|
+
if (typeof process === "undefined") return;
|
|
715
|
+
const self = this;
|
|
716
|
+
const auditMode = this.config.auditMode;
|
|
717
|
+
try {
|
|
718
|
+
const originalDescriptor = Object.getOwnPropertyDescriptor(
|
|
719
|
+
process,
|
|
720
|
+
"mainModule"
|
|
721
|
+
);
|
|
722
|
+
this.originalDescriptors.push({
|
|
723
|
+
target: process,
|
|
724
|
+
prop: "mainModule",
|
|
725
|
+
descriptor: originalDescriptor
|
|
726
|
+
});
|
|
727
|
+
const currentValue = originalDescriptor?.value;
|
|
728
|
+
if (currentValue !== void 0) {
|
|
729
|
+
Object.defineProperty(process, "mainModule", {
|
|
730
|
+
get() {
|
|
731
|
+
const message = "process.mainModule access is blocked in worker context";
|
|
732
|
+
const violation = self.recordViolation(
|
|
733
|
+
"process_main_module",
|
|
734
|
+
"process.mainModule",
|
|
735
|
+
message
|
|
736
|
+
);
|
|
737
|
+
if (!auditMode) {
|
|
738
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
739
|
+
}
|
|
740
|
+
return currentValue;
|
|
741
|
+
},
|
|
742
|
+
set(value) {
|
|
743
|
+
const message = "process.mainModule modification is blocked in worker context";
|
|
744
|
+
const violation = self.recordViolation(
|
|
745
|
+
"process_main_module",
|
|
746
|
+
"process.mainModule",
|
|
747
|
+
message
|
|
748
|
+
);
|
|
749
|
+
if (!auditMode) {
|
|
750
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
751
|
+
}
|
|
752
|
+
Object.defineProperty(process, "mainModule", {
|
|
753
|
+
value,
|
|
754
|
+
writable: true,
|
|
755
|
+
configurable: true
|
|
756
|
+
});
|
|
757
|
+
},
|
|
758
|
+
configurable: true
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
} catch {
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* Protect Module._load from being called.
|
|
766
|
+
*
|
|
767
|
+
* The attack vector is:
|
|
768
|
+
* ```
|
|
769
|
+
* module.constructor._load('child_process')
|
|
770
|
+
* require.main.constructor._load('vm')
|
|
771
|
+
* ```
|
|
772
|
+
*
|
|
773
|
+
* We access the Module class and replace _load with a blocking proxy.
|
|
774
|
+
*/
|
|
775
|
+
protectModuleLoad() {
|
|
776
|
+
const self = this;
|
|
777
|
+
const auditMode = this.config.auditMode;
|
|
778
|
+
try {
|
|
779
|
+
let ModuleClass = null;
|
|
780
|
+
if (typeof process !== "undefined") {
|
|
781
|
+
const mainModule = process.mainModule;
|
|
782
|
+
if (mainModule && typeof mainModule === "object") {
|
|
783
|
+
ModuleClass = mainModule.constructor;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
if (!ModuleClass && typeof __require !== "undefined" && typeof __require.main !== "undefined") {
|
|
787
|
+
ModuleClass = __require.main.constructor;
|
|
788
|
+
}
|
|
789
|
+
if (!ModuleClass || typeof ModuleClass._load !== "function") {
|
|
790
|
+
return;
|
|
791
|
+
}
|
|
792
|
+
const original = ModuleClass._load;
|
|
793
|
+
const descriptor = Object.getOwnPropertyDescriptor(ModuleClass, "_load");
|
|
794
|
+
this.originalDescriptors.push({
|
|
795
|
+
target: ModuleClass,
|
|
796
|
+
prop: "_load",
|
|
797
|
+
descriptor
|
|
798
|
+
});
|
|
799
|
+
const path = "Module._load";
|
|
800
|
+
const proxy = new this.originalProxy(original, {
|
|
801
|
+
apply(_target, _thisArg, _args) {
|
|
802
|
+
const message = `${path} is blocked in worker context`;
|
|
803
|
+
const violation = self.recordViolation("module_load", path, message);
|
|
804
|
+
if (!auditMode) {
|
|
805
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
806
|
+
}
|
|
807
|
+
return Reflect.apply(_target, _thisArg, _args);
|
|
808
|
+
}
|
|
809
|
+
});
|
|
810
|
+
Object.defineProperty(ModuleClass, "_load", {
|
|
811
|
+
value: proxy,
|
|
812
|
+
writable: true,
|
|
813
|
+
configurable: true
|
|
814
|
+
});
|
|
815
|
+
} catch {
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
/**
|
|
819
|
+
* Apply a single patch to a blocked global.
|
|
820
|
+
*/
|
|
821
|
+
applyPatch(blocked) {
|
|
822
|
+
const { target, prop, violationType, strategy } = blocked;
|
|
823
|
+
try {
|
|
824
|
+
const original = target[prop];
|
|
825
|
+
if (original === void 0) {
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
const descriptor = Object.getOwnPropertyDescriptor(target, prop);
|
|
829
|
+
this.originalDescriptors.push({ target, prop, descriptor });
|
|
830
|
+
if (strategy === "freeze") {
|
|
831
|
+
if (typeof original === "object" && original !== null) {
|
|
832
|
+
Object.freeze(original);
|
|
833
|
+
}
|
|
834
|
+
} else {
|
|
835
|
+
const path = this.getPathForTarget(target, prop);
|
|
836
|
+
const proxy = typeof original === "function" ? this.createBlockingProxy(
|
|
837
|
+
original,
|
|
838
|
+
path,
|
|
839
|
+
violationType
|
|
840
|
+
) : this.createBlockingObjectProxy(
|
|
841
|
+
original,
|
|
842
|
+
path,
|
|
843
|
+
violationType
|
|
844
|
+
);
|
|
845
|
+
Object.defineProperty(target, prop, {
|
|
846
|
+
value: proxy,
|
|
847
|
+
writable: true,
|
|
848
|
+
configurable: true
|
|
849
|
+
});
|
|
850
|
+
}
|
|
851
|
+
} catch {
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
/**
|
|
855
|
+
* Restore all original values.
|
|
856
|
+
*/
|
|
857
|
+
restorePatches() {
|
|
858
|
+
for (let i = this.originalDescriptors.length - 1; i >= 0; i--) {
|
|
859
|
+
const { target, prop, descriptor } = this.originalDescriptors[i];
|
|
860
|
+
try {
|
|
861
|
+
if (descriptor) {
|
|
862
|
+
Object.defineProperty(target, prop, descriptor);
|
|
863
|
+
} else {
|
|
864
|
+
delete target[prop];
|
|
865
|
+
}
|
|
866
|
+
} catch {
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
this.originalDescriptors = [];
|
|
870
|
+
}
|
|
871
|
+
};
|
|
872
|
+
|
|
873
|
+
// src/commands/python3/protocol.ts
|
|
874
|
+
var OpCode = {
|
|
875
|
+
NOOP: 0,
|
|
876
|
+
READ_FILE: 1,
|
|
877
|
+
WRITE_FILE: 2,
|
|
878
|
+
STAT: 3,
|
|
879
|
+
READDIR: 4,
|
|
880
|
+
MKDIR: 5,
|
|
881
|
+
RM: 6,
|
|
882
|
+
EXISTS: 7,
|
|
883
|
+
APPEND_FILE: 8,
|
|
884
|
+
SYMLINK: 9,
|
|
885
|
+
READLINK: 10,
|
|
886
|
+
LSTAT: 11,
|
|
887
|
+
CHMOD: 12,
|
|
888
|
+
REALPATH: 13,
|
|
889
|
+
// Special operations for Python I/O
|
|
890
|
+
WRITE_STDOUT: 100,
|
|
891
|
+
WRITE_STDERR: 101,
|
|
892
|
+
EXIT: 102,
|
|
893
|
+
// HTTP operations
|
|
894
|
+
HTTP_REQUEST: 200
|
|
895
|
+
};
|
|
896
|
+
var Status = {
|
|
897
|
+
PENDING: 0,
|
|
898
|
+
READY: 1,
|
|
899
|
+
SUCCESS: 2,
|
|
900
|
+
ERROR: 3
|
|
901
|
+
};
|
|
902
|
+
var ErrorCode = {
|
|
903
|
+
NONE: 0,
|
|
904
|
+
NOT_FOUND: 1,
|
|
905
|
+
IS_DIRECTORY: 2,
|
|
906
|
+
NOT_DIRECTORY: 3,
|
|
907
|
+
EXISTS: 4,
|
|
908
|
+
PERMISSION_DENIED: 5,
|
|
909
|
+
INVALID_PATH: 6,
|
|
910
|
+
IO_ERROR: 7,
|
|
911
|
+
TIMEOUT: 8,
|
|
912
|
+
NETWORK_ERROR: 9,
|
|
913
|
+
NETWORK_NOT_CONFIGURED: 10
|
|
914
|
+
};
|
|
915
|
+
var Offset = {
|
|
916
|
+
OP_CODE: 0,
|
|
917
|
+
STATUS: 4,
|
|
918
|
+
PATH_LENGTH: 8,
|
|
919
|
+
DATA_LENGTH: 12,
|
|
920
|
+
RESULT_LENGTH: 16,
|
|
921
|
+
ERROR_CODE: 20,
|
|
922
|
+
FLAGS: 24,
|
|
923
|
+
MODE: 28,
|
|
924
|
+
PATH_BUFFER: 32,
|
|
925
|
+
DATA_BUFFER: 4128
|
|
926
|
+
// 32 + 4096
|
|
927
|
+
};
|
|
928
|
+
var Size = {
|
|
929
|
+
CONTROL_REGION: 32,
|
|
930
|
+
PATH_BUFFER: 4096,
|
|
931
|
+
DATA_BUFFER: 1048576,
|
|
932
|
+
// 1MB (reduced from 16MB for faster tests)
|
|
933
|
+
TOTAL: 1052704
|
|
934
|
+
// 32 + 4096 + 1MB
|
|
935
|
+
};
|
|
936
|
+
var Flags = {
|
|
937
|
+
NONE: 0,
|
|
938
|
+
RECURSIVE: 1,
|
|
939
|
+
FORCE: 2,
|
|
940
|
+
MKDIR_RECURSIVE: 1
|
|
941
|
+
};
|
|
942
|
+
var StatLayout = {
|
|
943
|
+
IS_FILE: 0,
|
|
944
|
+
IS_DIRECTORY: 1,
|
|
945
|
+
IS_SYMLINK: 2,
|
|
946
|
+
MODE: 4,
|
|
947
|
+
SIZE: 8,
|
|
948
|
+
MTIME: 16,
|
|
949
|
+
TOTAL: 24
|
|
950
|
+
};
|
|
951
|
+
var ProtocolBuffer = class {
|
|
952
|
+
int32View;
|
|
953
|
+
uint8View;
|
|
954
|
+
dataView;
|
|
955
|
+
constructor(buffer) {
|
|
956
|
+
this.int32View = new Int32Array(buffer);
|
|
957
|
+
this.uint8View = new Uint8Array(buffer);
|
|
958
|
+
this.dataView = new DataView(buffer);
|
|
959
|
+
}
|
|
960
|
+
getOpCode() {
|
|
961
|
+
return Atomics.load(this.int32View, Offset.OP_CODE / 4);
|
|
962
|
+
}
|
|
963
|
+
setOpCode(code) {
|
|
964
|
+
Atomics.store(this.int32View, Offset.OP_CODE / 4, code);
|
|
965
|
+
}
|
|
966
|
+
getStatus() {
|
|
967
|
+
return Atomics.load(this.int32View, Offset.STATUS / 4);
|
|
968
|
+
}
|
|
969
|
+
setStatus(status) {
|
|
970
|
+
Atomics.store(this.int32View, Offset.STATUS / 4, status);
|
|
971
|
+
}
|
|
972
|
+
getPathLength() {
|
|
973
|
+
return Atomics.load(this.int32View, Offset.PATH_LENGTH / 4);
|
|
974
|
+
}
|
|
975
|
+
setPathLength(length) {
|
|
976
|
+
Atomics.store(this.int32View, Offset.PATH_LENGTH / 4, length);
|
|
977
|
+
}
|
|
978
|
+
getDataLength() {
|
|
979
|
+
return Atomics.load(this.int32View, Offset.DATA_LENGTH / 4);
|
|
980
|
+
}
|
|
981
|
+
setDataLength(length) {
|
|
982
|
+
Atomics.store(this.int32View, Offset.DATA_LENGTH / 4, length);
|
|
983
|
+
}
|
|
984
|
+
getResultLength() {
|
|
985
|
+
return Atomics.load(this.int32View, Offset.RESULT_LENGTH / 4);
|
|
986
|
+
}
|
|
987
|
+
setResultLength(length) {
|
|
988
|
+
Atomics.store(this.int32View, Offset.RESULT_LENGTH / 4, length);
|
|
989
|
+
}
|
|
990
|
+
getErrorCode() {
|
|
991
|
+
return Atomics.load(this.int32View, Offset.ERROR_CODE / 4);
|
|
992
|
+
}
|
|
993
|
+
setErrorCode(code) {
|
|
994
|
+
Atomics.store(this.int32View, Offset.ERROR_CODE / 4, code);
|
|
995
|
+
}
|
|
996
|
+
getFlags() {
|
|
997
|
+
return Atomics.load(this.int32View, Offset.FLAGS / 4);
|
|
998
|
+
}
|
|
999
|
+
setFlags(flags) {
|
|
1000
|
+
Atomics.store(this.int32View, Offset.FLAGS / 4, flags);
|
|
1001
|
+
}
|
|
1002
|
+
getMode() {
|
|
1003
|
+
return Atomics.load(this.int32View, Offset.MODE / 4);
|
|
1004
|
+
}
|
|
1005
|
+
setMode(mode) {
|
|
1006
|
+
Atomics.store(this.int32View, Offset.MODE / 4, mode);
|
|
1007
|
+
}
|
|
1008
|
+
getPath() {
|
|
1009
|
+
const length = this.getPathLength();
|
|
1010
|
+
const bytes = this.uint8View.slice(
|
|
1011
|
+
Offset.PATH_BUFFER,
|
|
1012
|
+
Offset.PATH_BUFFER + length
|
|
1013
|
+
);
|
|
1014
|
+
return new TextDecoder().decode(bytes);
|
|
1015
|
+
}
|
|
1016
|
+
setPath(path) {
|
|
1017
|
+
const encoded = new TextEncoder().encode(path);
|
|
1018
|
+
if (encoded.length > Size.PATH_BUFFER) {
|
|
1019
|
+
throw new Error(`Path too long: ${encoded.length} > ${Size.PATH_BUFFER}`);
|
|
1020
|
+
}
|
|
1021
|
+
this.uint8View.set(encoded, Offset.PATH_BUFFER);
|
|
1022
|
+
this.setPathLength(encoded.length);
|
|
1023
|
+
}
|
|
1024
|
+
getData() {
|
|
1025
|
+
const length = this.getDataLength();
|
|
1026
|
+
return this.uint8View.slice(
|
|
1027
|
+
Offset.DATA_BUFFER,
|
|
1028
|
+
Offset.DATA_BUFFER + length
|
|
1029
|
+
);
|
|
1030
|
+
}
|
|
1031
|
+
setData(data) {
|
|
1032
|
+
if (data.length > Size.DATA_BUFFER) {
|
|
1033
|
+
throw new Error(`Data too large: ${data.length} > ${Size.DATA_BUFFER}`);
|
|
1034
|
+
}
|
|
1035
|
+
this.uint8View.set(data, Offset.DATA_BUFFER);
|
|
1036
|
+
this.setDataLength(data.length);
|
|
1037
|
+
}
|
|
1038
|
+
getDataAsString() {
|
|
1039
|
+
const data = this.getData();
|
|
1040
|
+
return new TextDecoder().decode(data);
|
|
1041
|
+
}
|
|
1042
|
+
setDataFromString(str) {
|
|
1043
|
+
const encoded = new TextEncoder().encode(str);
|
|
1044
|
+
this.setData(encoded);
|
|
1045
|
+
}
|
|
1046
|
+
getResult() {
|
|
1047
|
+
const length = this.getResultLength();
|
|
1048
|
+
return this.uint8View.slice(
|
|
1049
|
+
Offset.DATA_BUFFER,
|
|
1050
|
+
Offset.DATA_BUFFER + length
|
|
1051
|
+
);
|
|
1052
|
+
}
|
|
1053
|
+
setResult(data) {
|
|
1054
|
+
if (data.length > Size.DATA_BUFFER) {
|
|
1055
|
+
throw new Error(`Result too large: ${data.length} > ${Size.DATA_BUFFER}`);
|
|
1056
|
+
}
|
|
1057
|
+
this.uint8View.set(data, Offset.DATA_BUFFER);
|
|
1058
|
+
this.setResultLength(data.length);
|
|
1059
|
+
}
|
|
1060
|
+
getResultAsString() {
|
|
1061
|
+
const result = this.getResult();
|
|
1062
|
+
return new TextDecoder().decode(result);
|
|
1063
|
+
}
|
|
1064
|
+
setResultFromString(str) {
|
|
1065
|
+
const encoded = new TextEncoder().encode(str);
|
|
1066
|
+
this.setResult(encoded);
|
|
1067
|
+
}
|
|
1068
|
+
encodeStat(stat) {
|
|
1069
|
+
this.uint8View[Offset.DATA_BUFFER + StatLayout.IS_FILE] = stat.isFile ? 1 : 0;
|
|
1070
|
+
this.uint8View[Offset.DATA_BUFFER + StatLayout.IS_DIRECTORY] = stat.isDirectory ? 1 : 0;
|
|
1071
|
+
this.uint8View[Offset.DATA_BUFFER + StatLayout.IS_SYMLINK] = stat.isSymbolicLink ? 1 : 0;
|
|
1072
|
+
this.dataView.setInt32(
|
|
1073
|
+
Offset.DATA_BUFFER + StatLayout.MODE,
|
|
1074
|
+
stat.mode,
|
|
1075
|
+
true
|
|
1076
|
+
);
|
|
1077
|
+
const size = Math.min(stat.size, Number.MAX_SAFE_INTEGER);
|
|
1078
|
+
this.dataView.setFloat64(Offset.DATA_BUFFER + StatLayout.SIZE, size, true);
|
|
1079
|
+
this.dataView.setFloat64(
|
|
1080
|
+
Offset.DATA_BUFFER + StatLayout.MTIME,
|
|
1081
|
+
stat.mtime.getTime(),
|
|
1082
|
+
true
|
|
1083
|
+
);
|
|
1084
|
+
this.setResultLength(StatLayout.TOTAL);
|
|
1085
|
+
}
|
|
1086
|
+
decodeStat() {
|
|
1087
|
+
return {
|
|
1088
|
+
isFile: this.uint8View[Offset.DATA_BUFFER + StatLayout.IS_FILE] === 1,
|
|
1089
|
+
isDirectory: this.uint8View[Offset.DATA_BUFFER + StatLayout.IS_DIRECTORY] === 1,
|
|
1090
|
+
isSymbolicLink: this.uint8View[Offset.DATA_BUFFER + StatLayout.IS_SYMLINK] === 1,
|
|
1091
|
+
mode: this.dataView.getInt32(Offset.DATA_BUFFER + StatLayout.MODE, true),
|
|
1092
|
+
size: this.dataView.getFloat64(
|
|
1093
|
+
Offset.DATA_BUFFER + StatLayout.SIZE,
|
|
1094
|
+
true
|
|
1095
|
+
),
|
|
1096
|
+
mtime: new Date(
|
|
1097
|
+
this.dataView.getFloat64(Offset.DATA_BUFFER + StatLayout.MTIME, true)
|
|
1098
|
+
)
|
|
1099
|
+
};
|
|
1100
|
+
}
|
|
1101
|
+
waitForReady(timeout) {
|
|
1102
|
+
return Atomics.wait(
|
|
1103
|
+
this.int32View,
|
|
1104
|
+
Offset.STATUS / 4,
|
|
1105
|
+
Status.PENDING,
|
|
1106
|
+
timeout
|
|
1107
|
+
);
|
|
1108
|
+
}
|
|
1109
|
+
waitForReadyAsync(timeout) {
|
|
1110
|
+
return Atomics.waitAsync(
|
|
1111
|
+
this.int32View,
|
|
1112
|
+
Offset.STATUS / 4,
|
|
1113
|
+
Status.PENDING,
|
|
1114
|
+
timeout
|
|
1115
|
+
);
|
|
1116
|
+
}
|
|
1117
|
+
/**
|
|
1118
|
+
* Wait for status to become READY.
|
|
1119
|
+
* Returns immediately if status is already READY, or waits until it changes.
|
|
1120
|
+
*/
|
|
1121
|
+
async waitUntilReady(timeout) {
|
|
1122
|
+
const startTime = Date.now();
|
|
1123
|
+
while (true) {
|
|
1124
|
+
const status = this.getStatus();
|
|
1125
|
+
if (status === Status.READY) {
|
|
1126
|
+
return true;
|
|
1127
|
+
}
|
|
1128
|
+
const elapsed = Date.now() - startTime;
|
|
1129
|
+
if (elapsed >= timeout) {
|
|
1130
|
+
return false;
|
|
1131
|
+
}
|
|
1132
|
+
const remainingMs = timeout - elapsed;
|
|
1133
|
+
const result = Atomics.waitAsync(
|
|
1134
|
+
this.int32View,
|
|
1135
|
+
Offset.STATUS / 4,
|
|
1136
|
+
status,
|
|
1137
|
+
remainingMs
|
|
1138
|
+
);
|
|
1139
|
+
if (result.async) {
|
|
1140
|
+
const waitResult = await result.value;
|
|
1141
|
+
if (waitResult === "timed-out") {
|
|
1142
|
+
return false;
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
waitForResult(timeout) {
|
|
1148
|
+
return Atomics.wait(
|
|
1149
|
+
this.int32View,
|
|
1150
|
+
Offset.STATUS / 4,
|
|
1151
|
+
Status.READY,
|
|
1152
|
+
timeout
|
|
1153
|
+
);
|
|
1154
|
+
}
|
|
1155
|
+
notify() {
|
|
1156
|
+
return Atomics.notify(this.int32View, Offset.STATUS / 4);
|
|
1157
|
+
}
|
|
1158
|
+
reset() {
|
|
1159
|
+
this.setOpCode(OpCode.NOOP);
|
|
1160
|
+
this.setStatus(Status.PENDING);
|
|
1161
|
+
this.setPathLength(0);
|
|
1162
|
+
this.setDataLength(0);
|
|
1163
|
+
this.setResultLength(0);
|
|
1164
|
+
this.setErrorCode(ErrorCode.NONE);
|
|
1165
|
+
this.setFlags(Flags.NONE);
|
|
1166
|
+
this.setMode(0);
|
|
1167
|
+
}
|
|
1168
|
+
};
|
|
1169
|
+
|
|
1170
|
+
// src/commands/python3/sync-fs-backend.ts
|
|
1171
|
+
var SyncFsBackend = class {
|
|
1172
|
+
protocol;
|
|
1173
|
+
constructor(sharedBuffer) {
|
|
1174
|
+
this.protocol = new ProtocolBuffer(sharedBuffer);
|
|
1175
|
+
}
|
|
1176
|
+
execSync(opCode, path, data, flags = 0, mode = 0) {
|
|
1177
|
+
this.protocol.reset();
|
|
1178
|
+
this.protocol.setOpCode(opCode);
|
|
1179
|
+
this.protocol.setPath(path);
|
|
1180
|
+
this.protocol.setFlags(flags);
|
|
1181
|
+
this.protocol.setMode(mode);
|
|
1182
|
+
if (data) {
|
|
1183
|
+
this.protocol.setData(data);
|
|
1184
|
+
}
|
|
1185
|
+
this.protocol.setStatus(Status.READY);
|
|
1186
|
+
this.protocol.notify();
|
|
1187
|
+
const waitResult = this.protocol.waitForResult(5e3);
|
|
1188
|
+
if (waitResult === "timed-out") {
|
|
1189
|
+
return { success: false, error: "Operation timed out" };
|
|
1190
|
+
}
|
|
1191
|
+
const status = this.protocol.getStatus();
|
|
1192
|
+
if (status === Status.SUCCESS) {
|
|
1193
|
+
return { success: true, result: this.protocol.getResult() };
|
|
1194
|
+
}
|
|
1195
|
+
return {
|
|
1196
|
+
success: false,
|
|
1197
|
+
error: this.protocol.getResultAsString() || `Error code: ${this.protocol.getErrorCode()}`
|
|
1198
|
+
};
|
|
1199
|
+
}
|
|
1200
|
+
readFile(path) {
|
|
1201
|
+
const result = this.execSync(OpCode.READ_FILE, path);
|
|
1202
|
+
if (!result.success) {
|
|
1203
|
+
throw new Error(result.error || "Failed to read file");
|
|
1204
|
+
}
|
|
1205
|
+
return result.result ?? new Uint8Array(0);
|
|
1206
|
+
}
|
|
1207
|
+
writeFile(path, data) {
|
|
1208
|
+
const result = this.execSync(OpCode.WRITE_FILE, path, data);
|
|
1209
|
+
if (!result.success) {
|
|
1210
|
+
throw new Error(result.error || "Failed to write file");
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
stat(path) {
|
|
1214
|
+
const result = this.execSync(OpCode.STAT, path);
|
|
1215
|
+
if (!result.success) {
|
|
1216
|
+
throw new Error(result.error || "Failed to stat");
|
|
1217
|
+
}
|
|
1218
|
+
return this.protocol.decodeStat();
|
|
1219
|
+
}
|
|
1220
|
+
lstat(path) {
|
|
1221
|
+
const result = this.execSync(OpCode.LSTAT, path);
|
|
1222
|
+
if (!result.success) {
|
|
1223
|
+
throw new Error(result.error || "Failed to lstat");
|
|
1224
|
+
}
|
|
1225
|
+
return this.protocol.decodeStat();
|
|
1226
|
+
}
|
|
1227
|
+
readdir(path) {
|
|
1228
|
+
const result = this.execSync(OpCode.READDIR, path);
|
|
1229
|
+
if (!result.success) {
|
|
1230
|
+
throw new Error(result.error || "Failed to readdir");
|
|
1231
|
+
}
|
|
1232
|
+
return JSON.parse(this.protocol.getResultAsString());
|
|
1233
|
+
}
|
|
1234
|
+
mkdir(path, recursive = false) {
|
|
1235
|
+
const flags = recursive ? Flags.MKDIR_RECURSIVE : 0;
|
|
1236
|
+
const result = this.execSync(OpCode.MKDIR, path, void 0, flags);
|
|
1237
|
+
if (!result.success) {
|
|
1238
|
+
throw new Error(result.error || "Failed to mkdir");
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
rm(path, recursive = false, force = false) {
|
|
1242
|
+
let flags = 0;
|
|
1243
|
+
if (recursive) flags |= Flags.RECURSIVE;
|
|
1244
|
+
if (force) flags |= Flags.FORCE;
|
|
1245
|
+
const result = this.execSync(OpCode.RM, path, void 0, flags);
|
|
1246
|
+
if (!result.success) {
|
|
1247
|
+
throw new Error(result.error || "Failed to rm");
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
exists(path) {
|
|
1251
|
+
const result = this.execSync(OpCode.EXISTS, path);
|
|
1252
|
+
if (!result.success) {
|
|
1253
|
+
return false;
|
|
1254
|
+
}
|
|
1255
|
+
return result.result?.[0] === 1;
|
|
1256
|
+
}
|
|
1257
|
+
appendFile(path, data) {
|
|
1258
|
+
const result = this.execSync(OpCode.APPEND_FILE, path, data);
|
|
1259
|
+
if (!result.success) {
|
|
1260
|
+
throw new Error(result.error || "Failed to append file");
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
symlink(target, linkPath) {
|
|
1264
|
+
const targetData = new TextEncoder().encode(target);
|
|
1265
|
+
const result = this.execSync(OpCode.SYMLINK, linkPath, targetData);
|
|
1266
|
+
if (!result.success) {
|
|
1267
|
+
throw new Error(result.error || "Failed to symlink");
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
readlink(path) {
|
|
1271
|
+
const result = this.execSync(OpCode.READLINK, path);
|
|
1272
|
+
if (!result.success) {
|
|
1273
|
+
throw new Error(result.error || "Failed to readlink");
|
|
1274
|
+
}
|
|
1275
|
+
return this.protocol.getResultAsString();
|
|
1276
|
+
}
|
|
1277
|
+
chmod(path, mode) {
|
|
1278
|
+
const result = this.execSync(OpCode.CHMOD, path, void 0, 0, mode);
|
|
1279
|
+
if (!result.success) {
|
|
1280
|
+
throw new Error(result.error || "Failed to chmod");
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
realpath(path) {
|
|
1284
|
+
const result = this.execSync(OpCode.REALPATH, path);
|
|
1285
|
+
if (!result.success) {
|
|
1286
|
+
throw new Error(result.error || "Failed to realpath");
|
|
1287
|
+
}
|
|
1288
|
+
return this.protocol.getResultAsString();
|
|
1289
|
+
}
|
|
1290
|
+
writeStdout(data) {
|
|
1291
|
+
const encoded = new TextEncoder().encode(data);
|
|
1292
|
+
this.execSync(OpCode.WRITE_STDOUT, "", encoded);
|
|
1293
|
+
}
|
|
1294
|
+
writeStderr(data) {
|
|
1295
|
+
const encoded = new TextEncoder().encode(data);
|
|
1296
|
+
this.execSync(OpCode.WRITE_STDERR, "", encoded);
|
|
1297
|
+
}
|
|
1298
|
+
exit(code) {
|
|
1299
|
+
this.execSync(OpCode.EXIT, "", void 0, code);
|
|
1300
|
+
}
|
|
1301
|
+
/**
|
|
1302
|
+
* Make an HTTP request through the main thread's secureFetch.
|
|
1303
|
+
* Returns the response as a parsed object.
|
|
1304
|
+
*/
|
|
1305
|
+
httpRequest(url, options) {
|
|
1306
|
+
const requestData = options ? new TextEncoder().encode(JSON.stringify(options)) : void 0;
|
|
1307
|
+
const result = this.execSync(OpCode.HTTP_REQUEST, url, requestData);
|
|
1308
|
+
if (!result.success) {
|
|
1309
|
+
throw new Error(result.error || "HTTP request failed");
|
|
1310
|
+
}
|
|
1311
|
+
const responseJson = new TextDecoder().decode(result.result);
|
|
1312
|
+
return JSON.parse(responseJson);
|
|
1313
|
+
}
|
|
1314
|
+
};
|
|
1315
|
+
|
|
1316
|
+
// src/commands/python3/worker.ts
|
|
1317
|
+
var pyodideInstance = null;
|
|
1318
|
+
var pyodideLoading = null;
|
|
1319
|
+
var require2 = createRequire(import.meta.url);
|
|
1320
|
+
var pyodideIndexURL = `${dirname(require2.resolve("pyodide/pyodide.mjs"))}/`;
|
|
1321
|
+
async function getPyodide() {
|
|
1322
|
+
if (pyodideInstance) {
|
|
1323
|
+
return pyodideInstance;
|
|
1324
|
+
}
|
|
1325
|
+
if (pyodideLoading) {
|
|
1326
|
+
return pyodideLoading;
|
|
1327
|
+
}
|
|
1328
|
+
pyodideLoading = loadPyodide({ indexURL: pyodideIndexURL });
|
|
1329
|
+
pyodideInstance = await pyodideLoading;
|
|
1330
|
+
return pyodideInstance;
|
|
1331
|
+
}
|
|
1332
|
+
function createHOSTFS(backend, FS, PATH) {
|
|
1333
|
+
const ERRNO_CODES = {
|
|
1334
|
+
EPERM: 63,
|
|
1335
|
+
ENOENT: 44,
|
|
1336
|
+
EIO: 29,
|
|
1337
|
+
EBADF: 8,
|
|
1338
|
+
EAGAIN: 6,
|
|
1339
|
+
EACCES: 2,
|
|
1340
|
+
EBUSY: 10,
|
|
1341
|
+
EEXIST: 20,
|
|
1342
|
+
ENOTDIR: 54,
|
|
1343
|
+
EISDIR: 31,
|
|
1344
|
+
EINVAL: 28,
|
|
1345
|
+
EMFILE: 33,
|
|
1346
|
+
ENOSPC: 51,
|
|
1347
|
+
ESPIPE: 70,
|
|
1348
|
+
EROFS: 69,
|
|
1349
|
+
ENOTEMPTY: 55,
|
|
1350
|
+
ENOSYS: 52,
|
|
1351
|
+
ENOTSUP: 138,
|
|
1352
|
+
ENODATA: 42
|
|
1353
|
+
};
|
|
1354
|
+
function realPath(node) {
|
|
1355
|
+
const parts = [];
|
|
1356
|
+
while (node.parent !== node) {
|
|
1357
|
+
parts.push(node.name);
|
|
1358
|
+
node = node.parent;
|
|
1359
|
+
}
|
|
1360
|
+
parts.push(node.mount.opts.root);
|
|
1361
|
+
parts.reverse();
|
|
1362
|
+
return PATH.join(...parts);
|
|
1363
|
+
}
|
|
1364
|
+
function tryFSOperation(f) {
|
|
1365
|
+
try {
|
|
1366
|
+
return f();
|
|
1367
|
+
} catch (e) {
|
|
1368
|
+
const msg = e?.message?.toLowerCase() || (typeof e === "string" ? e.toLowerCase() : "");
|
|
1369
|
+
let code = ERRNO_CODES.EIO;
|
|
1370
|
+
if (msg.includes("no such file") || msg.includes("not found")) {
|
|
1371
|
+
code = ERRNO_CODES.ENOENT;
|
|
1372
|
+
} else if (msg.includes("is a directory")) {
|
|
1373
|
+
code = ERRNO_CODES.EISDIR;
|
|
1374
|
+
} else if (msg.includes("not a directory")) {
|
|
1375
|
+
code = ERRNO_CODES.ENOTDIR;
|
|
1376
|
+
} else if (msg.includes("already exists")) {
|
|
1377
|
+
code = ERRNO_CODES.EEXIST;
|
|
1378
|
+
} else if (msg.includes("permission")) {
|
|
1379
|
+
code = ERRNO_CODES.EACCES;
|
|
1380
|
+
} else if (msg.includes("not empty")) {
|
|
1381
|
+
code = ERRNO_CODES.ENOTEMPTY;
|
|
1382
|
+
}
|
|
1383
|
+
throw new FS.ErrnoError(code);
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
function getMode(path) {
|
|
1387
|
+
return tryFSOperation(() => {
|
|
1388
|
+
const stat = backend.stat(path);
|
|
1389
|
+
let mode = stat.mode & 511;
|
|
1390
|
+
if (stat.isDirectory) {
|
|
1391
|
+
mode |= 16384;
|
|
1392
|
+
} else if (stat.isSymbolicLink) {
|
|
1393
|
+
mode |= 40960;
|
|
1394
|
+
} else {
|
|
1395
|
+
mode |= 32768;
|
|
1396
|
+
}
|
|
1397
|
+
return mode;
|
|
1398
|
+
});
|
|
1399
|
+
}
|
|
1400
|
+
const HOSTFS = {
|
|
1401
|
+
mount(_mount) {
|
|
1402
|
+
return HOSTFS.createNode(null, "/", 16877, 0);
|
|
1403
|
+
},
|
|
1404
|
+
createNode(parent, name, mode, dev) {
|
|
1405
|
+
if (!FS.isDir(mode) && !FS.isFile(mode) && !FS.isLink(mode)) {
|
|
1406
|
+
throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
|
|
1407
|
+
}
|
|
1408
|
+
const node = FS.createNode(parent, name, mode, dev);
|
|
1409
|
+
node.node_ops = HOSTFS.node_ops;
|
|
1410
|
+
node.stream_ops = HOSTFS.stream_ops;
|
|
1411
|
+
return node;
|
|
1412
|
+
},
|
|
1413
|
+
node_ops: {
|
|
1414
|
+
getattr(node) {
|
|
1415
|
+
const path = realPath(node);
|
|
1416
|
+
return tryFSOperation(() => {
|
|
1417
|
+
const stat = backend.stat(path);
|
|
1418
|
+
let mode = stat.mode & 511;
|
|
1419
|
+
if (stat.isDirectory) {
|
|
1420
|
+
mode |= 16384;
|
|
1421
|
+
} else if (stat.isSymbolicLink) {
|
|
1422
|
+
mode |= 40960;
|
|
1423
|
+
} else {
|
|
1424
|
+
mode |= 32768;
|
|
1425
|
+
}
|
|
1426
|
+
return {
|
|
1427
|
+
dev: 1,
|
|
1428
|
+
ino: node.id,
|
|
1429
|
+
mode,
|
|
1430
|
+
nlink: 1,
|
|
1431
|
+
uid: 0,
|
|
1432
|
+
gid: 0,
|
|
1433
|
+
rdev: 0,
|
|
1434
|
+
size: stat.size,
|
|
1435
|
+
atime: stat.mtime,
|
|
1436
|
+
mtime: stat.mtime,
|
|
1437
|
+
ctime: stat.mtime,
|
|
1438
|
+
blksize: 4096,
|
|
1439
|
+
blocks: Math.ceil(stat.size / 512)
|
|
1440
|
+
};
|
|
1441
|
+
});
|
|
1442
|
+
},
|
|
1443
|
+
setattr(node, attr) {
|
|
1444
|
+
const path = realPath(node);
|
|
1445
|
+
const mode = attr.mode;
|
|
1446
|
+
if (mode !== void 0) {
|
|
1447
|
+
tryFSOperation(() => backend.chmod(path, mode));
|
|
1448
|
+
node.mode = mode;
|
|
1449
|
+
}
|
|
1450
|
+
if (attr.size !== void 0) {
|
|
1451
|
+
tryFSOperation(() => {
|
|
1452
|
+
const content = backend.readFile(path);
|
|
1453
|
+
const newContent = content.slice(0, attr.size);
|
|
1454
|
+
backend.writeFile(path, newContent);
|
|
1455
|
+
});
|
|
1456
|
+
}
|
|
1457
|
+
},
|
|
1458
|
+
lookup(parent, name) {
|
|
1459
|
+
const path = PATH.join2(realPath(parent), name);
|
|
1460
|
+
const mode = getMode(path);
|
|
1461
|
+
return HOSTFS.createNode(parent, name, mode);
|
|
1462
|
+
},
|
|
1463
|
+
mknod(parent, name, mode, _dev) {
|
|
1464
|
+
const node = HOSTFS.createNode(parent, name, mode, _dev);
|
|
1465
|
+
const path = realPath(node);
|
|
1466
|
+
tryFSOperation(() => {
|
|
1467
|
+
if (FS.isDir(node.mode)) {
|
|
1468
|
+
backend.mkdir(path, false);
|
|
1469
|
+
} else {
|
|
1470
|
+
backend.writeFile(path, new Uint8Array(0));
|
|
1471
|
+
}
|
|
1472
|
+
});
|
|
1473
|
+
return node;
|
|
1474
|
+
},
|
|
1475
|
+
rename(oldNode, newDir, newName) {
|
|
1476
|
+
const oldPath = realPath(oldNode);
|
|
1477
|
+
const newPath = PATH.join2(realPath(newDir), newName);
|
|
1478
|
+
tryFSOperation(() => {
|
|
1479
|
+
const content = backend.readFile(oldPath);
|
|
1480
|
+
backend.writeFile(newPath, content);
|
|
1481
|
+
backend.rm(oldPath, false, false);
|
|
1482
|
+
});
|
|
1483
|
+
oldNode.name = newName;
|
|
1484
|
+
},
|
|
1485
|
+
unlink(parent, name) {
|
|
1486
|
+
const path = PATH.join2(realPath(parent), name);
|
|
1487
|
+
tryFSOperation(() => backend.rm(path, false, false));
|
|
1488
|
+
},
|
|
1489
|
+
rmdir(parent, name) {
|
|
1490
|
+
const path = PATH.join2(realPath(parent), name);
|
|
1491
|
+
tryFSOperation(() => backend.rm(path, false, false));
|
|
1492
|
+
},
|
|
1493
|
+
readdir(node) {
|
|
1494
|
+
const path = realPath(node);
|
|
1495
|
+
return tryFSOperation(() => backend.readdir(path));
|
|
1496
|
+
},
|
|
1497
|
+
symlink(parent, newName, oldPath) {
|
|
1498
|
+
const newPath = PATH.join2(realPath(parent), newName);
|
|
1499
|
+
tryFSOperation(() => backend.symlink(oldPath, newPath));
|
|
1500
|
+
},
|
|
1501
|
+
readlink(node) {
|
|
1502
|
+
const path = realPath(node);
|
|
1503
|
+
return tryFSOperation(() => backend.readlink(path));
|
|
1504
|
+
}
|
|
1505
|
+
},
|
|
1506
|
+
stream_ops: {
|
|
1507
|
+
open(stream) {
|
|
1508
|
+
const path = realPath(stream.node);
|
|
1509
|
+
const flags = stream.flags;
|
|
1510
|
+
const O_WRONLY = 1;
|
|
1511
|
+
const O_RDWR = 2;
|
|
1512
|
+
const O_CREAT = 64;
|
|
1513
|
+
const O_TRUNC = 512;
|
|
1514
|
+
const O_APPEND = 1024;
|
|
1515
|
+
const accessMode = flags & 3;
|
|
1516
|
+
const isWrite = accessMode === O_WRONLY || accessMode === O_RDWR;
|
|
1517
|
+
const isCreate = (flags & O_CREAT) !== 0;
|
|
1518
|
+
const isTruncate = (flags & O_TRUNC) !== 0;
|
|
1519
|
+
const isAppend = (flags & O_APPEND) !== 0;
|
|
1520
|
+
if (FS.isDir(stream.node.mode)) {
|
|
1521
|
+
return;
|
|
1522
|
+
}
|
|
1523
|
+
let content;
|
|
1524
|
+
try {
|
|
1525
|
+
if (isTruncate && isWrite) {
|
|
1526
|
+
content = new Uint8Array(0);
|
|
1527
|
+
} else {
|
|
1528
|
+
content = backend.readFile(path);
|
|
1529
|
+
}
|
|
1530
|
+
} catch (_e) {
|
|
1531
|
+
if (isCreate && isWrite) {
|
|
1532
|
+
content = new Uint8Array(0);
|
|
1533
|
+
} else {
|
|
1534
|
+
throw new FS.ErrnoError(ERRNO_CODES.ENOENT);
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
stream.hostContent = content;
|
|
1538
|
+
stream.hostModified = isTruncate && isWrite;
|
|
1539
|
+
stream.hostPath = path;
|
|
1540
|
+
if (isAppend) {
|
|
1541
|
+
stream.position = content.length;
|
|
1542
|
+
}
|
|
1543
|
+
},
|
|
1544
|
+
close(stream) {
|
|
1545
|
+
const hostPath = stream.hostPath;
|
|
1546
|
+
const hostContent = stream.hostContent;
|
|
1547
|
+
if (stream.hostModified && hostContent && hostPath) {
|
|
1548
|
+
tryFSOperation(() => backend.writeFile(hostPath, hostContent));
|
|
1549
|
+
}
|
|
1550
|
+
delete stream.hostContent;
|
|
1551
|
+
delete stream.hostModified;
|
|
1552
|
+
delete stream.hostPath;
|
|
1553
|
+
},
|
|
1554
|
+
read(stream, buffer, offset, length, position) {
|
|
1555
|
+
const content = stream.hostContent;
|
|
1556
|
+
if (!content) return 0;
|
|
1557
|
+
const size = content.length;
|
|
1558
|
+
if (position >= size) return 0;
|
|
1559
|
+
const bytesToRead = Math.min(length, size - position);
|
|
1560
|
+
buffer.set(content.subarray(position, position + bytesToRead), offset);
|
|
1561
|
+
return bytesToRead;
|
|
1562
|
+
},
|
|
1563
|
+
write(stream, buffer, offset, length, position) {
|
|
1564
|
+
let content = stream.hostContent || new Uint8Array(0);
|
|
1565
|
+
const newSize = Math.max(content.length, position + length);
|
|
1566
|
+
if (newSize > content.length) {
|
|
1567
|
+
const newContent = new Uint8Array(newSize);
|
|
1568
|
+
newContent.set(content);
|
|
1569
|
+
content = newContent;
|
|
1570
|
+
stream.hostContent = content;
|
|
1571
|
+
}
|
|
1572
|
+
content.set(buffer.subarray(offset, offset + length), position);
|
|
1573
|
+
stream.hostModified = true;
|
|
1574
|
+
return length;
|
|
1575
|
+
},
|
|
1576
|
+
llseek(stream, offset, whence) {
|
|
1577
|
+
const SEEK_CUR = 1;
|
|
1578
|
+
const SEEK_END = 2;
|
|
1579
|
+
let position = offset;
|
|
1580
|
+
if (whence === SEEK_CUR) {
|
|
1581
|
+
position += stream.position;
|
|
1582
|
+
} else if (whence === SEEK_END) {
|
|
1583
|
+
if (FS.isFile(stream.node.mode)) {
|
|
1584
|
+
const content = stream.hostContent;
|
|
1585
|
+
position += content ? content.length : 0;
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
if (position < 0) {
|
|
1589
|
+
throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
|
|
1590
|
+
}
|
|
1591
|
+
return position;
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
};
|
|
1595
|
+
return HOSTFS;
|
|
1596
|
+
}
|
|
1597
|
+
async function runPython(input) {
|
|
1598
|
+
const backend = new SyncFsBackend(input.sharedBuffer);
|
|
1599
|
+
let pyodide;
|
|
1600
|
+
try {
|
|
1601
|
+
pyodide = await getPyodide();
|
|
1602
|
+
} catch (e) {
|
|
1603
|
+
return {
|
|
1604
|
+
success: false,
|
|
1605
|
+
error: `Failed to load Pyodide: ${e.message}`
|
|
1606
|
+
};
|
|
1607
|
+
}
|
|
1608
|
+
pyodide.setStdout({ batched: () => {
|
|
1609
|
+
} });
|
|
1610
|
+
pyodide.setStderr({ batched: () => {
|
|
1611
|
+
} });
|
|
1612
|
+
try {
|
|
1613
|
+
pyodide.runPython(`
|
|
1614
|
+
import sys
|
|
1615
|
+
if hasattr(sys.stdout, 'flush'):
|
|
1616
|
+
sys.stdout.flush()
|
|
1617
|
+
if hasattr(sys.stderr, 'flush'):
|
|
1618
|
+
sys.stderr.flush()
|
|
1619
|
+
`);
|
|
1620
|
+
} catch (_e) {
|
|
1621
|
+
}
|
|
1622
|
+
pyodide.setStdout({
|
|
1623
|
+
batched: (text) => {
|
|
1624
|
+
backend.writeStdout(`${text}
|
|
1625
|
+
`);
|
|
1626
|
+
}
|
|
1627
|
+
});
|
|
1628
|
+
pyodide.setStderr({
|
|
1629
|
+
batched: (text) => {
|
|
1630
|
+
backend.writeStderr(`${text}
|
|
1631
|
+
`);
|
|
1632
|
+
}
|
|
1633
|
+
});
|
|
1634
|
+
const FS = pyodide.FS;
|
|
1635
|
+
const PATH = pyodide.PATH;
|
|
1636
|
+
const HOSTFS = createHOSTFS(backend, FS, PATH);
|
|
1637
|
+
try {
|
|
1638
|
+
try {
|
|
1639
|
+
pyodide.runPython(`import os; os.chdir('/')`);
|
|
1640
|
+
} catch (_e) {
|
|
1641
|
+
}
|
|
1642
|
+
try {
|
|
1643
|
+
FS.mkdir("/host");
|
|
1644
|
+
} catch (_e) {
|
|
1645
|
+
}
|
|
1646
|
+
try {
|
|
1647
|
+
FS.unmount("/host");
|
|
1648
|
+
} catch (_e) {
|
|
1649
|
+
}
|
|
1650
|
+
FS.mount(HOSTFS, { root: "/" }, "/host");
|
|
1651
|
+
} catch (e) {
|
|
1652
|
+
return {
|
|
1653
|
+
success: false,
|
|
1654
|
+
error: `Failed to mount HOSTFS: ${e.message}`
|
|
1655
|
+
};
|
|
1656
|
+
}
|
|
1657
|
+
try {
|
|
1658
|
+
pyodide.runPython(`
|
|
1659
|
+
import sys
|
|
1660
|
+
if '_jb_http_bridge' in sys.modules:
|
|
1661
|
+
del sys.modules['_jb_http_bridge']
|
|
1662
|
+
if 'jb_http' in sys.modules:
|
|
1663
|
+
del sys.modules['jb_http']
|
|
1664
|
+
`);
|
|
1665
|
+
} catch (_e) {
|
|
1666
|
+
}
|
|
1667
|
+
pyodide.registerJsModule("_jb_http_bridge", {
|
|
1668
|
+
request: (url, method, headersJson, body) => {
|
|
1669
|
+
try {
|
|
1670
|
+
const headers = headersJson ? JSON.parse(headersJson) : void 0;
|
|
1671
|
+
const result = backend.httpRequest(url, {
|
|
1672
|
+
method: method || "GET",
|
|
1673
|
+
headers,
|
|
1674
|
+
body: body || void 0
|
|
1675
|
+
});
|
|
1676
|
+
return JSON.stringify(result);
|
|
1677
|
+
} catch (e) {
|
|
1678
|
+
return JSON.stringify({ error: e.message });
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
});
|
|
1682
|
+
const envSetup = Object.entries(input.env).map(([key, value]) => {
|
|
1683
|
+
return `os.environ[${JSON.stringify(key)}] = ${JSON.stringify(value)}`;
|
|
1684
|
+
}).join("\n");
|
|
1685
|
+
const argv0 = input.scriptPath || "python3";
|
|
1686
|
+
const argvList = [argv0, ...input.args].map((arg) => JSON.stringify(arg)).join(", ");
|
|
1687
|
+
try {
|
|
1688
|
+
await pyodide.runPythonAsync(`
|
|
1689
|
+
import os
|
|
1690
|
+
import sys
|
|
1691
|
+
import builtins
|
|
1692
|
+
import json
|
|
1693
|
+
|
|
1694
|
+
${envSetup}
|
|
1695
|
+
|
|
1696
|
+
sys.argv = [${argvList}]
|
|
1697
|
+
|
|
1698
|
+
# Create jb_http module for HTTP requests
|
|
1699
|
+
class _JbHttpResponse:
|
|
1700
|
+
"""HTTP response object similar to requests.Response"""
|
|
1701
|
+
def __init__(self, data):
|
|
1702
|
+
self.status_code = data.get('status', 0)
|
|
1703
|
+
self.reason = data.get('statusText', '')
|
|
1704
|
+
# @banned-pattern-ignore: Python code, not JavaScript
|
|
1705
|
+
self.headers = data.get('headers', {})
|
|
1706
|
+
self.text = data.get('body', '')
|
|
1707
|
+
self.url = data.get('url', '')
|
|
1708
|
+
self._error = data.get('error')
|
|
1709
|
+
|
|
1710
|
+
@property
|
|
1711
|
+
def ok(self):
|
|
1712
|
+
return 200 <= self.status_code < 300
|
|
1713
|
+
|
|
1714
|
+
def json(self):
|
|
1715
|
+
return json.loads(self.text)
|
|
1716
|
+
|
|
1717
|
+
def raise_for_status(self):
|
|
1718
|
+
if self._error:
|
|
1719
|
+
raise Exception(self._error)
|
|
1720
|
+
if not self.ok:
|
|
1721
|
+
raise Exception(f"HTTP {self.status_code}: {self.reason}")
|
|
1722
|
+
|
|
1723
|
+
class _JbHttp:
|
|
1724
|
+
"""HTTP client that bridges to just-bash's secureFetch"""
|
|
1725
|
+
def request(self, method, url, headers=None, data=None, json_data=None):
|
|
1726
|
+
# Import fresh each time to ensure we use the current bridge
|
|
1727
|
+
# (important when worker is reused with different SharedArrayBuffer)
|
|
1728
|
+
import _jb_http_bridge
|
|
1729
|
+
if json_data is not None:
|
|
1730
|
+
data = json.dumps(json_data)
|
|
1731
|
+
headers = headers or {}
|
|
1732
|
+
headers['Content-Type'] = 'application/json'
|
|
1733
|
+
# Serialize headers to JSON to avoid PyProxy issues when passing to JS
|
|
1734
|
+
headers_json = json.dumps(headers) if headers else None
|
|
1735
|
+
result_json = _jb_http_bridge.request(url, method, headers_json, data)
|
|
1736
|
+
result = json.loads(result_json)
|
|
1737
|
+
# Check for errors from the bridge (network not configured, URL not allowed, etc.)
|
|
1738
|
+
if 'error' in result and result.get('status') is None:
|
|
1739
|
+
raise Exception(result['error'])
|
|
1740
|
+
return _JbHttpResponse(result)
|
|
1741
|
+
|
|
1742
|
+
def get(self, url, headers=None, **kwargs):
|
|
1743
|
+
return self.request('GET', url, headers=headers, **kwargs)
|
|
1744
|
+
|
|
1745
|
+
def post(self, url, headers=None, data=None, json=None, **kwargs):
|
|
1746
|
+
return self.request('POST', url, headers=headers, data=data, json_data=json, **kwargs)
|
|
1747
|
+
|
|
1748
|
+
def put(self, url, headers=None, data=None, json=None, **kwargs):
|
|
1749
|
+
return self.request('PUT', url, headers=headers, data=data, json_data=json, **kwargs)
|
|
1750
|
+
|
|
1751
|
+
def delete(self, url, headers=None, **kwargs):
|
|
1752
|
+
return self.request('DELETE', url, headers=headers, **kwargs)
|
|
1753
|
+
|
|
1754
|
+
def head(self, url, headers=None, **kwargs):
|
|
1755
|
+
return self.request('HEAD', url, headers=headers, **kwargs)
|
|
1756
|
+
|
|
1757
|
+
def patch(self, url, headers=None, data=None, json=None, **kwargs):
|
|
1758
|
+
return self.request('PATCH', url, headers=headers, data=data, json_data=json, **kwargs)
|
|
1759
|
+
|
|
1760
|
+
# Register jb_http as an importable module
|
|
1761
|
+
import types
|
|
1762
|
+
jb_http = types.ModuleType('jb_http')
|
|
1763
|
+
jb_http._client = _JbHttp()
|
|
1764
|
+
jb_http.get = jb_http._client.get
|
|
1765
|
+
jb_http.post = jb_http._client.post
|
|
1766
|
+
jb_http.put = jb_http._client.put
|
|
1767
|
+
jb_http.delete = jb_http._client.delete
|
|
1768
|
+
jb_http.head = jb_http._client.head
|
|
1769
|
+
jb_http.patch = jb_http._client.patch
|
|
1770
|
+
jb_http.request = jb_http._client.request
|
|
1771
|
+
jb_http.Response = _JbHttpResponse
|
|
1772
|
+
sys.modules['jb_http'] = jb_http
|
|
1773
|
+
|
|
1774
|
+
# ============================================================
|
|
1775
|
+
# SANDBOX SECURITY SETUP
|
|
1776
|
+
# ============================================================
|
|
1777
|
+
# Only apply sandbox restrictions once per Pyodide instance
|
|
1778
|
+
if not hasattr(builtins, '_jb_sandbox_initialized'):
|
|
1779
|
+
builtins._jb_sandbox_initialized = True
|
|
1780
|
+
|
|
1781
|
+
# ------------------------------------------------------------
|
|
1782
|
+
# 1. Block dangerous module imports (js, pyodide, pyodide_js, pyodide.ffi)
|
|
1783
|
+
# These allow sandbox escape via JavaScript execution
|
|
1784
|
+
# ------------------------------------------------------------
|
|
1785
|
+
_BLOCKED_MODULES = frozenset({'js', 'pyodide', 'pyodide_js', 'pyodide.ffi'})
|
|
1786
|
+
_BLOCKED_PREFIXES = ('js.', 'pyodide.', 'pyodide_js.')
|
|
1787
|
+
|
|
1788
|
+
# Remove pre-loaded dangerous modules from sys.modules
|
|
1789
|
+
for _blocked_mod in list(sys.modules.keys()):
|
|
1790
|
+
if _blocked_mod in _BLOCKED_MODULES or any(_blocked_mod.startswith(p) for p in _BLOCKED_PREFIXES):
|
|
1791
|
+
del sys.modules[_blocked_mod]
|
|
1792
|
+
|
|
1793
|
+
# Create a secure callable wrapper that hides introspection attributes
|
|
1794
|
+
# This prevents access to __closure__, __kwdefaults__, __globals__, etc.
|
|
1795
|
+
def _make_secure_import(orig_import, blocked, prefixes):
|
|
1796
|
+
"""Create import function wrapped to block introspection."""
|
|
1797
|
+
def _inner(name, globals=None, locals=None, fromlist=(), level=0):
|
|
1798
|
+
if name in blocked or any(name.startswith(p) for p in prefixes):
|
|
1799
|
+
raise ImportError(f"Module '{name}' is blocked in this sandbox")
|
|
1800
|
+
return orig_import(name, globals, locals, fromlist, level)
|
|
1801
|
+
|
|
1802
|
+
class _SecureImport:
|
|
1803
|
+
"""Wrapper that hides function internals from introspection."""
|
|
1804
|
+
__slots__ = ()
|
|
1805
|
+
def __call__(self, name, globals=None, locals=None, fromlist=(), level=0):
|
|
1806
|
+
return _inner(name, globals, locals, fromlist, level)
|
|
1807
|
+
def __getattribute__(self, name):
|
|
1808
|
+
if name in ('__call__', '__class__'):
|
|
1809
|
+
return object.__getattribute__(self, name)
|
|
1810
|
+
raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'")
|
|
1811
|
+
def __repr__(self):
|
|
1812
|
+
return '<built-in function __import__>'
|
|
1813
|
+
return _SecureImport()
|
|
1814
|
+
|
|
1815
|
+
builtins.__import__ = _make_secure_import(builtins.__import__, _BLOCKED_MODULES, _BLOCKED_PREFIXES)
|
|
1816
|
+
del _BLOCKED_MODULES, _BLOCKED_PREFIXES, _make_secure_import
|
|
1817
|
+
|
|
1818
|
+
# ------------------------------------------------------------
|
|
1819
|
+
# 2. Path redirection helper
|
|
1820
|
+
# ------------------------------------------------------------
|
|
1821
|
+
def _should_redirect(path):
|
|
1822
|
+
"""Check if a path should be redirected to /host."""
|
|
1823
|
+
return (isinstance(path, str) and
|
|
1824
|
+
path.startswith('/') and
|
|
1825
|
+
not path.startswith('/lib') and
|
|
1826
|
+
not path.startswith('/proc') and
|
|
1827
|
+
not path.startswith('/host'))
|
|
1828
|
+
|
|
1829
|
+
# ------------------------------------------------------------
|
|
1830
|
+
# 3. Secure wrapper factory for file operations
|
|
1831
|
+
# ------------------------------------------------------------
|
|
1832
|
+
# This creates callable wrappers that hide __closure__, __globals__, etc.
|
|
1833
|
+
def _make_secure_wrapper(func, name):
|
|
1834
|
+
"""Wrap a function to block introspection attributes."""
|
|
1835
|
+
class _SecureWrapper:
|
|
1836
|
+
__slots__ = ()
|
|
1837
|
+
def __call__(self, *args, **kwargs):
|
|
1838
|
+
return func(*args, **kwargs)
|
|
1839
|
+
def __getattribute__(self, attr):
|
|
1840
|
+
if attr in ('__call__', '__class__'):
|
|
1841
|
+
return object.__getattribute__(self, attr)
|
|
1842
|
+
raise AttributeError(f"'{type(self).__name__}' object has no attribute '{attr}'")
|
|
1843
|
+
def __repr__(self):
|
|
1844
|
+
return f'<built-in function {name}>'
|
|
1845
|
+
return _SecureWrapper()
|
|
1846
|
+
|
|
1847
|
+
# ------------------------------------------------------------
|
|
1848
|
+
# 4. Redirect file operations to /host (with secure wrappers)
|
|
1849
|
+
# ------------------------------------------------------------
|
|
1850
|
+
# builtins.open
|
|
1851
|
+
_orig_open = builtins.open
|
|
1852
|
+
def _redir_open(path, mode='r', *args, **kwargs):
|
|
1853
|
+
if _should_redirect(path):
|
|
1854
|
+
path = '/host' + path
|
|
1855
|
+
return _orig_open(path, mode, *args, **kwargs)
|
|
1856
|
+
builtins.open = _make_secure_wrapper(_redir_open, 'open')
|
|
1857
|
+
|
|
1858
|
+
# os.listdir
|
|
1859
|
+
_orig_listdir = os.listdir
|
|
1860
|
+
def _redir_listdir(path='.'):
|
|
1861
|
+
if _should_redirect(path):
|
|
1862
|
+
path = '/host' + path
|
|
1863
|
+
return _orig_listdir(path)
|
|
1864
|
+
os.listdir = _make_secure_wrapper(_redir_listdir, 'listdir')
|
|
1865
|
+
|
|
1866
|
+
# os.path.exists
|
|
1867
|
+
_orig_exists = os.path.exists
|
|
1868
|
+
def _redir_exists(path):
|
|
1869
|
+
if _should_redirect(path):
|
|
1870
|
+
path = '/host' + path
|
|
1871
|
+
return _orig_exists(path)
|
|
1872
|
+
os.path.exists = _make_secure_wrapper(_redir_exists, 'exists')
|
|
1873
|
+
|
|
1874
|
+
# os.path.isfile
|
|
1875
|
+
_orig_isfile = os.path.isfile
|
|
1876
|
+
def _redir_isfile(path):
|
|
1877
|
+
if _should_redirect(path):
|
|
1878
|
+
path = '/host' + path
|
|
1879
|
+
return _orig_isfile(path)
|
|
1880
|
+
os.path.isfile = _make_secure_wrapper(_redir_isfile, 'isfile')
|
|
1881
|
+
|
|
1882
|
+
# os.path.isdir
|
|
1883
|
+
_orig_isdir = os.path.isdir
|
|
1884
|
+
def _redir_isdir(path):
|
|
1885
|
+
if _should_redirect(path):
|
|
1886
|
+
path = '/host' + path
|
|
1887
|
+
return _orig_isdir(path)
|
|
1888
|
+
os.path.isdir = _make_secure_wrapper(_redir_isdir, 'isdir')
|
|
1889
|
+
|
|
1890
|
+
# os.stat
|
|
1891
|
+
_orig_stat = os.stat
|
|
1892
|
+
def _redir_stat(path, *args, **kwargs):
|
|
1893
|
+
if _should_redirect(path):
|
|
1894
|
+
path = '/host' + path
|
|
1895
|
+
return _orig_stat(path, *args, **kwargs)
|
|
1896
|
+
os.stat = _make_secure_wrapper(_redir_stat, 'stat')
|
|
1897
|
+
|
|
1898
|
+
# os.mkdir
|
|
1899
|
+
_orig_mkdir = os.mkdir
|
|
1900
|
+
def _redir_mkdir(path, *args, **kwargs):
|
|
1901
|
+
if _should_redirect(path):
|
|
1902
|
+
path = '/host' + path
|
|
1903
|
+
return _orig_mkdir(path, *args, **kwargs)
|
|
1904
|
+
os.mkdir = _make_secure_wrapper(_redir_mkdir, 'mkdir')
|
|
1905
|
+
|
|
1906
|
+
# os.makedirs
|
|
1907
|
+
_orig_makedirs = os.makedirs
|
|
1908
|
+
def _redir_makedirs(path, *args, **kwargs):
|
|
1909
|
+
if _should_redirect(path):
|
|
1910
|
+
path = '/host' + path
|
|
1911
|
+
return _orig_makedirs(path, *args, **kwargs)
|
|
1912
|
+
os.makedirs = _make_secure_wrapper(_redir_makedirs, 'makedirs')
|
|
1913
|
+
|
|
1914
|
+
# os.remove
|
|
1915
|
+
_orig_remove = os.remove
|
|
1916
|
+
def _redir_remove(path, *args, **kwargs):
|
|
1917
|
+
if _should_redirect(path):
|
|
1918
|
+
path = '/host' + path
|
|
1919
|
+
return _orig_remove(path, *args, **kwargs)
|
|
1920
|
+
os.remove = _make_secure_wrapper(_redir_remove, 'remove')
|
|
1921
|
+
|
|
1922
|
+
# os.rmdir
|
|
1923
|
+
_orig_rmdir = os.rmdir
|
|
1924
|
+
def _redir_rmdir(path, *args, **kwargs):
|
|
1925
|
+
if _should_redirect(path):
|
|
1926
|
+
path = '/host' + path
|
|
1927
|
+
return _orig_rmdir(path, *args, **kwargs)
|
|
1928
|
+
os.rmdir = _make_secure_wrapper(_redir_rmdir, 'rmdir')
|
|
1929
|
+
|
|
1930
|
+
# os.getcwd - strip /host prefix
|
|
1931
|
+
_orig_getcwd = os.getcwd
|
|
1932
|
+
def _redir_getcwd():
|
|
1933
|
+
cwd = _orig_getcwd()
|
|
1934
|
+
if cwd.startswith('/host'):
|
|
1935
|
+
return cwd[5:] # Strip '/host' prefix
|
|
1936
|
+
return cwd
|
|
1937
|
+
os.getcwd = _make_secure_wrapper(_redir_getcwd, 'getcwd')
|
|
1938
|
+
|
|
1939
|
+
# os.chdir
|
|
1940
|
+
_orig_chdir = os.chdir
|
|
1941
|
+
def _redir_chdir(path):
|
|
1942
|
+
if _should_redirect(path):
|
|
1943
|
+
path = '/host' + path
|
|
1944
|
+
return _orig_chdir(path)
|
|
1945
|
+
os.chdir = _make_secure_wrapper(_redir_chdir, 'chdir')
|
|
1946
|
+
|
|
1947
|
+
# ------------------------------------------------------------
|
|
1948
|
+
# 5. Additional file operations (glob, walk, scandir, io.open)
|
|
1949
|
+
# ------------------------------------------------------------
|
|
1950
|
+
import glob as _glob_module
|
|
1951
|
+
|
|
1952
|
+
_orig_glob = _glob_module.glob
|
|
1953
|
+
def _redir_glob(pathname, *args, **kwargs):
|
|
1954
|
+
if _should_redirect(pathname):
|
|
1955
|
+
pathname = '/host' + pathname
|
|
1956
|
+
return _orig_glob(pathname, *args, **kwargs)
|
|
1957
|
+
_glob_module.glob = _make_secure_wrapper(_redir_glob, 'glob')
|
|
1958
|
+
|
|
1959
|
+
_orig_iglob = _glob_module.iglob
|
|
1960
|
+
def _redir_iglob(pathname, *args, **kwargs):
|
|
1961
|
+
if _should_redirect(pathname):
|
|
1962
|
+
pathname = '/host' + pathname
|
|
1963
|
+
return _orig_iglob(pathname, *args, **kwargs)
|
|
1964
|
+
_glob_module.iglob = _make_secure_wrapper(_redir_iglob, 'iglob')
|
|
1965
|
+
|
|
1966
|
+
# os.walk (generator - needs special handling)
|
|
1967
|
+
_orig_walk = os.walk
|
|
1968
|
+
def _redir_walk(top, *args, **kwargs):
|
|
1969
|
+
redirected = False
|
|
1970
|
+
if _should_redirect(top):
|
|
1971
|
+
top = '/host' + top
|
|
1972
|
+
redirected = True
|
|
1973
|
+
for dirpath, dirnames, filenames in _orig_walk(top, *args, **kwargs):
|
|
1974
|
+
if redirected and dirpath.startswith('/host'):
|
|
1975
|
+
dirpath = dirpath[5:] if len(dirpath) > 5 else '/'
|
|
1976
|
+
yield dirpath, dirnames, filenames
|
|
1977
|
+
os.walk = _make_secure_wrapper(_redir_walk, 'walk')
|
|
1978
|
+
|
|
1979
|
+
# os.scandir
|
|
1980
|
+
_orig_scandir = os.scandir
|
|
1981
|
+
def _redir_scandir(path='.'):
|
|
1982
|
+
if _should_redirect(path):
|
|
1983
|
+
path = '/host' + path
|
|
1984
|
+
return _orig_scandir(path)
|
|
1985
|
+
os.scandir = _make_secure_wrapper(_redir_scandir, 'scandir')
|
|
1986
|
+
|
|
1987
|
+
# io.open (same secure wrapper as builtins.open)
|
|
1988
|
+
import io as _io_module
|
|
1989
|
+
_io_module.open = builtins.open
|
|
1990
|
+
|
|
1991
|
+
# ------------------------------------------------------------
|
|
1992
|
+
# 6. shutil file operations
|
|
1993
|
+
# ------------------------------------------------------------
|
|
1994
|
+
import shutil as _shutil_module
|
|
1995
|
+
|
|
1996
|
+
# shutil.copy(src, dst)
|
|
1997
|
+
_orig_shutil_copy = _shutil_module.copy
|
|
1998
|
+
def _redir_shutil_copy(src, dst, *args, **kwargs):
|
|
1999
|
+
if _should_redirect(src):
|
|
2000
|
+
src = '/host' + src
|
|
2001
|
+
if _should_redirect(dst):
|
|
2002
|
+
dst = '/host' + dst
|
|
2003
|
+
return _orig_shutil_copy(src, dst, *args, **kwargs)
|
|
2004
|
+
_shutil_module.copy = _make_secure_wrapper(_redir_shutil_copy, 'copy')
|
|
2005
|
+
|
|
2006
|
+
# shutil.copy2(src, dst)
|
|
2007
|
+
_orig_shutil_copy2 = _shutil_module.copy2
|
|
2008
|
+
def _redir_shutil_copy2(src, dst, *args, **kwargs):
|
|
2009
|
+
if _should_redirect(src):
|
|
2010
|
+
src = '/host' + src
|
|
2011
|
+
if _should_redirect(dst):
|
|
2012
|
+
dst = '/host' + dst
|
|
2013
|
+
return _orig_shutil_copy2(src, dst, *args, **kwargs)
|
|
2014
|
+
_shutil_module.copy2 = _make_secure_wrapper(_redir_shutil_copy2, 'copy2')
|
|
2015
|
+
|
|
2016
|
+
# shutil.copyfile(src, dst)
|
|
2017
|
+
_orig_shutil_copyfile = _shutil_module.copyfile
|
|
2018
|
+
def _redir_shutil_copyfile(src, dst, *args, **kwargs):
|
|
2019
|
+
if _should_redirect(src):
|
|
2020
|
+
src = '/host' + src
|
|
2021
|
+
if _should_redirect(dst):
|
|
2022
|
+
dst = '/host' + dst
|
|
2023
|
+
return _orig_shutil_copyfile(src, dst, *args, **kwargs)
|
|
2024
|
+
_shutil_module.copyfile = _make_secure_wrapper(_redir_shutil_copyfile, 'copyfile')
|
|
2025
|
+
|
|
2026
|
+
# shutil.copytree(src, dst)
|
|
2027
|
+
_orig_shutil_copytree = _shutil_module.copytree
|
|
2028
|
+
def _redir_shutil_copytree(src, dst, *args, **kwargs):
|
|
2029
|
+
if _should_redirect(src):
|
|
2030
|
+
src = '/host' + src
|
|
2031
|
+
if _should_redirect(dst):
|
|
2032
|
+
dst = '/host' + dst
|
|
2033
|
+
return _orig_shutil_copytree(src, dst, *args, **kwargs)
|
|
2034
|
+
_shutil_module.copytree = _make_secure_wrapper(_redir_shutil_copytree, 'copytree')
|
|
2035
|
+
|
|
2036
|
+
# shutil.move(src, dst)
|
|
2037
|
+
_orig_shutil_move = _shutil_module.move
|
|
2038
|
+
def _redir_shutil_move(src, dst, *args, **kwargs):
|
|
2039
|
+
if _should_redirect(src):
|
|
2040
|
+
src = '/host' + src
|
|
2041
|
+
if _should_redirect(dst):
|
|
2042
|
+
dst = '/host' + dst
|
|
2043
|
+
return _orig_shutil_move(src, dst, *args, **kwargs)
|
|
2044
|
+
_shutil_module.move = _make_secure_wrapper(_redir_shutil_move, 'move')
|
|
2045
|
+
|
|
2046
|
+
# shutil.rmtree(path)
|
|
2047
|
+
_orig_shutil_rmtree = _shutil_module.rmtree
|
|
2048
|
+
def _redir_shutil_rmtree(path, *args, **kwargs):
|
|
2049
|
+
if _should_redirect(path):
|
|
2050
|
+
path = '/host' + path
|
|
2051
|
+
return _orig_shutil_rmtree(path, *args, **kwargs)
|
|
2052
|
+
_shutil_module.rmtree = _make_secure_wrapper(_redir_shutil_rmtree, 'rmtree')
|
|
2053
|
+
|
|
2054
|
+
# ------------------------------------------------------------
|
|
2055
|
+
# 7. pathlib.Path - redirect path resolution
|
|
2056
|
+
# ------------------------------------------------------------
|
|
2057
|
+
from pathlib import Path, PurePosixPath
|
|
2058
|
+
|
|
2059
|
+
def _redirect_path(p):
|
|
2060
|
+
"""Convert a Path to redirect /absolute paths to /host."""
|
|
2061
|
+
s = str(p)
|
|
2062
|
+
if _should_redirect(s):
|
|
2063
|
+
return Path('/host' + s)
|
|
2064
|
+
return p
|
|
2065
|
+
|
|
2066
|
+
# Helper to create method wrappers for Path
|
|
2067
|
+
def _wrap_path_method(orig_method, name):
|
|
2068
|
+
def wrapper(self, *args, **kwargs):
|
|
2069
|
+
redirected = _redirect_path(self)
|
|
2070
|
+
return getattr(redirected, '_orig_' + name)(*args, **kwargs)
|
|
2071
|
+
return wrapper
|
|
2072
|
+
|
|
2073
|
+
# Store original methods with _orig_ prefix, then replace with redirecting versions
|
|
2074
|
+
# Path.stat()
|
|
2075
|
+
Path._orig_stat = Path.stat
|
|
2076
|
+
def _path_stat(self, *args, **kwargs):
|
|
2077
|
+
return _redirect_path(self)._orig_stat(*args, **kwargs)
|
|
2078
|
+
Path.stat = _path_stat
|
|
2079
|
+
|
|
2080
|
+
# Path.exists()
|
|
2081
|
+
Path._orig_exists = Path.exists
|
|
2082
|
+
def _path_exists(self):
|
|
2083
|
+
return _redirect_path(self)._orig_exists()
|
|
2084
|
+
Path.exists = _path_exists
|
|
2085
|
+
|
|
2086
|
+
# Path.is_file()
|
|
2087
|
+
Path._orig_is_file = Path.is_file
|
|
2088
|
+
def _path_is_file(self):
|
|
2089
|
+
return _redirect_path(self)._orig_is_file()
|
|
2090
|
+
Path.is_file = _path_is_file
|
|
2091
|
+
|
|
2092
|
+
# Path.is_dir()
|
|
2093
|
+
Path._orig_is_dir = Path.is_dir
|
|
2094
|
+
def _path_is_dir(self):
|
|
2095
|
+
return _redirect_path(self)._orig_is_dir()
|
|
2096
|
+
Path.is_dir = _path_is_dir
|
|
2097
|
+
|
|
2098
|
+
# Path.open()
|
|
2099
|
+
Path._orig_open = Path.open
|
|
2100
|
+
def _path_open(self, *args, **kwargs):
|
|
2101
|
+
return _redirect_path(self)._orig_open(*args, **kwargs)
|
|
2102
|
+
Path.open = _path_open
|
|
2103
|
+
|
|
2104
|
+
# Path.read_text()
|
|
2105
|
+
Path._orig_read_text = Path.read_text
|
|
2106
|
+
def _path_read_text(self, *args, **kwargs):
|
|
2107
|
+
return _redirect_path(self)._orig_read_text(*args, **kwargs)
|
|
2108
|
+
Path.read_text = _path_read_text
|
|
2109
|
+
|
|
2110
|
+
# Path.read_bytes()
|
|
2111
|
+
Path._orig_read_bytes = Path.read_bytes
|
|
2112
|
+
def _path_read_bytes(self):
|
|
2113
|
+
return _redirect_path(self)._orig_read_bytes()
|
|
2114
|
+
Path.read_bytes = _path_read_bytes
|
|
2115
|
+
|
|
2116
|
+
# Path.write_text()
|
|
2117
|
+
Path._orig_write_text = Path.write_text
|
|
2118
|
+
def _path_write_text(self, *args, **kwargs):
|
|
2119
|
+
return _redirect_path(self)._orig_write_text(*args, **kwargs)
|
|
2120
|
+
Path.write_text = _path_write_text
|
|
2121
|
+
|
|
2122
|
+
# Path.write_bytes()
|
|
2123
|
+
Path._orig_write_bytes = Path.write_bytes
|
|
2124
|
+
def _path_write_bytes(self, data):
|
|
2125
|
+
return _redirect_path(self)._orig_write_bytes(data)
|
|
2126
|
+
Path.write_bytes = _path_write_bytes
|
|
2127
|
+
|
|
2128
|
+
# Path.mkdir()
|
|
2129
|
+
Path._orig_mkdir = Path.mkdir
|
|
2130
|
+
def _path_mkdir(self, *args, **kwargs):
|
|
2131
|
+
return _redirect_path(self)._orig_mkdir(*args, **kwargs)
|
|
2132
|
+
Path.mkdir = _path_mkdir
|
|
2133
|
+
|
|
2134
|
+
# Path.rmdir()
|
|
2135
|
+
Path._orig_rmdir = Path.rmdir
|
|
2136
|
+
def _path_rmdir(self):
|
|
2137
|
+
return _redirect_path(self)._orig_rmdir()
|
|
2138
|
+
Path.rmdir = _path_rmdir
|
|
2139
|
+
|
|
2140
|
+
# Path.unlink()
|
|
2141
|
+
Path._orig_unlink = Path.unlink
|
|
2142
|
+
def _path_unlink(self, *args, **kwargs):
|
|
2143
|
+
return _redirect_path(self)._orig_unlink(*args, **kwargs)
|
|
2144
|
+
Path.unlink = _path_unlink
|
|
2145
|
+
|
|
2146
|
+
# Path.iterdir()
|
|
2147
|
+
Path._orig_iterdir = Path.iterdir
|
|
2148
|
+
def _path_iterdir(self):
|
|
2149
|
+
redirected = _redirect_path(self)
|
|
2150
|
+
for p in redirected._orig_iterdir():
|
|
2151
|
+
# Strip /host prefix from results
|
|
2152
|
+
s = str(p)
|
|
2153
|
+
if s.startswith('/host'):
|
|
2154
|
+
yield Path(s[5:])
|
|
2155
|
+
else:
|
|
2156
|
+
yield p
|
|
2157
|
+
Path.iterdir = _path_iterdir
|
|
2158
|
+
|
|
2159
|
+
# Path.glob()
|
|
2160
|
+
Path._orig_glob = Path.glob
|
|
2161
|
+
def _path_glob(self, pattern):
|
|
2162
|
+
redirected = _redirect_path(self)
|
|
2163
|
+
for p in redirected._orig_glob(pattern):
|
|
2164
|
+
s = str(p)
|
|
2165
|
+
if s.startswith('/host'):
|
|
2166
|
+
yield Path(s[5:])
|
|
2167
|
+
else:
|
|
2168
|
+
yield p
|
|
2169
|
+
Path.glob = _path_glob
|
|
2170
|
+
|
|
2171
|
+
# Path.rglob()
|
|
2172
|
+
Path._orig_rglob = Path.rglob
|
|
2173
|
+
def _path_rglob(self, pattern):
|
|
2174
|
+
redirected = _redirect_path(self)
|
|
2175
|
+
for p in redirected._orig_rglob(pattern):
|
|
2176
|
+
s = str(p)
|
|
2177
|
+
if s.startswith('/host'):
|
|
2178
|
+
yield Path(s[5:])
|
|
2179
|
+
else:
|
|
2180
|
+
yield p
|
|
2181
|
+
Path.rglob = _path_rglob
|
|
2182
|
+
|
|
2183
|
+
# Set cwd to host mount
|
|
2184
|
+
os.chdir('/host' + ${JSON.stringify(input.cwd)})
|
|
2185
|
+
`);
|
|
2186
|
+
} catch (e) {
|
|
2187
|
+
return {
|
|
2188
|
+
success: false,
|
|
2189
|
+
error: `Failed to set up environment: ${e.message}`
|
|
2190
|
+
};
|
|
2191
|
+
}
|
|
2192
|
+
try {
|
|
2193
|
+
const wrappedCode = `
|
|
2194
|
+
import sys
|
|
2195
|
+
_jb_exit_code = 0
|
|
2196
|
+
try:
|
|
2197
|
+
${input.pythonCode.split("\n").map((line) => ` ${line}`).join("\n")}
|
|
2198
|
+
except SystemExit as e:
|
|
2199
|
+
_jb_exit_code = e.code if isinstance(e.code, int) else (1 if e.code else 0)
|
|
2200
|
+
`;
|
|
2201
|
+
await pyodide.runPythonAsync(wrappedCode);
|
|
2202
|
+
const exitCode = pyodide.globals.get("_jb_exit_code");
|
|
2203
|
+
backend.exit(exitCode);
|
|
2204
|
+
return { success: true };
|
|
2205
|
+
} catch (e) {
|
|
2206
|
+
const error = e;
|
|
2207
|
+
backend.writeStderr(`${error.message}
|
|
2208
|
+
`);
|
|
2209
|
+
backend.exit(1);
|
|
2210
|
+
return { success: true };
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
var defense = null;
|
|
2214
|
+
async function initializeWithDefense() {
|
|
2215
|
+
await getPyodide();
|
|
2216
|
+
defense = new WorkerDefenseInDepth({
|
|
2217
|
+
excludeViolationTypes: [
|
|
2218
|
+
"proxy",
|
|
2219
|
+
"setImmediate",
|
|
2220
|
+
// 3. SharedArrayBuffer/Atomics: Used by sync-fs-backend.ts for synchronous
|
|
2221
|
+
// filesystem communication between Pyodide's WASM thread and the main thread.
|
|
2222
|
+
// Without this, Pyodide cannot perform synchronous file I/O operations.
|
|
2223
|
+
"shared_array_buffer",
|
|
2224
|
+
"atomics"
|
|
2225
|
+
],
|
|
2226
|
+
onViolation: (v) => {
|
|
2227
|
+
parentPort?.postMessage({ type: "security-violation", violation: v });
|
|
2228
|
+
}
|
|
2229
|
+
});
|
|
2230
|
+
}
|
|
2231
|
+
if (parentPort) {
|
|
2232
|
+
if (workerData) {
|
|
2233
|
+
initializeWithDefense().then(() => runPython(workerData)).then((result) => {
|
|
2234
|
+
result.defenseStats = defense?.getStats();
|
|
2235
|
+
parentPort?.postMessage(result);
|
|
2236
|
+
}).catch((e) => {
|
|
2237
|
+
parentPort?.postMessage({
|
|
2238
|
+
success: false,
|
|
2239
|
+
error: e.message,
|
|
2240
|
+
defenseStats: defense?.getStats()
|
|
2241
|
+
});
|
|
2242
|
+
});
|
|
2243
|
+
}
|
|
2244
|
+
parentPort.on("message", async (input) => {
|
|
2245
|
+
try {
|
|
2246
|
+
if (!defense) {
|
|
2247
|
+
await initializeWithDefense();
|
|
2248
|
+
}
|
|
2249
|
+
const result = await runPython(input);
|
|
2250
|
+
result.defenseStats = defense?.getStats();
|
|
2251
|
+
parentPort?.postMessage(result);
|
|
2252
|
+
} catch (e) {
|
|
2253
|
+
parentPort?.postMessage({
|
|
2254
|
+
success: false,
|
|
2255
|
+
error: e.message,
|
|
2256
|
+
defenseStats: defense?.getStats()
|
|
2257
|
+
});
|
|
2258
|
+
}
|
|
2259
|
+
});
|
|
2260
|
+
}
|