@theokit/sdk 4.21.0 → 4.22.0
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/sandbox/index.js
CHANGED
|
@@ -536,7 +536,7 @@ var LinuxSandbox = class extends LocalSandbox {
|
|
|
536
536
|
this.cwd = config.workDir ?? process.cwd();
|
|
537
537
|
this.bin = opts.bin ?? "bwrap";
|
|
538
538
|
this.env = opts.env ?? allowlistedEnv();
|
|
539
|
-
this.seccompPath = this.network
|
|
539
|
+
this.seccompPath = seccompPathParaRede(this.network);
|
|
540
540
|
}
|
|
541
541
|
/** Extracted for test visibility — delegates to the pure `wrapCommandForSandbox` (M57, single wrap SoT). */
|
|
542
542
|
wrapCommand(command) {
|
|
@@ -552,6 +552,32 @@ var LinuxSandbox = class extends LocalSandbox {
|
|
|
552
552
|
command
|
|
553
553
|
);
|
|
554
554
|
}
|
|
555
|
+
/**
|
|
556
|
+
* M75 review (arquitetura, HIGH) — sem este override a classe MENTIA.
|
|
557
|
+
*
|
|
558
|
+
* `LinuxSandbox` se documenta como "kernel-enforced sandbox backend", mas sobrescrevia apenas
|
|
559
|
+
* `execute`. `uploadFile` continuava o herdado de `LocalSandbox`, que escreve direto no host via
|
|
560
|
+
* `fs/promises` e aceita caminho ABSOLUTO — sem bwrap, sem seccomp, sem restrição de caminho. E
|
|
561
|
+
* `SandboxBackend.writeFile` delega a ele. O resultado era uma classe incoerente: ler, buscar e
|
|
562
|
+
* listar passavam pelo confinamento; escrever, não.
|
|
563
|
+
*
|
|
564
|
+
* Rotear pelo `execute` embrulhado resolve na raiz: a escrita passa a viver sob a MESMA política
|
|
565
|
+
* do resto — se o bwrap nega o caminho, a escrita falha, como deve. O conteúdo vai por stdin (não
|
|
566
|
+
* por argv) porque argv tem limite de tamanho e conteúdo de arquivo não tem.
|
|
567
|
+
*/
|
|
568
|
+
async uploadFile(caminho, conteudo) {
|
|
569
|
+
if (this.mode === "danger-full-access") return super.uploadFile(caminho, conteudo);
|
|
570
|
+
const alvo = caminho.startsWith("/") ? caminho : `${this.cwd}/${caminho}`;
|
|
571
|
+
const b64 = Buffer.from(conteudo).toString("base64");
|
|
572
|
+
const r = await this.execute(
|
|
573
|
+
`mkdir -p ${shellQuote(dirname(alvo))} && printf %s ${shellQuote(b64)} | base64 -d > ${shellQuote(alvo)}`
|
|
574
|
+
);
|
|
575
|
+
if (r.exitCode !== 0) {
|
|
576
|
+
throw new Error(
|
|
577
|
+
`uploadFile bloqueado ou falhou sob confinamento (${alvo}): ${r.stderr.trim() || `exit ${r.exitCode}`}`
|
|
578
|
+
);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
555
581
|
execute(command, opts) {
|
|
556
582
|
const wrapped = this.wrapCommand(command);
|
|
557
583
|
if (wrapped === null) return super.execute(command, opts);
|
|
@@ -626,28 +652,34 @@ var avisouInterativo = false;
|
|
|
626
652
|
function resetInteractiveWarnLatch() {
|
|
627
653
|
avisouInterativo = false;
|
|
628
654
|
}
|
|
655
|
+
function seccompPathParaRede(redeLiberada) {
|
|
656
|
+
return redeLiberada ? void 0 : restrictedSeccompPath();
|
|
657
|
+
}
|
|
658
|
+
function decidirConfinamento(opts) {
|
|
659
|
+
if (opts.mode === "danger-full-access") return null;
|
|
660
|
+
const detection = (opts.detect ?? detectBwrapMemoizado)();
|
|
661
|
+
if (detection.ok) return detection.bin;
|
|
662
|
+
if (!avisouInterativo) {
|
|
663
|
+
avisouInterativo = true;
|
|
664
|
+
const warn = opts.warn ?? ((m) => console.warn(redactSecrets(m)));
|
|
665
|
+
warn(
|
|
666
|
+
`[sandbox] OS-level enforcement unavailable (${detection.reason}) \u2014 interactive session runs WITHOUT kernel confinement (sandbox_mode=${opts.mode}).`
|
|
667
|
+
);
|
|
668
|
+
}
|
|
669
|
+
return null;
|
|
670
|
+
}
|
|
629
671
|
function interactiveWrapCommand(opts) {
|
|
630
672
|
return (command, cwd) => {
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
if (!detection.ok) {
|
|
634
|
-
if (!avisouInterativo) {
|
|
635
|
-
avisouInterativo = true;
|
|
636
|
-
const warn = opts.warn ?? ((m) => console.warn(redactSecrets(m)));
|
|
637
|
-
warn(
|
|
638
|
-
`[sandbox] OS-level enforcement unavailable (${detection.reason}) \u2014 interactive session runs WITHOUT kernel confinement (sandbox_mode=${opts.mode}).`
|
|
639
|
-
);
|
|
640
|
-
}
|
|
641
|
-
return null;
|
|
642
|
-
}
|
|
673
|
+
const bin = decidirConfinamento(opts);
|
|
674
|
+
if (bin === null) return null;
|
|
643
675
|
return wrapCommandForSandbox(
|
|
644
676
|
opts.mode,
|
|
645
677
|
{
|
|
646
678
|
cwd,
|
|
647
679
|
network: opts.network ?? false,
|
|
648
680
|
env: allowlistedEnv(),
|
|
649
|
-
bin
|
|
650
|
-
seccompPath:
|
|
681
|
+
bin,
|
|
682
|
+
seccompPath: seccompPathParaRede(opts.network ?? false)
|
|
651
683
|
},
|
|
652
684
|
command
|
|
653
685
|
);
|