just-bash 2.11.7 → 2.11.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/chunks/chunk-MXVNCVD6.js +30 -0
- package/dist/bin/{shell/chunks/flag-coverage-23SVOOPG.js → chunks/flag-coverage-CVSXSL4T.js} +1 -1
- package/dist/bin/{shell/chunks/ls-ZXYOL67L.js → chunks/ls-G2PXHSNX.js} +1 -1
- package/dist/bin/chunks/worker.js +190 -32
- package/dist/bin/just-bash.js +78 -78
- package/dist/bin/shell/chunks/chunk-MXVNCVD6.js +30 -0
- package/dist/bin/{chunks/flag-coverage-23SVOOPG.js → shell/chunks/flag-coverage-CVSXSL4T.js} +1 -1
- package/dist/bin/{chunks/ls-ZXYOL67L.js → shell/chunks/ls-G2PXHSNX.js} +1 -1
- package/dist/bin/shell/shell.js +103 -103
- package/dist/bundle/browser.js +507 -503
- package/dist/bundle/chunks/chunk-V7TAPXDL.js +27 -0
- package/dist/bundle/chunks/{flag-coverage-YHMPSZHK.js → flag-coverage-KCADAH3N.js} +1 -1
- package/dist/bundle/chunks/{ls-OTONBH2E.js → ls-KSXFZCWH.js} +1 -1
- package/dist/bundle/chunks/worker.js +190 -32
- package/dist/bundle/index.cjs +2072 -0
- package/dist/bundle/index.js +76 -76
- package/dist/index.d.cts +27 -0
- package/dist/sandbox/Sandbox.d.ts +25 -2
- package/dist/sandbox/index.d.ts +1 -1
- package/package.json +14 -5
- package/dist/bin/chunks/chunk-4P5OA25Z.js +0 -26
- package/dist/bin/shell/chunks/chunk-4P5OA25Z.js +0 -26
- package/dist/bundle/chunks/chunk-KY5VPZXG.js +0 -23
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as K}from"./chunk-JBABAK44.js";import{a as U,b as Z}from"./chunk-GTNBSMZR.js";var B=(n,t,e)=>{let s=n instanceof RegExp?V(n,e):n,r=t instanceof RegExp?V(t,e):t,i=s!==null&&r!=null&&$t(s,r,e);return i&&{start:i[0],end:i[1],pre:e.slice(0,i[0]),body:e.slice(i[0]+s.length,i[1]),post:e.slice(i[1]+r.length)}},V=(n,t)=>{let e=t.match(n);return e?e[0]:null},$t=(n,t,e)=>{let s,r,i,o,c,h=e.indexOf(n),u=e.indexOf(t,h+1),l=h;if(h>=0&&u>0){if(n===t)return[h,u];for(s=[],i=e.length;l>=0&&!c;){if(l===h)s.push(l),h=e.indexOf(n,l+1);else if(s.length===1){let m=s.pop();m!==void 0&&(c=[m,u])}else r=s.pop(),r!==void 0&&r<i&&(i=r,o=u),u=e.indexOf(t,l+1);l=h<u&&h>=0?h:u}s.length&&o!==void 0&&(c=[i,o])}return c};var X="\0SLASH"+Math.random()+"\0",Y="\0OPEN"+Math.random()+"\0",q="\0CLOSE"+Math.random()+"\0",Q="\0COMMA"+Math.random()+"\0",tt="\0PERIOD"+Math.random()+"\0",xt=new RegExp(X,"g"),bt=new RegExp(Y,"g"),Et=new RegExp(q,"g"),At=new RegExp(Q,"g"),Pt=new RegExp(tt,"g"),Tt=/\\\\/g,vt=/\\{/g,Mt=/\\}/g,Nt=/\\,/g,Ot=/\\./g;function _(n){return isNaN(n)?n.charCodeAt(0):parseInt(n,10)}function Ct(n){return n.replace(Tt,X).replace(vt,Y).replace(Mt,q).replace(Nt,Q).replace(Ot,tt)}function zt(n){return n.replace(xt,"\\").replace(bt,"{").replace(Et,"}").replace(At,",").replace(Pt,".")}function et(n){if(!n)return[""];let t=[],e=B("{","}",n);if(!e)return n.split(",");let{pre:s,body:r,post:i}=e,o=s.split(",");o[o.length-1]+="{"+r+"}";let c=et(i);return i.length&&(o[o.length-1]+=c.shift(),o.push.apply(o,c)),t.push.apply(t,o),t}function st(n){return n?(n.slice(0,2)==="{}"&&(n="\\{\\}"+n.slice(2)),W(Ct(n),!0).map(zt)):[]}function Dt(n){return"{"+n+"}"}function Rt(n){return/^-?0\d/.test(n)}function Wt(n,t){return n<=t}function jt(n,t){return n>=t}function W(n,t){let e=[],s=B("{","}",n);if(!s)return[n];let r=s.pre,i=s.post.length?W(s.post,!1):[""];if(/\$$/.test(s.pre))for(let o=0;o<i.length;o++){let c=r+"{"+s.body+"}"+i[o];e.push(c)}else{let o=/^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(s.body),c=/^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(s.body),h=o||c,u=s.body.indexOf(",")>=0;if(!h&&!u)return s.post.match(/,(?!,).*\}/)?(n=s.pre+"{"+s.body+q+s.post,W(n)):[n];let l;if(h)l=s.body.split(/\.\./);else if(l=et(s.body),l.length===1&&l[0]!==void 0&&(l=W(l[0],!1).map(Dt),l.length===1))return i.map(p=>s.pre+l[0]+p);let m;if(h&&l[0]!==void 0&&l[1]!==void 0){let p=_(l[0]),a=_(l[1]),d=Math.max(l[0].length,l[1].length),f=l.length===3&&l[2]!==void 0?Math.abs(_(l[2])):1,$=Wt;a<p&&(f*=-1,$=jt);let S=l.some(Rt);m=[];for(let y=p;$(y,a);y+=f){let g;if(c)g=String.fromCharCode(y),g==="\\"&&(g="");else if(g=String(y),S){let w=d-g.length;if(w>0){let b=new Array(w+1).join("0");y<0?g="-"+b+g.slice(1):g=b+g}}m.push(g)}}else{m=[];for(let p=0;p<l.length;p++)m.push.apply(m,W(l[p],!1))}for(let p=0;p<m.length;p++)for(let a=0;a<i.length;a++){let d=r+m[p]+i[a];(!t||h||d)&&e.push(d)}}return e}var j=n=>{if(typeof n!="string")throw new TypeError("invalid pattern");if(n.length>65536)throw new TypeError("pattern is too long")};var Lt={"[:alnum:]":["\\p{L}\\p{Nl}\\p{Nd}",!0],"[:alpha:]":["\\p{L}\\p{Nl}",!0],"[:ascii:]":["\\x00-\\x7f",!1],"[:blank:]":["\\p{Zs}\\t",!0],"[:cntrl:]":["\\p{Cc}",!0],"[:digit:]":["\\p{Nd}",!0],"[:graph:]":["\\p{Z}\\p{C}",!0,!0],"[:lower:]":["\\p{Ll}",!0],"[:print:]":["\\p{C}",!0],"[:punct:]":["\\p{P}",!0],"[:space:]":["\\p{Z}\\t\\r\\n\\v\\f",!0],"[:upper:]":["\\p{Lu}",!0],"[:word:]":["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}",!0],"[:xdigit:]":["A-Fa-f0-9",!1]},L=n=>n.replace(/[[\]\\-]/g,"\\$&"),kt=n=>n.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),nt=n=>n.join(""),it=(n,t)=>{let e=t;if(n.charAt(e)!=="[")throw new Error("not in a brace expression");let s=[],r=[],i=e+1,o=!1,c=!1,h=!1,u=!1,l=e,m="";t:for(;i<n.length;){let f=n.charAt(i);if((f==="!"||f==="^")&&i===e+1){u=!0,i++;continue}if(f==="]"&&o&&!h){l=i+1;break}if(o=!0,f==="\\"&&!h){h=!0,i++;continue}if(f==="["&&!h){for(let[$,[x,S,y]]of Object.entries(Lt))if(n.startsWith($,i)){if(m)return["$.",!1,n.length-e,!0];i+=$.length,y?r.push(x):s.push(x),c=c||S;continue t}}if(h=!1,m){f>m?s.push(L(m)+"-"+L(f)):f===m&&s.push(L(f)),m="",i++;continue}if(n.startsWith("-]",i+1)){s.push(L(f+"-")),i+=2;continue}if(n.startsWith("-",i+1)){m=f,i+=2;continue}s.push(L(f)),i++}if(l<i)return["",!1,0,!1];if(!s.length&&!r.length)return["$.",!1,n.length-e,!0];if(r.length===0&&s.length===1&&/^\\?.$/.test(s[0])&&!u){let f=s[0].length===2?s[0].slice(-1):s[0];return[kt(f),!1,l-e,!1]}let p="["+(u?"^":"")+nt(s)+"]",a="["+(u?"":"^")+nt(r)+"]";return[s.length&&r.length?"("+p+"|"+a+")":s.length?p:a,c,l-e,!0]};var N=(n,{windowsPathsNoEscape:t=!1,magicalBraces:e=!0}={})=>e?t?n.replace(/\[([^\/\\])\]/g,"$1"):n.replace(/((?!\\).|^)\[([^\/\\])\]/g,"$1$2").replace(/\\([^\/])/g,"$1"):t?n.replace(/\[([^\/\\{}])\]/g,"$1"):n.replace(/((?!\\).|^)\[([^\/\\{}])\]/g,"$1$2").replace(/\\([^\/{}])/g,"$1");var Ft=new Set(["!","?","+","*","@"]),rt=n=>Ft.has(n),Gt="(?!(?:^|/)\\.\\.?(?:$|/))",k="(?!\\.)",Bt=new Set(["[","."]),_t=new Set(["..","."]),qt=new Set("().*{}+?[]^$\\!"),Ht=n=>n.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),H="[^/]",ot=H+"*?",at=H+"+?",D=class n{type;#s;#n;#r=!1;#t=[];#e;#o;#l;#a=!1;#i;#c;#f=!1;constructor(t,e,s={}){this.type=t,t&&(this.#n=!0),this.#e=e,this.#s=this.#e?this.#e.#s:this,this.#i=this.#s===this?s:this.#s.#i,this.#l=this.#s===this?[]:this.#s.#l,t==="!"&&!this.#s.#a&&this.#l.push(this),this.#o=this.#e?this.#e.#t.length:0}get hasMagic(){if(this.#n!==void 0)return this.#n;for(let t of this.#t)if(typeof t!="string"&&(t.type||t.hasMagic))return this.#n=!0;return this.#n}toString(){return this.#c!==void 0?this.#c:this.type?this.#c=this.type+"("+this.#t.map(t=>String(t)).join("|")+")":this.#c=this.#t.map(t=>String(t)).join("")}#p(){if(this!==this.#s)throw new Error("should only call on root");if(this.#a)return this;this.toString(),this.#a=!0;let t;for(;t=this.#l.pop();){if(t.type!=="!")continue;let e=t,s=e.#e;for(;s;){for(let r=e.#o+1;!s.type&&r<s.#t.length;r++)for(let i of t.#t){if(typeof i=="string")throw new Error("string part in extglob AST??");i.copyIn(s.#t[r])}e=s,s=e.#e}}return this}push(...t){for(let e of t)if(e!==""){if(typeof e!="string"&&!(e instanceof n&&e.#e===this))throw new Error("invalid part: "+e);this.#t.push(e)}}toJSON(){let t=this.type===null?this.#t.slice().map(e=>typeof e=="string"?e:e.toJSON()):[this.type,...this.#t.map(e=>e.toJSON())];return this.isStart()&&!this.type&&t.unshift([]),this.isEnd()&&(this===this.#s||this.#s.#a&&this.#e?.type==="!")&&t.push({}),t}isStart(){if(this.#s===this)return!0;if(!this.#e?.isStart())return!1;if(this.#o===0)return!0;let t=this.#e;for(let e=0;e<this.#o;e++){let s=t.#t[e];if(!(s instanceof n&&s.type==="!"))return!1}return!0}isEnd(){if(this.#s===this||this.#e?.type==="!")return!0;if(!this.#e?.isEnd())return!1;if(!this.type)return this.#e?.isEnd();let t=this.#e?this.#e.#t.length:0;return this.#o===t-1}copyIn(t){typeof t=="string"?this.push(t):this.push(t.clone(this))}clone(t){let e=new n(this.type,t);for(let s of this.#t)e.copyIn(s);return e}static#h(t,e,s,r){let i=!1,o=!1,c=-1,h=!1;if(e.type===null){let a=s,d="";for(;a<t.length;){let f=t.charAt(a++);if(i||f==="\\"){i=!i,d+=f;continue}if(o){a===c+1?(f==="^"||f==="!")&&(h=!0):f==="]"&&!(a===c+2&&h)&&(o=!1),d+=f;continue}else if(f==="["){o=!0,c=a,h=!1,d+=f;continue}if(!r.noext&&rt(f)&&t.charAt(a)==="("){e.push(d),d="";let $=new n(f,e);a=n.#h(t,$,a,r),e.push($);continue}d+=f}return e.push(d),a}let u=s+1,l=new n(null,e),m=[],p="";for(;u<t.length;){let a=t.charAt(u++);if(i||a==="\\"){i=!i,p+=a;continue}if(o){u===c+1?(a==="^"||a==="!")&&(h=!0):a==="]"&&!(u===c+2&&h)&&(o=!1),p+=a;continue}else if(a==="["){o=!0,c=u,h=!1,p+=a;continue}if(rt(a)&&t.charAt(u)==="("){l.push(p),p="";let d=new n(a,l);l.push(d),u=n.#h(t,d,u,r);continue}if(a==="|"){l.push(p),p="",m.push(l),l=new n(null,e);continue}if(a===")")return p===""&&e.#t.length===0&&(e.#f=!0),l.push(p),p="",e.push(...m,l),u;p+=a}return e.type=null,e.#n=void 0,e.#t=[t.substring(s-1)],u}static fromGlob(t,e={}){let s=new n(null,void 0,e);return n.#h(t,s,0,e),s}toMMPattern(){if(this!==this.#s)return this.#s.toMMPattern();let t=this.toString(),[e,s,r,i]=this.toRegExpSource();if(!(r||this.#n||this.#i.nocase&&!this.#i.nocaseMagicOnly&&t.toUpperCase()!==t.toLowerCase()))return s;let c=(this.#i.nocase?"i":"")+(i?"u":"");return Object.assign(new RegExp(`^${e}$`,c),{_src:e,_glob:t})}get options(){return this.#i}toRegExpSource(t){let e=t??!!this.#i.dot;if(this.#s===this&&this.#p(),!this.type){let h=this.isStart()&&this.isEnd()&&!this.#t.some(a=>typeof a!="string"),u=this.#t.map(a=>{let[d,f,$,x]=typeof a=="string"?n.#d(a,this.#n,h):a.toRegExpSource(t);return this.#n=this.#n||$,this.#r=this.#r||x,d}).join(""),l="";if(this.isStart()&&typeof this.#t[0]=="string"&&!(this.#t.length===1&&_t.has(this.#t[0]))){let d=Bt,f=e&&d.has(u.charAt(0))||u.startsWith("\\.")&&d.has(u.charAt(2))||u.startsWith("\\.\\.")&&d.has(u.charAt(4)),$=!e&&!t&&d.has(u.charAt(0));l=f?Gt:$?k:""}let m="";return this.isEnd()&&this.#s.#a&&this.#e?.type==="!"&&(m="(?:$|\\/)"),[l+u+m,N(u),this.#n=!!this.#n,this.#r]}let s=this.type==="*"||this.type==="+",r=this.type==="!"?"(?:(?!(?:":"(?:",i=this.#u(e);if(this.isStart()&&this.isEnd()&&!i&&this.type!=="!"){let h=this.toString();return this.#t=[h],this.type=null,this.#n=void 0,[h,N(this.toString()),!1,!1]}let o=!s||t||e||!k?"":this.#u(!0);o===i&&(o=""),o&&(i=`(?:${i})(?:${o})*?`);let c="";if(this.type==="!"&&this.#f)c=(this.isStart()&&!e?k:"")+at;else{let h=this.type==="!"?"))"+(this.isStart()&&!e&&!t?k:"")+ot+")":this.type==="@"?")":this.type==="?"?")?":this.type==="+"&&o?")":this.type==="*"&&o?")?":`)${this.type}`;c=r+i+h}return[c,N(i),this.#n=!!this.#n,this.#r]}#u(t){return this.#t.map(e=>{if(typeof e=="string")throw new Error("string type in extglob ast??");let[s,r,i,o]=e.toRegExpSource(t);return this.#r=this.#r||o,s}).filter(e=>!(this.isStart()&&this.isEnd())||!!e).join("|")}static#d(t,e,s=!1){let r=!1,i="",o=!1;for(let c=0;c<t.length;c++){let h=t.charAt(c);if(r){r=!1,i+=(qt.has(h)?"\\":"")+h;continue}if(h==="\\"){c===t.length-1?i+="\\\\":r=!0;continue}if(h==="["){let[u,l,m,p]=it(t,c);if(m){i+=u,o=o||l,c+=m-1,e=e||p;continue}}if(h==="*"){i+=s&&t==="*"?at:ot,e=!0;continue}if(h==="?"){i+=H,e=!0;continue}i+=Ht(h)}return[i,N(t),!!e,o]}};var I=(n,{windowsPathsNoEscape:t=!1,magicalBraces:e=!1}={})=>e?t?n.replace(/[?*()[\]{}]/g,"[$&]"):n.replace(/[?*()[\]\\{}]/g,"\\$&"):t?n.replace(/[?*()[\]]/g,"[$&]"):n.replace(/[?*()[\]\\]/g,"\\$&");var A=(n,t,e={})=>(j(t),!e.nocomment&&t.charAt(0)==="#"?!1:new R(t,e).match(n)),It=/^\*+([^+@!?\*\[\(]*)$/,Jt=n=>t=>!t.startsWith(".")&&t.endsWith(n),Ut=n=>t=>t.endsWith(n),Zt=n=>(n=n.toLowerCase(),t=>!t.startsWith(".")&&t.toLowerCase().endsWith(n)),Kt=n=>(n=n.toLowerCase(),t=>t.toLowerCase().endsWith(n)),Vt=/^\*+\.\*+$/,Xt=n=>!n.startsWith(".")&&n.includes("."),Yt=n=>n!=="."&&n!==".."&&n.includes("."),Qt=/^\.\*+$/,te=n=>n!=="."&&n!==".."&&n.startsWith("."),ee=/^\*+$/,se=n=>n.length!==0&&!n.startsWith("."),ne=n=>n.length!==0&&n!=="."&&n!=="..",ie=/^\?+([^+@!?\*\[\(]*)?$/,re=([n,t=""])=>{let e=ht([n]);return t?(t=t.toLowerCase(),s=>e(s)&&s.toLowerCase().endsWith(t)):e},oe=([n,t=""])=>{let e=ft([n]);return t?(t=t.toLowerCase(),s=>e(s)&&s.toLowerCase().endsWith(t)):e},ae=([n,t=""])=>{let e=ft([n]);return t?s=>e(s)&&s.endsWith(t):e},le=([n,t=""])=>{let e=ht([n]);return t?s=>e(s)&&s.endsWith(t):e},ht=([n])=>{let t=n.length;return e=>e.length===t&&!e.startsWith(".")},ft=([n])=>{let t=n.length;return e=>e.length===t&&e!=="."&&e!==".."},ut=typeof process=="object"&&process?typeof process.env=="object"&&process.env&&process.env.__MINIMATCH_TESTING_PLATFORM__||process.platform:"posix",lt={win32:{sep:"\\"},posix:{sep:"/"}},ce=ut==="win32"?lt.win32.sep:lt.posix.sep;A.sep=ce;var v=Symbol("globstar **");A.GLOBSTAR=v;var he="[^/]",fe=he+"*?",ue="(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?",pe="(?:(?!(?:\\/|^)\\.).)*?",de=(n,t={})=>e=>A(e,n,t);A.filter=de;var T=(n,t={})=>Object.assign({},n,t),ge=n=>{if(!n||typeof n!="object"||!Object.keys(n).length)return A;let t=A;return Object.assign((s,r,i={})=>t(s,r,T(n,i)),{Minimatch:class extends t.Minimatch{constructor(r,i={}){super(r,T(n,i))}static defaults(r){return t.defaults(T(n,r)).Minimatch}},AST:class extends t.AST{constructor(r,i,o={}){super(r,i,T(n,o))}static fromGlob(r,i={}){return t.AST.fromGlob(r,T(n,i))}},unescape:(s,r={})=>t.unescape(s,T(n,r)),escape:(s,r={})=>t.escape(s,T(n,r)),filter:(s,r={})=>t.filter(s,T(n,r)),defaults:s=>t.defaults(T(n,s)),makeRe:(s,r={})=>t.makeRe(s,T(n,r)),braceExpand:(s,r={})=>t.braceExpand(s,T(n,r)),match:(s,r,i={})=>t.match(s,r,T(n,i)),sep:t.sep,GLOBSTAR:v})};A.defaults=ge;var pt=(n,t={})=>(j(n),t.nobrace||!/\{(?:(?!\{).)*\}/.test(n)?[n]:st(n));A.braceExpand=pt;var me=(n,t={})=>new R(n,t).makeRe();A.makeRe=me;var ye=(n,t,e={})=>{let s=new R(t,e);return n=n.filter(r=>s.match(r)),s.options.nonull&&!n.length&&n.push(t),n};A.match=ye;var ct=/[?*]|[+@!]\(.*?\)|\[|\]/,we=n=>n.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),R=class{options;set;pattern;windowsPathsNoEscape;nonegate;negate;comment;empty;preserveMultipleSlashes;partial;globSet;globParts;nocase;isWindows;platform;windowsNoMagicRoot;regexp;constructor(t,e={}){j(t),e=e||{},this.options=e,this.pattern=t,this.platform=e.platform||ut,this.isWindows=this.platform==="win32",this.windowsPathsNoEscape=!!e.windowsPathsNoEscape||e.allowWindowsEscape===!1,this.windowsPathsNoEscape&&(this.pattern=this.pattern.replace(/\\/g,"/")),this.preserveMultipleSlashes=!!e.preserveMultipleSlashes,this.regexp=null,this.negate=!1,this.nonegate=!!e.nonegate,this.comment=!1,this.empty=!1,this.partial=!!e.partial,this.nocase=!!this.options.nocase,this.windowsNoMagicRoot=e.windowsNoMagicRoot!==void 0?e.windowsNoMagicRoot:!!(this.isWindows&&this.nocase),this.globSet=[],this.globParts=[],this.set=[],this.make()}hasMagic(){if(this.options.magicalBraces&&this.set.length>1)return!0;for(let t of this.set)for(let e of t)if(typeof e!="string")return!0;return!1}debug(...t){}make(){let t=this.pattern,e=this.options;if(!e.nocomment&&t.charAt(0)==="#"){this.comment=!0;return}if(!t){this.empty=!0;return}this.parseNegate(),this.globSet=[...new Set(this.braceExpand())],e.debug&&(this.debug=(...i)=>console.error(...i)),this.debug(this.pattern,this.globSet);let s=this.globSet.map(i=>this.slashSplit(i));this.globParts=this.preprocess(s),this.debug(this.pattern,this.globParts);let r=this.globParts.map((i,o,c)=>{if(this.isWindows&&this.windowsNoMagicRoot){let h=i[0]===""&&i[1]===""&&(i[2]==="?"||!ct.test(i[2]))&&!ct.test(i[3]),u=/^[a-z]:/i.test(i[0]);if(h)return[...i.slice(0,4),...i.slice(4).map(l=>this.parse(l))];if(u)return[i[0],...i.slice(1).map(l=>this.parse(l))]}return i.map(h=>this.parse(h))});if(this.debug(this.pattern,r),this.set=r.filter(i=>i.indexOf(!1)===-1),this.isWindows)for(let i=0;i<this.set.length;i++){let o=this.set[i];o[0]===""&&o[1]===""&&this.globParts[i][2]==="?"&&typeof o[3]=="string"&&/^[a-z]:$/i.test(o[3])&&(o[2]="?")}this.debug(this.pattern,this.set)}preprocess(t){if(this.options.noglobstar)for(let s=0;s<t.length;s++)for(let r=0;r<t[s].length;r++)t[s][r]==="**"&&(t[s][r]="*");let{optimizationLevel:e=1}=this.options;return e>=2?(t=this.firstPhasePreProcess(t),t=this.secondPhasePreProcess(t)):e>=1?t=this.levelOneOptimize(t):t=this.adjascentGlobstarOptimize(t),t}adjascentGlobstarOptimize(t){return t.map(e=>{let s=-1;for(;(s=e.indexOf("**",s+1))!==-1;){let r=s;for(;e[r+1]==="**";)r++;r!==s&&e.splice(s,r-s)}return e})}levelOneOptimize(t){return t.map(e=>(e=e.reduce((s,r)=>{let i=s[s.length-1];return r==="**"&&i==="**"?s:r===".."&&i&&i!==".."&&i!=="."&&i!=="**"?(s.pop(),s):(s.push(r),s)},[]),e.length===0?[""]:e))}levelTwoFileOptimize(t){Array.isArray(t)||(t=this.slashSplit(t));let e=!1;do{if(e=!1,!this.preserveMultipleSlashes){for(let r=1;r<t.length-1;r++){let i=t[r];r===1&&i===""&&t[0]===""||(i==="."||i==="")&&(e=!0,t.splice(r,1),r--)}t[0]==="."&&t.length===2&&(t[1]==="."||t[1]==="")&&(e=!0,t.pop())}let s=0;for(;(s=t.indexOf("..",s+1))!==-1;){let r=t[s-1];r&&r!=="."&&r!==".."&&r!=="**"&&(e=!0,t.splice(s-1,2),s-=2)}}while(e);return t.length===0?[""]:t}firstPhasePreProcess(t){let e=!1;do{e=!1;for(let s of t){let r=-1;for(;(r=s.indexOf("**",r+1))!==-1;){let o=r;for(;s[o+1]==="**";)o++;o>r&&s.splice(r+1,o-r);let c=s[r+1],h=s[r+2],u=s[r+3];if(c!==".."||!h||h==="."||h===".."||!u||u==="."||u==="..")continue;e=!0,s.splice(r,1);let l=s.slice(0);l[r]="**",t.push(l),r--}if(!this.preserveMultipleSlashes){for(let o=1;o<s.length-1;o++){let c=s[o];o===1&&c===""&&s[0]===""||(c==="."||c==="")&&(e=!0,s.splice(o,1),o--)}s[0]==="."&&s.length===2&&(s[1]==="."||s[1]==="")&&(e=!0,s.pop())}let i=0;for(;(i=s.indexOf("..",i+1))!==-1;){let o=s[i-1];if(o&&o!=="."&&o!==".."&&o!=="**"){e=!0;let h=i===1&&s[i+1]==="**"?["."]:[];s.splice(i-1,2,...h),s.length===0&&s.push(""),i-=2}}}}while(e);return t}secondPhasePreProcess(t){for(let e=0;e<t.length-1;e++)for(let s=e+1;s<t.length;s++){let r=this.partsMatch(t[e],t[s],!this.preserveMultipleSlashes);if(r){t[e]=[],t[s]=r;break}}return t.filter(e=>e.length)}partsMatch(t,e,s=!1){let r=0,i=0,o=[],c="";for(;r<t.length&&i<e.length;)if(t[r]===e[i])o.push(c==="b"?e[i]:t[r]),r++,i++;else if(s&&t[r]==="**"&&e[i]===t[r+1])o.push(t[r]),r++;else if(s&&e[i]==="**"&&t[r]===e[i+1])o.push(e[i]),i++;else if(t[r]==="*"&&e[i]&&(this.options.dot||!e[i].startsWith("."))&&e[i]!=="**"){if(c==="b")return!1;c="a",o.push(t[r]),r++,i++}else if(e[i]==="*"&&t[r]&&(this.options.dot||!t[r].startsWith("."))&&t[r]!=="**"){if(c==="a")return!1;c="b",o.push(e[i]),r++,i++}else return!1;return t.length===e.length&&o}parseNegate(){if(this.nonegate)return;let t=this.pattern,e=!1,s=0;for(let r=0;r<t.length&&t.charAt(r)==="!";r++)e=!e,s++;s&&(this.pattern=t.slice(s)),this.negate=e}matchOne(t,e,s=!1){let r=this.options;if(this.isWindows){let f=typeof t[0]=="string"&&/^[a-z]:$/i.test(t[0]),$=!f&&t[0]===""&&t[1]===""&&t[2]==="?"&&/^[a-z]:$/i.test(t[3]),x=typeof e[0]=="string"&&/^[a-z]:$/i.test(e[0]),S=!x&&e[0]===""&&e[1]===""&&e[2]==="?"&&typeof e[3]=="string"&&/^[a-z]:$/i.test(e[3]),y=$?3:f?0:void 0,g=S?3:x?0:void 0;if(typeof y=="number"&&typeof g=="number"){let[w,b]=[t[y],e[g]];w.toLowerCase()===b.toLowerCase()&&(e[g]=w,g>y?e=e.slice(g):y>g&&(t=t.slice(y)))}}let{optimizationLevel:i=1}=this.options;i>=2&&(t=this.levelTwoFileOptimize(t)),this.debug("matchOne",this,{file:t,pattern:e}),this.debug("matchOne",t.length,e.length);for(var o=0,c=0,h=t.length,u=e.length;o<h&&c<u;o++,c++){this.debug("matchOne loop");var l=e[c],m=t[o];if(this.debug(e,l,m),l===!1)return!1;if(l===v){this.debug("GLOBSTAR",[e,l,m]);var p=o,a=c+1;if(a===u){for(this.debug("** at the end");o<h;o++)if(t[o]==="."||t[o]===".."||!r.dot&&t[o].charAt(0)===".")return!1;return!0}for(;p<h;){var d=t[p];if(this.debug(`
|
|
3
|
+
globstar while`,t,p,e,a,d),this.matchOne(t.slice(p),e.slice(a),s))return this.debug("globstar found match!",p,h,d),!0;if(d==="."||d===".."||!r.dot&&d.charAt(0)==="."){this.debug("dot detected!",t,p,e,a);break}this.debug("globstar swallow a segment, and continue"),p++}return!!(s&&(this.debug(`
|
|
4
|
+
>>> no match, partial?`,t,p,e,a),p===h))}let f;if(typeof l=="string"?(f=m===l,this.debug("string match",l,m,f)):(f=l.test(m),this.debug("pattern match",l,m,f)),!f)return!1}if(o===h&&c===u)return!0;if(o===h)return s;if(c===u)return o===h-1&&t[o]==="";throw new Error("wtf?")}braceExpand(){return pt(this.pattern,this.options)}parse(t){j(t);let e=this.options;if(t==="**")return v;if(t==="")return"";let s,r=null;(s=t.match(ee))?r=e.dot?ne:se:(s=t.match(It))?r=(e.nocase?e.dot?Kt:Zt:e.dot?Ut:Jt)(s[1]):(s=t.match(ie))?r=(e.nocase?e.dot?oe:re:e.dot?ae:le)(s):(s=t.match(Vt))?r=e.dot?Yt:Xt:(s=t.match(Qt))&&(r=te);let i=D.fromGlob(t,this.options).toMMPattern();return r&&typeof i=="object"&&Reflect.defineProperty(i,"test",{value:r}),i}makeRe(){if(this.regexp||this.regexp===!1)return this.regexp;let t=this.set;if(!t.length)return this.regexp=!1,this.regexp;let e=this.options,s=e.noglobstar?fe:e.dot?ue:pe,r=new Set(e.nocase?["i"]:[]),i=t.map(h=>{let u=h.map(m=>{if(m instanceof RegExp)for(let p of m.flags.split(""))r.add(p);return typeof m=="string"?we(m):m===v?v:m._src});u.forEach((m,p)=>{let a=u[p+1],d=u[p-1];m!==v||d===v||(d===void 0?a!==void 0&&a!==v?u[p+1]="(?:\\/|"+s+"\\/)?"+a:u[p]=s:a===void 0?u[p-1]=d+"(?:\\/|\\/"+s+")?":a!==v&&(u[p-1]=d+"(?:\\/|\\/"+s+"\\/)"+a,u[p+1]=v))});let l=u.filter(m=>m!==v);if(this.partial&&l.length>=1){let m=[];for(let p=1;p<=l.length;p++)m.push(l.slice(0,p).join("/"));return"(?:"+m.join("|")+")"}return l.join("/")}).join("|"),[o,c]=t.length>1?["(?:",")"]:["",""];i="^"+o+i+c+"$",this.partial&&(i="^(?:\\/|"+o+i.slice(1,-1)+c+")$"),this.negate&&(i="^(?!"+i+").+$");try{this.regexp=new RegExp(i,[...r].join(""))}catch{this.regexp=!1}return this.regexp}slashSplit(t){return this.preserveMultipleSlashes?t.split("/"):this.isWindows&&/^\/\/[^\/]+/.test(t)?["",...t.split(/\/+/)]:t.split(/\/+/)}match(t,e=this.partial){if(this.debug("match",t,this.pattern),this.comment)return!1;if(this.empty)return t==="";if(t==="/"&&e)return!0;let s=this.options;this.isWindows&&(t=t.split("\\").join("/"));let r=this.slashSplit(t);this.debug(this.pattern,"split",r);let i=this.set;this.debug(this.pattern,"set",i);let o=r[r.length-1];if(!o)for(let c=r.length-2;!o&&c>=0;c--)o=r[c];for(let c=0;c<i.length;c++){let h=i[c],u=r;if(s.matchBase&&h.length===1&&(u=[o]),this.matchOne(u,h,e))return s.flipNegate?!0:!this.negate}return s.flipNegate?!1:this.negate}static defaults(t){return A.defaults(t).Minimatch}};A.AST=D;A.Minimatch=R;A.escape=I;A.unescape=N;function F(n){if(n<1024)return String(n);if(n<1024*1024){let e=n/1024;return e<10?`${e.toFixed(1)}K`:`${Math.round(e)}K`}if(n<1024*1024*1024){let e=n/1048576;return e<10?`${e.toFixed(1)}M`:`${Math.round(e)}M`}let t=n/(1024*1024*1024);return t<10?`${t.toFixed(1)}G`:`${Math.round(t)}G`}function G(n){let e=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][n.getMonth()],s=String(n.getDate()).padStart(2," "),r=new Date,i=new Date(r.getTime()-4320*60*60*1e3);if(n>i){let c=String(n.getHours()).padStart(2,"0"),h=String(n.getMinutes()).padStart(2,"0");return`${e} ${s} ${c}:${h}`}let o=n.getFullYear();return`${e} ${s} ${o}`}function C(n){return n.isDirectory?"/":n.isSymbolicLink?"@":(n.mode&73)!==0?"*":""}var Se={name:"ls",summary:"list directory contents",usage:"ls [OPTION]... [FILE]...",options:["-a, --all do not ignore entries starting with .","-A, --almost-all do not list . and ..","-d, --directory list directories themselves, not their contents","-F, --classify append indicator (one of */=>@) to entries","-h, --human-readable with -l, print sizes like 1K 234M 2G etc.","-l use a long listing format","-r, --reverse reverse order while sorting","-R, --recursive list subdirectories recursively","-S sort by file size, largest first","-t sort by time, newest first","-1 list one file per line"," --help display this help and exit"]},$e={showAll:{short:"a",long:"all",type:"boolean"},showAlmostAll:{short:"A",long:"almost-all",type:"boolean"},longFormat:{short:"l",type:"boolean"},humanReadable:{short:"h",long:"human-readable",type:"boolean"},recursive:{short:"R",long:"recursive",type:"boolean"},reverse:{short:"r",long:"reverse",type:"boolean"},sortBySize:{short:"S",type:"boolean"},classifyFiles:{short:"F",long:"classify",type:"boolean"},directoryOnly:{short:"d",long:"directory",type:"boolean"},sortByTime:{short:"t",type:"boolean"},onePerLine:{short:"1",type:"boolean"}},Ue={name:"ls",async execute(n,t){if(Z(n))return U(Se);let e=K("ls",n,$e);if(!e.ok)return e.error;let s=e.result.flags.showAll,r=e.result.flags.showAlmostAll,i=e.result.flags.longFormat,o=e.result.flags.humanReadable,c=e.result.flags.recursive,h=e.result.flags.reverse,u=e.result.flags.sortBySize,l=e.result.flags.classifyFiles,m=e.result.flags.directoryOnly,p=e.result.flags.sortByTime;e.result.flags.onePerLine;let a=e.result.positional;a.length===0&&a.push(".");let d="",f="",$=0;for(let x=0;x<a.length;x++){let S=a[x];if(x>0&&d&&!d.endsWith(`
|
|
5
|
+
|
|
6
|
+
`)&&(d+=`
|
|
7
|
+
`),m){let y=t.fs.resolvePath(t.cwd,S);try{let g=await t.fs.stat(y);if(i){let w=g.isDirectory?"drwxr-xr-x":"-rw-r--r--",b=l?C(await t.fs.lstat(y)):g.isDirectory?"/":"",E=g.size??0,P=o?F(E).padStart(5):String(E).padStart(5),M=g.mtime??new Date(0),z=G(M);d+=`${w} 1 user user ${P} ${z} ${S}${b}
|
|
8
|
+
`}else{let w=l?C(await t.fs.lstat(y)):"";d+=`${S}${w}
|
|
9
|
+
`}}catch{f+=`ls: cannot access '${S}': No such file or directory
|
|
10
|
+
`,$=2}continue}if(S.includes("*")||S.includes("?")||S.includes("[")){let y=await xe(S,t,s,r,i,h,o,u,l);d+=y.stdout,f+=y.stderr,y.exitCode!==0&&($=y.exitCode)}else{let y=await dt(S,t,s,r,i,c,a.length>1,h,o,u,l);d+=y.stdout,f+=y.stderr,y.exitCode!==0&&($=y.exitCode)}}return{stdout:d,stderr:f,exitCode:$}}};async function xe(n,t,e,s,r,i=!1,o=!1,c=!1,h=!1){let u=e||s,l=t.fs.getAllPaths(),m=t.fs.resolvePath(t.cwd,"."),p=[];for(let a of l){let d=a.startsWith(m)&&a.slice(m.length+1)||a;if(A(d,n)||A(a,n)){let f=d.split("/").pop()||d;if(!u&&f.startsWith("."))continue;p.push(d||a)}}if(p.length===0)return{stdout:"",stderr:`ls: ${n}: No such file or directory
|
|
11
|
+
`,exitCode:2};if(c){let a=[];for(let d of p){let f=t.fs.resolvePath(t.cwd,d);try{let $=await t.fs.stat(f);a.push({path:d,size:$.size??0})}catch{a.push({path:d,size:0})}}a.sort((d,f)=>f.size-d.size),p.length=0,p.push(...a.map(d=>d.path))}else p.sort();if(i&&p.reverse(),r){let a=[];for(let d of p){let f=t.fs.resolvePath(t.cwd,d);try{let $=await t.fs.stat(f),x=$.isDirectory?"drwxr-xr-x":"-rw-r--r--",S=h?C(await t.fs.lstat(f)):$.isDirectory?"/":"",y=$.size??0,g=o?F(y).padStart(5):String(y).padStart(5),w=$.mtime??new Date(0),b=G(w);a.push(`${x} 1 user user ${g} ${b} ${d}${S}`)}catch{a.push(`-rw-r--r-- 1 user user 0 Jan 1 00:00 ${d}`)}}return{stdout:`${a.join(`
|
|
12
|
+
`)}
|
|
13
|
+
`,stderr:"",exitCode:0}}if(h){let a=[];for(let d of p){let f=t.fs.resolvePath(t.cwd,d);try{let $=await t.fs.lstat(f);a.push(`${d}${C($)}`)}catch{a.push(d)}}return{stdout:`${a.join(`
|
|
14
|
+
`)}
|
|
15
|
+
`,stderr:"",exitCode:0}}return{stdout:`${p.join(`
|
|
16
|
+
`)}
|
|
17
|
+
`,stderr:"",exitCode:0}}async function dt(n,t,e,s,r,i,o,c=!1,h=!1,u=!1,l=!1,m=!1){let p=e||s,a=t.fs.resolvePath(t.cwd,n);try{let d=await t.fs.stat(a);if(!d.isDirectory){let x=l?C(await t.fs.lstat(a)):"";if(r){let S=d.size??0,y=h?F(S).padStart(5):String(S).padStart(5),g=d.mtime??new Date(0),w=G(g);return{stdout:`-rw-r--r-- 1 user user ${y} ${w} ${n}${x}
|
|
18
|
+
`,stderr:"",exitCode:0}}return{stdout:`${n}${x}
|
|
19
|
+
`,stderr:"",exitCode:0}}let f=await t.fs.readdir(a);if(p||(f=f.filter(x=>!x.startsWith("."))),u){let x=[];for(let S of f){let y=a==="/"?`/${S}`:`${a}/${S}`;try{let g=await t.fs.stat(y);x.push({name:S,size:g.size??0})}catch{x.push({name:S,size:0})}}x.sort((S,y)=>y.size-S.size),f=x.map(S=>S.name)}else f.sort();e&&(f=[".","..",...f]),c&&f.reverse();let $="";if((i||o)&&($+=`${n}:
|
|
20
|
+
`),r){$+=`total ${f.length}
|
|
21
|
+
`;let x=f.filter(w=>w==="."||w===".."),S=f.filter(w=>w!=="."&&w!=="..");for(let w of x)$+=`drwxr-xr-x 1 user user 0 Jan 1 00:00 ${w}
|
|
22
|
+
`;let y=[];for(let w=0;w<S.length;w+=100){let b=S.slice(w,w+100),E=await Promise.all(b.map(async P=>{let M=a==="/"?`/${P}`:`${a}/${P}`;try{let z=await t.fs.stat(M),gt=z.isDirectory?"drwxr-xr-x":"-rw-r--r--",mt=l?C(await t.fs.lstat(M)):z.isDirectory?"/":"",J=z.size??0,yt=h?F(J).padStart(5):String(J).padStart(5),wt=z.mtime??new Date(0),St=G(wt);return{name:P,line:`${gt} 1 user user ${yt} ${St} ${P}${mt}
|
|
23
|
+
`}}catch{return{name:P,line:`-rw-r--r-- 1 user user 0 Jan 1 00:00 ${P}
|
|
24
|
+
`}}}));y.push(...E)}let g=new Map(S.map((w,b)=>[w,b]));y.sort((w,b)=>(g.get(w.name)??0)-(g.get(b.name)??0));for(let{line:w}of y)$+=w}else if(l){let x=[],S=f.filter(g=>g!=="."&&g!==".."),y=f.filter(g=>g==="."||g==="..");for(let g of y)x.push(`${g}/`);for(let g=0;g<S.length;g+=100){let w=S.slice(g,g+100),b=await Promise.all(w.map(async E=>{let P=a==="/"?`/${E}`:`${a}/${E}`;try{let M=await t.fs.lstat(P);return`${E}${C(M)}`}catch{return E}}));x.push(...b)}$+=x.join(`
|
|
25
|
+
`)+(x.length?`
|
|
26
|
+
`:"")}else $+=f.join(`
|
|
27
|
+
`)+(f.length?`
|
|
28
|
+
`:"");if(i){let x=f.filter(g=>g!=="."&&g!==".."),S=[];if(t.fs.readdirWithFileTypes)S=(await t.fs.readdirWithFileTypes(a)).filter(w=>w.isDirectory&&x.includes(w.name)).map(w=>({name:w.name,isDirectory:!0}));else for(let g=0;g<x.length;g+=100){let w=x.slice(g,g+100),b=await Promise.all(w.map(async E=>{let P=a==="/"?`/${E}`:`${a}/${E}`;try{let M=await t.fs.stat(P);return{name:E,isDirectory:M.isDirectory}}catch{return{name:E,isDirectory:!1}}}));S.push(...b.filter(E=>E.isDirectory))}S.sort((g,w)=>g.name.localeCompare(w.name)),c&&S.reverse();let y=[];for(let g=0;g<S.length;g+=100){let w=S.slice(g,g+100),b=await Promise.all(w.map(async E=>{let P=n==="."?`./${E.name}`:`${n}/${E.name}`,M=await dt(P,t,e,s,r,i,!1,c,h,u,l,!0);return{name:E.name,result:M}}));y.push(...b)}y.sort((g,w)=>g.name.localeCompare(w.name)),c&&y.reverse();for(let{result:g}of y)$+=`
|
|
29
|
+
`,$+=g.stdout}return{stdout:$,stderr:"",exitCode:0}}catch{return{stdout:"",stderr:`ls: ${n}: No such file or directory
|
|
30
|
+
`,exitCode:2}}}var Ze={name:"ls",flags:[{flag:"-a",type:"boolean"},{flag:"-A",type:"boolean"},{flag:"-l",type:"boolean"},{flag:"-h",type:"boolean"},{flag:"-R",type:"boolean"},{flag:"-r",type:"boolean"},{flag:"-S",type:"boolean"},{flag:"-F",type:"boolean"},{flag:"-d",type:"boolean"},{flag:"-t",type:"boolean"},{flag:"-1",type:"boolean"}],needsFiles:!0};export{Ue as a,Ze as b};
|
package/dist/bin/{shell/chunks/flag-coverage-23SVOOPG.js → chunks/flag-coverage-CVSXSL4T.js}
RENAMED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{b as yr}from"./chunk-EFX3F2HZ.js";import{b as Ar}from"./chunk-CHB75QIN.js";import{b as $r}from"./chunk-MNNOATCV.js";import"./chunk-GZHFXDDO.js";import"./chunk-QSDVMMYI.js";import{b as Sr}from"./chunk-PDVXLMUU.js";import{b as wr}from"./chunk-XKPFI566.js";import{b as xr}from"./chunk-KLMOJKL4.js";import{b as vr}from"./chunk-TIDZOIPX.js";import{b as kr}from"./chunk-6VUEI2GS.js";import{b as qr}from"./chunk-BYDV4VEF.js";import{b as Cr}from"./chunk-JLX6YWGA.js";import{b as br}from"./chunk-FLPVVSN5.js";import{d as Ir,e as Mr,f as jr}from"./chunk-DAGNL3F2.js";import{b as tr}from"./chunk-P7UCWJ33.js";import{b as lr}from"./chunk-N73TVRMN.js";import{b as ur}from"./chunk-THALLNXT.js";import{b as pr}from"./chunk-2SIXTZCJ.js";import{b as er}from"./chunk-3Y32LPNT.js";import{b as dr}from"./chunk-7BORMNPQ.js";import{b as cr}from"./chunk-N43DJTSI.js";import"./chunk-OBI37ZY4.js";import{b as hr}from"./chunk-N5OTVT4F.js";import{c as or,d as ar}from"./chunk-MAVV76T4.js";import{b as sr}from"./chunk-JTF74J6E.js";import{c as ir,d as gr}from"./chunk-RDZMRK5M.js";import{b as mr}from"./chunk-QEBPVWVB.js";import"./chunk-A4442AOC.js";import"./chunk-UYBH3FNE.js";import{b as Fr}from"./chunk-BARKRZDC.js";import{b as zr}from"./chunk-P6GNZPVW.js";import{b as fr}from"./chunk-LOJMXC4F.js";import{b as nr}from"./chunk-NFZDITRV.js";import{b as R}from"./chunk-PQNTKMH3.js";import{b as U}from"./chunk-PPBQJBC2.js";import{b as V}from"./chunk-NSUMEERA.js";import{b as W}from"./chunk-4PS5JJDT.js";import{c as X,d as Y}from"./chunk-W2FKF3MM.js";import{c as Z,d as _}from"./chunk-3MBAUIBB.js";import{b as N}from"./chunk-RT7TRQVZ.js";import{b as rr}from"./chunk-JXC25GVQ.js";import{b as G}from"./chunk-RJSAGJQJ.js";import{b as H}from"./chunk-YEKSVVRC.js";import{b as J}from"./chunk-26NO42TF.js";import{b as K}from"./chunk-QXB5WI2V.js";import{b as L}from"./chunk-LMK6G2HH.js";import{b as O}from"./chunk-ZKC5HQYO.js";import{b as P}from"./chunk-ROJPSS6N.js";import{b as Q}from"./chunk-7ECKLAVW.js";import{b as y}from"./chunk-NEQEZ32M.js";import{b as A}from"./chunk-ZA4HUKJ3.js";import{b as $}from"./chunk-5U7Q4GUC.js";import{b as S}from"./chunk-JQBC3FXE.js";import{b as T}from"./chunk-BDSRLH5T.js";import{b as B}from"./chunk-5G2VOPPJ.js";import{b as D}from"./chunk-SGA7Y45Z.js";import{b as E}from"./chunk-EUXCM6C4.js";import{b as w}from"./chunk-YLE2OYY6.js";import{b as x}from"./chunk-S7OHMN3F.js";import{b as v}from"./chunk-XAL6VWGA.js";import{d as k,e as q,f as C}from"./chunk-WT2HWDDA.js";import"./chunk-GIFF636B.js";import{b}from"./chunk-Q4QFIAHB.js";import"./chunk-G43H2WGH.js";import{b as I}from"./chunk-4U7XM2O3.js";import{b as M}from"./chunk-K7XSYP4L.js";import{b as j}from"./chunk-THLAHQXV.js";import{b as t}from"./chunk-YYQ22ZRL.js";import{b as l}from"./chunk-PS4LOXE5.js";import{b as u}from"./chunk-VNER2XXL.js";import{b as p}from"./chunk-4E3LY6YK.js";import{b as e}from"./chunk-5VFN7VVJ.js";import{b as d}from"./chunk-TEFXEYX3.js";import{b as c}from"./chunk-D2GFNFUN.js";import{b as h}from"./chunk-SXRVLCZ4.js";import"./chunk-FSZWFMB4.js";import"./chunk-4PRVMER6.js";import"./chunk-SE4C7FJY.js";import{b as i}from"./chunk-LJKIWB5F.js";import{b as g}from"./chunk-K47SEEPI.js";import"./chunk-5WFYIUU2.js";import{b as m}from"./chunk-X2I3PJTX.js";import"./chunk-D5WP4CKS.js";import"./chunk-K5IXNHO5.js";import{b as F}from"./chunk-
|
|
2
|
+
import{b as yr}from"./chunk-EFX3F2HZ.js";import{b as Ar}from"./chunk-CHB75QIN.js";import{b as $r}from"./chunk-MNNOATCV.js";import"./chunk-GZHFXDDO.js";import"./chunk-QSDVMMYI.js";import{b as Sr}from"./chunk-PDVXLMUU.js";import{b as wr}from"./chunk-XKPFI566.js";import{b as xr}from"./chunk-KLMOJKL4.js";import{b as vr}from"./chunk-TIDZOIPX.js";import{b as kr}from"./chunk-6VUEI2GS.js";import{b as qr}from"./chunk-BYDV4VEF.js";import{b as Cr}from"./chunk-JLX6YWGA.js";import{b as br}from"./chunk-FLPVVSN5.js";import{d as Ir,e as Mr,f as jr}from"./chunk-DAGNL3F2.js";import{b as tr}from"./chunk-P7UCWJ33.js";import{b as lr}from"./chunk-N73TVRMN.js";import{b as ur}from"./chunk-THALLNXT.js";import{b as pr}from"./chunk-2SIXTZCJ.js";import{b as er}from"./chunk-3Y32LPNT.js";import{b as dr}from"./chunk-7BORMNPQ.js";import{b as cr}from"./chunk-N43DJTSI.js";import"./chunk-OBI37ZY4.js";import{b as hr}from"./chunk-N5OTVT4F.js";import{c as or,d as ar}from"./chunk-MAVV76T4.js";import{b as sr}from"./chunk-JTF74J6E.js";import{c as ir,d as gr}from"./chunk-RDZMRK5M.js";import{b as mr}from"./chunk-QEBPVWVB.js";import"./chunk-A4442AOC.js";import"./chunk-UYBH3FNE.js";import{b as Fr}from"./chunk-BARKRZDC.js";import{b as zr}from"./chunk-P6GNZPVW.js";import{b as fr}from"./chunk-LOJMXC4F.js";import{b as nr}from"./chunk-NFZDITRV.js";import{b as R}from"./chunk-PQNTKMH3.js";import{b as U}from"./chunk-PPBQJBC2.js";import{b as V}from"./chunk-NSUMEERA.js";import{b as W}from"./chunk-4PS5JJDT.js";import{c as X,d as Y}from"./chunk-W2FKF3MM.js";import{c as Z,d as _}from"./chunk-3MBAUIBB.js";import{b as N}from"./chunk-RT7TRQVZ.js";import{b as rr}from"./chunk-JXC25GVQ.js";import{b as G}from"./chunk-RJSAGJQJ.js";import{b as H}from"./chunk-YEKSVVRC.js";import{b as J}from"./chunk-26NO42TF.js";import{b as K}from"./chunk-QXB5WI2V.js";import{b as L}from"./chunk-LMK6G2HH.js";import{b as O}from"./chunk-ZKC5HQYO.js";import{b as P}from"./chunk-ROJPSS6N.js";import{b as Q}from"./chunk-7ECKLAVW.js";import{b as y}from"./chunk-NEQEZ32M.js";import{b as A}from"./chunk-ZA4HUKJ3.js";import{b as $}from"./chunk-5U7Q4GUC.js";import{b as S}from"./chunk-JQBC3FXE.js";import{b as T}from"./chunk-BDSRLH5T.js";import{b as B}from"./chunk-5G2VOPPJ.js";import{b as D}from"./chunk-SGA7Y45Z.js";import{b as E}from"./chunk-EUXCM6C4.js";import{b as w}from"./chunk-YLE2OYY6.js";import{b as x}from"./chunk-S7OHMN3F.js";import{b as v}from"./chunk-XAL6VWGA.js";import{d as k,e as q,f as C}from"./chunk-WT2HWDDA.js";import"./chunk-GIFF636B.js";import{b}from"./chunk-Q4QFIAHB.js";import"./chunk-G43H2WGH.js";import{b as I}from"./chunk-4U7XM2O3.js";import{b as M}from"./chunk-K7XSYP4L.js";import{b as j}from"./chunk-THLAHQXV.js";import{b as t}from"./chunk-YYQ22ZRL.js";import{b as l}from"./chunk-PS4LOXE5.js";import{b as u}from"./chunk-VNER2XXL.js";import{b as p}from"./chunk-4E3LY6YK.js";import{b as e}from"./chunk-5VFN7VVJ.js";import{b as d}from"./chunk-TEFXEYX3.js";import{b as c}from"./chunk-D2GFNFUN.js";import{b as h}from"./chunk-SXRVLCZ4.js";import"./chunk-FSZWFMB4.js";import"./chunk-4PRVMER6.js";import"./chunk-SE4C7FJY.js";import{b as i}from"./chunk-LJKIWB5F.js";import{b as g}from"./chunk-K47SEEPI.js";import"./chunk-5WFYIUU2.js";import{b as m}from"./chunk-X2I3PJTX.js";import"./chunk-D5WP4CKS.js";import"./chunk-K5IXNHO5.js";import{b as F}from"./chunk-MXVNCVD6.js";import"./chunk-OBH7XN5N.js";import{b as z}from"./chunk-KWLLB7S3.js";import{b as f}from"./chunk-EJQKHROT.js";import"./chunk-JBABAK44.js";import{b as n}from"./chunk-ITA43A73.js";import"./chunk-4VDEBYW7.js";import"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";var Er=[i,g,m,F,z,f,n,t,l,u,p,e,d,c,h,w,x,v,k,q,C,b,I,M,j,y,A,$,S,T,B,D,E,G,H,J,K,L,O,P,Q,R,U,V,W,X,Y,Z,_,N,rr,or,ar,sr,ir,gr,mr,Fr,zr,fr,nr,tr,lr,ur,pr,er,dr,cr,hr,wr,xr,vr,kr,qr,Cr,br,Ir,Mr,jr,yr,Ar,$r,Sr];function Tr(){return Er}var Br=new Map;for(let r of Tr())Br.set(r.name,new Set(r.flags.map(o=>o.flag)));function Fa(r,o,Dr){let a=Br.get(o);if(!(!a||a.size===0))for(let s of Dr)a.has(s)&&r.hit(`cmd:flag:${o}:${s}`)}export{Fa as emitFlagCoverage};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a,b}from"./chunk-
|
|
2
|
+
import{a,b}from"./chunk-MXVNCVD6.js";import"./chunk-OBH7XN5N.js";import"./chunk-JBABAK44.js";import"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";export{b as flagsForFuzzing,a as lsCommand};
|
|
@@ -84,6 +84,13 @@ function getBlockedGlobals() {
|
|
|
84
84
|
strategy: "throw",
|
|
85
85
|
reason: "process.dlopen allows loading native addons"
|
|
86
86
|
},
|
|
87
|
+
{
|
|
88
|
+
prop: "getBuiltinModule",
|
|
89
|
+
target: process,
|
|
90
|
+
violationType: "process_get_builtin_module",
|
|
91
|
+
strategy: "throw",
|
|
92
|
+
reason: "process.getBuiltinModule allows loading native Node.js modules (fs, child_process, vm)"
|
|
93
|
+
},
|
|
87
94
|
// Note: process.mainModule is handled specially in defense-in-depth-box.ts
|
|
88
95
|
// and worker-defense-in-depth.ts because it may be undefined in ESM contexts
|
|
89
96
|
// but we still want to block both reading and setting it.
|
|
@@ -309,20 +316,11 @@ function getBlockedGlobals() {
|
|
|
309
316
|
}
|
|
310
317
|
|
|
311
318
|
// src/security/defense-in-depth-box.ts
|
|
319
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
312
320
|
var IS_BROWSER = typeof __BROWSER__ !== "undefined" && __BROWSER__;
|
|
313
321
|
var AsyncLocalStorageClass = null;
|
|
314
322
|
if (!IS_BROWSER) {
|
|
315
|
-
|
|
316
|
-
const { createRequire: createRequire2 } = await import("node:module");
|
|
317
|
-
const require3 = createRequire2(import.meta.url);
|
|
318
|
-
const asyncHooks = require3("node:async_hooks");
|
|
319
|
-
AsyncLocalStorageClass = asyncHooks.AsyncLocalStorage;
|
|
320
|
-
} catch (e) {
|
|
321
|
-
console.warn(
|
|
322
|
-
"[DefenseInDepthBox] WARNING: AsyncLocalStorage not available, defense-in-depth security layer is DISABLED. This means script execution will NOT be protected by runtime security patches. Reason:",
|
|
323
|
-
e instanceof Error ? e.message : e
|
|
324
|
-
);
|
|
325
|
-
}
|
|
323
|
+
AsyncLocalStorageClass = AsyncLocalStorage;
|
|
326
324
|
}
|
|
327
325
|
var executionContext = !IS_BROWSER && AsyncLocalStorageClass ? new AsyncLocalStorageClass() : null;
|
|
328
326
|
|
|
@@ -1888,21 +1886,23 @@ if 'jb_http' in sys.modules:
|
|
|
1888
1886
|
`);
|
|
1889
1887
|
} catch (_e) {
|
|
1890
1888
|
}
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
return JSON.stringify({ error: e.message });
|
|
1903
|
-
}
|
|
1889
|
+
const bridgeRequestFn = (url, method, headersJson, body) => {
|
|
1890
|
+
try {
|
|
1891
|
+
const headers = headersJson ? JSON.parse(headersJson) : void 0;
|
|
1892
|
+
const result = backend.httpRequest(url, {
|
|
1893
|
+
method: method || "GET",
|
|
1894
|
+
headers,
|
|
1895
|
+
body: body || void 0
|
|
1896
|
+
});
|
|
1897
|
+
return JSON.stringify(result);
|
|
1898
|
+
} catch (e) {
|
|
1899
|
+
return JSON.stringify({ error: e.message });
|
|
1904
1900
|
}
|
|
1901
|
+
};
|
|
1902
|
+
pyodide.registerJsModule("_jb_http_bridge", {
|
|
1903
|
+
request: bridgeRequestFn
|
|
1905
1904
|
});
|
|
1905
|
+
pyodide.globals.set("_jb_http_req_fn", bridgeRequestFn);
|
|
1906
1906
|
const envSetup = Object.entries(input.env).map(([key, value]) => {
|
|
1907
1907
|
return `os.environ[${JSON.stringify(key)}] = ${JSON.stringify(value)}`;
|
|
1908
1908
|
}).join("\n");
|
|
@@ -1919,6 +1919,10 @@ ${envSetup}
|
|
|
1919
1919
|
|
|
1920
1920
|
sys.argv = [${argvList}]
|
|
1921
1921
|
|
|
1922
|
+
# _jb_http_req_fn is injected by TypeScript via pyodide.globals.set().
|
|
1923
|
+
# It's the bridge request function directly \u2014 no import of _jb_http_bridge needed.
|
|
1924
|
+
# The _jb_http_bridge module is blocked from user import.
|
|
1925
|
+
|
|
1922
1926
|
# Create jb_http module for HTTP requests
|
|
1923
1927
|
class _JbHttpResponse:
|
|
1924
1928
|
"""HTTP response object similar to requests.Response"""
|
|
@@ -1947,16 +1951,17 @@ class _JbHttpResponse:
|
|
|
1947
1951
|
class _JbHttp:
|
|
1948
1952
|
"""HTTP client that bridges to just-bash's secureFetch"""
|
|
1949
1953
|
def request(self, method, url, headers=None, data=None, json_data=None):
|
|
1950
|
-
#
|
|
1951
|
-
#
|
|
1952
|
-
|
|
1954
|
+
# Uses _jb_http_req_fn captured above from sys.modules before scrub.
|
|
1955
|
+
# The bridge module itself is blocked from user import.
|
|
1956
|
+
if _jb_http_req_fn is None:
|
|
1957
|
+
raise Exception('HTTP bridge not available')
|
|
1953
1958
|
if json_data is not None:
|
|
1954
1959
|
data = json.dumps(json_data)
|
|
1955
1960
|
headers = headers or {}
|
|
1956
1961
|
headers['Content-Type'] = 'application/json'
|
|
1957
1962
|
# Serialize headers to JSON to avoid PyProxy issues when passing to JS
|
|
1958
1963
|
headers_json = json.dumps(headers) if headers else None
|
|
1959
|
-
result_json =
|
|
1964
|
+
result_json = _jb_http_req_fn(url, method, headers_json, data)
|
|
1960
1965
|
result = json.loads(result_json)
|
|
1961
1966
|
# Check for errors from the bridge (network not configured, URL not allowed, etc.)
|
|
1962
1967
|
if 'error' in result and result.get('status') is None:
|
|
@@ -2000,14 +2005,15 @@ sys.modules['jb_http'] = jb_http
|
|
|
2000
2005
|
# ============================================================
|
|
2001
2006
|
# Only apply sandbox restrictions once per Pyodide instance
|
|
2002
2007
|
if not hasattr(builtins, '_jb_sandbox_initialized'):
|
|
2008
|
+
def _jb_init_sandbox():
|
|
2003
2009
|
builtins._jb_sandbox_initialized = True
|
|
2004
2010
|
|
|
2005
2011
|
# ------------------------------------------------------------
|
|
2006
|
-
# 1. Block dangerous module imports (js, pyodide, pyodide_js, pyodide.ffi)
|
|
2012
|
+
# 1. Block dangerous module imports (js, pyodide, pyodide_js, pyodide.ffi, _pyodide)
|
|
2007
2013
|
# These allow sandbox escape via JavaScript execution
|
|
2008
2014
|
# ------------------------------------------------------------
|
|
2009
|
-
_BLOCKED_MODULES = frozenset({'js', 'pyodide', 'pyodide_js', 'pyodide.ffi'})
|
|
2010
|
-
_BLOCKED_PREFIXES = ('js.', 'pyodide.', 'pyodide_js.')
|
|
2015
|
+
_BLOCKED_MODULES = frozenset({'js', 'pyodide', 'pyodide_js', 'pyodide.ffi', '_pyodide', '_pyodide_core', 'ctypes', '_ctypes', '_jb_http_bridge'})
|
|
2016
|
+
_BLOCKED_PREFIXES = ('js.', 'pyodide.', 'pyodide_js.', '_pyodide.', '_pyodide_core.', 'ctypes.', '_ctypes.', '_jb_http_bridge.')
|
|
2011
2017
|
|
|
2012
2018
|
# Remove pre-loaded dangerous modules from sys.modules
|
|
2013
2019
|
for _blocked_mod in list(sys.modules.keys()):
|
|
@@ -2027,7 +2033,13 @@ if not hasattr(builtins, '_jb_sandbox_initialized'):
|
|
|
2027
2033
|
"""Wrapper that hides function internals from introspection."""
|
|
2028
2034
|
__slots__ = ()
|
|
2029
2035
|
def __call__(self, name, globals=None, locals=None, fromlist=(), level=0):
|
|
2030
|
-
|
|
2036
|
+
try:
|
|
2037
|
+
return _inner(name, globals, locals, fromlist, level)
|
|
2038
|
+
except BaseException as _e:
|
|
2039
|
+
# Strip traceback to prevent frame inspection leaking
|
|
2040
|
+
# orig_import from _inner's closure variables
|
|
2041
|
+
_e.__traceback__ = None
|
|
2042
|
+
raise
|
|
2031
2043
|
def __getattribute__(self, name):
|
|
2032
2044
|
if name in ('__call__', '__class__'):
|
|
2033
2045
|
return object.__getattribute__(self, name)
|
|
@@ -2037,8 +2049,141 @@ if not hasattr(builtins, '_jb_sandbox_initialized'):
|
|
|
2037
2049
|
return _SecureImport()
|
|
2038
2050
|
|
|
2039
2051
|
builtins.__import__ = _make_secure_import(builtins.__import__, _BLOCKED_MODULES, _BLOCKED_PREFIXES)
|
|
2052
|
+
|
|
2053
|
+
# ------------------------------------------------------------
|
|
2054
|
+
# 1b. Block imports via sys.meta_path finder
|
|
2055
|
+
# importlib.import_module routes through _bootstrap._find_and_load,
|
|
2056
|
+
# NOT through builtins.__import__. A meta_path finder blocks ALL
|
|
2057
|
+
# import paths at the most fundamental level.
|
|
2058
|
+
# ------------------------------------------------------------
|
|
2059
|
+
_blocked_set = frozenset(_BLOCKED_MODULES)
|
|
2060
|
+
_blocked_pfx = tuple(_BLOCKED_PREFIXES)
|
|
2061
|
+
|
|
2062
|
+
class _BlockingFinder:
|
|
2063
|
+
"""Meta-path finder that blocks imports of sandboxed modules."""
|
|
2064
|
+
__slots__ = ()
|
|
2065
|
+
def find_module(self, name, path=None):
|
|
2066
|
+
if name in _blocked_set or any(name.startswith(p) for p in _blocked_pfx):
|
|
2067
|
+
raise ImportError(f"Module '{name}' is blocked in this sandbox")
|
|
2068
|
+
return None
|
|
2069
|
+
def find_spec(self, name, path, target=None):
|
|
2070
|
+
if name in _blocked_set or any(name.startswith(p) for p in _blocked_pfx):
|
|
2071
|
+
raise ImportError(f"Module '{name}' is blocked in this sandbox")
|
|
2072
|
+
return None
|
|
2073
|
+
sys.meta_path.insert(0, _BlockingFinder())
|
|
2074
|
+
|
|
2075
|
+
# ------------------------------------------------------------
|
|
2076
|
+
# 1c. Patch importlib.import_module and importlib.util.find_spec
|
|
2077
|
+
# Belt-and-suspenders: also block at the importlib API level
|
|
2078
|
+
# in case sys.modules already contains the blocked module.
|
|
2079
|
+
# ------------------------------------------------------------
|
|
2080
|
+
import importlib
|
|
2081
|
+
import importlib.util
|
|
2082
|
+
|
|
2083
|
+
_orig_import_module = importlib.import_module
|
|
2084
|
+
def _secure_import_module_inner(name, package=None):
|
|
2085
|
+
if name in _blocked_set or any(name.startswith(p) for p in _blocked_pfx):
|
|
2086
|
+
raise ImportError(f"Module '{name}' is blocked in this sandbox")
|
|
2087
|
+
return _orig_import_module(name, package)
|
|
2088
|
+
|
|
2089
|
+
class _SecureImportModule:
|
|
2090
|
+
__slots__ = ()
|
|
2091
|
+
def __call__(self, name, package=None):
|
|
2092
|
+
try:
|
|
2093
|
+
return _secure_import_module_inner(name, package)
|
|
2094
|
+
except BaseException as _e:
|
|
2095
|
+
_e.__traceback__ = None
|
|
2096
|
+
raise
|
|
2097
|
+
def __getattribute__(self, name):
|
|
2098
|
+
if name in ('__call__', '__class__'):
|
|
2099
|
+
return object.__getattribute__(self, name)
|
|
2100
|
+
raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'")
|
|
2101
|
+
def __repr__(self):
|
|
2102
|
+
return '<function import_module>'
|
|
2103
|
+
importlib.import_module = _SecureImportModule()
|
|
2104
|
+
|
|
2105
|
+
_orig_find_spec = importlib.util.find_spec
|
|
2106
|
+
def _secure_find_spec_inner(name, package=None):
|
|
2107
|
+
if name in _blocked_set or any(name.startswith(p) for p in _blocked_pfx):
|
|
2108
|
+
raise ImportError(f"Module '{name}' is blocked in this sandbox")
|
|
2109
|
+
return _orig_find_spec(name, package)
|
|
2110
|
+
|
|
2111
|
+
class _SecureFindSpec:
|
|
2112
|
+
__slots__ = ()
|
|
2113
|
+
def __call__(self, name, package=None):
|
|
2114
|
+
try:
|
|
2115
|
+
return _secure_find_spec_inner(name, package)
|
|
2116
|
+
except BaseException as _e:
|
|
2117
|
+
_e.__traceback__ = None
|
|
2118
|
+
raise
|
|
2119
|
+
def __getattribute__(self, name):
|
|
2120
|
+
if name in ('__call__', '__class__'):
|
|
2121
|
+
return object.__getattribute__(self, name)
|
|
2122
|
+
raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'")
|
|
2123
|
+
def __repr__(self):
|
|
2124
|
+
return '<function find_spec>'
|
|
2125
|
+
importlib.util.find_spec = _SecureFindSpec()
|
|
2126
|
+
|
|
2127
|
+
# Note: We intentionally do NOT replace sys.modules with a custom dict
|
|
2128
|
+
# subclass. Replacing it breaks lazy imports (e.g., _strptime used by
|
|
2129
|
+
# datetime.strptime) because Pyodide's C-level import machinery
|
|
2130
|
+
# caches the original dict. Instead, we rely on:
|
|
2131
|
+
# 1. Per-run scrubbing of blocked modules from sys.modules
|
|
2132
|
+
# 2. meta_path finder blocking new imports
|
|
2133
|
+
# 3. builtins.__import__ hook blocking import statements
|
|
2134
|
+
|
|
2135
|
+
# ------------------------------------------------------------
|
|
2136
|
+
# 1cc. Patch importlib._bootstrap at the deepest level
|
|
2137
|
+
# _bootstrap.__import__ holds a reference to the ORIGINAL __import__
|
|
2138
|
+
# (not our wrapper). An attacker can use it directly to bypass all
|
|
2139
|
+
# our hooks. Patch it with our wrapper.
|
|
2140
|
+
# Also patch _bootstrap._find_and_load \u2014 this is the function that
|
|
2141
|
+
# the C-level import machinery calls. Even if an attacker steals
|
|
2142
|
+
# orig_import via closure introspection AND replaces sys.meta_path,
|
|
2143
|
+
# this blocks the import at the lowest Python-accessible level.
|
|
2144
|
+
# ------------------------------------------------------------
|
|
2145
|
+
_bootstrap_mod = sys.modules.get('importlib._bootstrap')
|
|
2146
|
+
if _bootstrap_mod:
|
|
2147
|
+
_bootstrap_mod.__import__ = builtins.__import__
|
|
2148
|
+
|
|
2149
|
+
_orig_find_and_load = _bootstrap_mod._find_and_load
|
|
2150
|
+
def _secure_find_and_load(name, import_):
|
|
2151
|
+
if name in _blocked_set or any(name.startswith(p) for p in _blocked_pfx):
|
|
2152
|
+
raise ImportError(f"Module '{name}' is blocked in this sandbox")
|
|
2153
|
+
return _orig_find_and_load(name, import_)
|
|
2154
|
+
_bootstrap_mod._find_and_load = _secure_find_and_load
|
|
2155
|
+
|
|
2156
|
+
# Also patch _find_and_load_unlocked (called internally)
|
|
2157
|
+
if hasattr(_bootstrap_mod, '_find_and_load_unlocked'):
|
|
2158
|
+
_orig_find_and_load_unlocked = _bootstrap_mod._find_and_load_unlocked
|
|
2159
|
+
def _secure_find_and_load_unlocked(name, import_):
|
|
2160
|
+
if name in _blocked_set or any(name.startswith(p) for p in _blocked_pfx):
|
|
2161
|
+
raise ImportError(f"Module '{name}' is blocked in this sandbox")
|
|
2162
|
+
return _orig_find_and_load_unlocked(name, import_)
|
|
2163
|
+
_bootstrap_mod._find_and_load_unlocked = _secure_find_and_load_unlocked
|
|
2164
|
+
|
|
2040
2165
|
del _BLOCKED_MODULES, _BLOCKED_PREFIXES, _make_secure_import
|
|
2041
2166
|
|
|
2167
|
+
# ------------------------------------------------------------
|
|
2168
|
+
# 1d. Block gc object-discovery functions
|
|
2169
|
+
# gc.get_objects() can find purged module objects still in memory
|
|
2170
|
+
# (held by Pyodide C internals), enabling sandbox escape.
|
|
2171
|
+
# ------------------------------------------------------------
|
|
2172
|
+
import gc as _gc_module
|
|
2173
|
+
_gc_module.get_objects = lambda: []
|
|
2174
|
+
_gc_module.get_referrers = lambda *args: []
|
|
2175
|
+
_gc_module.get_referents = lambda *args: []
|
|
2176
|
+
|
|
2177
|
+
# ------------------------------------------------------------
|
|
2178
|
+
# 1e. Neuter sys.settrace and sys.setprofile
|
|
2179
|
+
# These debugging APIs expose call frames via trace callbacks.
|
|
2180
|
+
# An attacker can use them to inspect closure variables in our
|
|
2181
|
+
# import hooks (e.g., orig_import in _inner), stealing the
|
|
2182
|
+
# original __import__ and bypassing all blocking.
|
|
2183
|
+
# ------------------------------------------------------------
|
|
2184
|
+
sys.settrace = lambda *args: None
|
|
2185
|
+
sys.setprofile = lambda *args: None
|
|
2186
|
+
|
|
2042
2187
|
# ------------------------------------------------------------
|
|
2043
2188
|
# 2. Path redirection helper
|
|
2044
2189
|
# ------------------------------------------------------------
|
|
@@ -2404,6 +2549,19 @@ if not hasattr(builtins, '_jb_sandbox_initialized'):
|
|
|
2404
2549
|
yield p
|
|
2405
2550
|
Path.rglob = _path_rglob
|
|
2406
2551
|
|
|
2552
|
+
_jb_init_sandbox()
|
|
2553
|
+
del _jb_init_sandbox
|
|
2554
|
+
|
|
2555
|
+
# Per-run: scrub blocked modules from sys.modules.
|
|
2556
|
+
# Pyodide's C-level JsFinder may re-insert 'js' etc. between runs.
|
|
2557
|
+
# This is hardcoded inline (not a callable on builtins) so attackers cannot neuter it.
|
|
2558
|
+
for _jb_k in list(sys.modules.keys()):
|
|
2559
|
+
if _jb_k in frozenset({'js', 'pyodide', 'pyodide_js', 'pyodide.ffi', '_pyodide', '_pyodide_core', 'ctypes', '_ctypes', '_jb_http_bridge'}) or \\
|
|
2560
|
+
any(_jb_k.startswith(_p) for _p in ('js.', 'pyodide.', 'pyodide_js.', '_pyodide.', '_pyodide_core.', 'ctypes.', '_ctypes.', '_jb_http_bridge.')):
|
|
2561
|
+
try: del sys.modules[_jb_k]
|
|
2562
|
+
except (KeyError, ImportError): pass
|
|
2563
|
+
del _jb_k
|
|
2564
|
+
|
|
2407
2565
|
# Set cwd to host mount
|
|
2408
2566
|
os.chdir('/host' + ${JSON.stringify(input.cwd)})
|
|
2409
2567
|
`);
|