fix: 限制NapCat自动化产物写入范围

This commit is contained in:
sunlei 2026-06-25 17:39:49 +08:00
parent 65807e8ef3
commit 1e39a431b7
2 changed files with 29 additions and 0 deletions

View File

@ -182,6 +182,34 @@ export async function runSelfTest(): Promise<void> {
); );
} }
} }
const unsafeSkeletonArtifactRootPath = path.resolve("/tmp/not-kt-skeleton");
const unsafeSkeletonArtifactRootExisted = existsSync(
unsafeSkeletonArtifactRootPath,
);
let unsafeSkeletonArtifactRootRejected = false;
try {
buildNapcatRuntimeReleaseReadiness({
artifactRoot: "/tmp/not-kt-skeleton",
});
} catch (error) {
unsafeSkeletonArtifactRootRejected = String(error).includes(
"Unsafe NapCat Codex artifactRoot",
);
} finally {
if (
!unsafeSkeletonArtifactRootExisted &&
existsSync(unsafeSkeletonArtifactRootPath)
) {
rmSync(unsafeSkeletonArtifactRootPath, { force: true, recursive: true });
}
}
if (
!unsafeSkeletonArtifactRootRejected ||
(!unsafeSkeletonArtifactRootExisted &&
existsSync(unsafeSkeletonArtifactRootPath))
) {
throw new Error("NapCat skeleton unsafe artifact root self-check failed");
}
if ( if (
napcatCandidateDefaults.candidateBranch !== napcatCandidateDefaults.candidateBranch !==
napcatAutomationDefaults.candidateBranch || napcatAutomationDefaults.candidateBranch ||

View File

@ -165,6 +165,7 @@ function buildNapcatPromptSkeleton(config: NapcatPromptSkeletonConfig) {
config.input, config.input,
config.artifactSlug, config.artifactSlug,
); );
assertSafeNapcatCodexArtifactRoot(artifactRoot);
const requestedExecute = config.input.execute === true; const requestedExecute = config.input.execute === true;
const promptText = loadNapcatAutomationPrompt(config.promptName).trim(); const promptText = loadNapcatAutomationPrompt(config.promptName).trim();
const promptPath = joinNapcatArtifactPath( const promptPath = joinNapcatArtifactPath(