mirror of
https://github.com/qybaihe/bla.git
synced 2026-11-20 08:20:59 +08:00
fix(defend): report the release-exposure stage as warn when the scan cannot run (#164)
This commit is contained in:
+10
-5
@@ -163,10 +163,12 @@ export function defendTarget(options: OneClickDefenseOptions): OneClickDefenseRe
|
||||
|
||||
// Stage 1: Release Exposure Scan (best-effort for local files/directories)
|
||||
let releaseExposure: ReleaseExposureReport | null = null;
|
||||
let releaseExposureError: string | undefined;
|
||||
try {
|
||||
releaseExposure = inspectReleaseExposure(absInput);
|
||||
} catch {
|
||||
} catch (err) {
|
||||
releaseExposure = null;
|
||||
releaseExposureError = err instanceof Error ? err.message : String(err);
|
||||
}
|
||||
|
||||
// Stage 2: Pre-flight REA Audit
|
||||
@@ -263,10 +265,13 @@ export function defendTarget(options: OneClickDefenseOptions): OneClickDefenseRe
|
||||
const stages: OneClickDefenseStageSummary[] = [
|
||||
{
|
||||
stage: "1-release-exposure-scan",
|
||||
status: "passed",
|
||||
headline: releaseExposure
|
||||
? `Inspected ${releaseExposure.filesInspected} file(s); ${releaseExposure.findings.length} raw source-map exposure finding(s) neutralized`
|
||||
: "Binary/container target validated for direct shield injection",
|
||||
status: releaseExposureError === undefined ? "passed" : "warn",
|
||||
headline:
|
||||
releaseExposureError !== undefined
|
||||
? `Release exposure scan could not run (${releaseExposureError}); the shield pipeline continues without an exposure report`
|
||||
: releaseExposure
|
||||
? `Inspected ${releaseExposure.filesInspected} file(s); ${releaseExposure.findings.length} raw source-map exposure finding(s) neutralized`
|
||||
: "Binary/container target validated for direct shield injection",
|
||||
},
|
||||
{
|
||||
stage: "2-preflight-rea-audit",
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import * as fs from "node:fs";
|
||||
import * as os from "node:os";
|
||||
import * as path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { defendTarget } from "../src/engine/defender.js";
|
||||
|
||||
describe("defendTarget stage-1 honesty", () => {
|
||||
it("reports warn instead of passed when the release-exposure scan cannot run", () => {
|
||||
const base = fs.mkdtempSync(path.join(os.tmpdir(), "bla-defend-stage-"));
|
||||
const real = path.join(base, "real");
|
||||
fs.mkdirSync(real);
|
||||
fs.writeFileSync(path.join(real, "app.js"), "export const value = 42;\n", "utf8");
|
||||
const link = path.join(base, "link");
|
||||
try {
|
||||
fs.symlinkSync(real, link, process.platform === "win32" ? "junction" : "dir");
|
||||
} catch {
|
||||
return; // symlink/junction creation unavailable on this host
|
||||
}
|
||||
try {
|
||||
const report = defendTarget({
|
||||
inputPath: link,
|
||||
outputPath: path.join(base, "out"),
|
||||
intensity: "balanced",
|
||||
seed: "stage-honesty-test",
|
||||
});
|
||||
expect(report.releaseExposure).toBeNull();
|
||||
expect(report.stages[0]).toMatchObject({
|
||||
stage: "1-release-exposure-scan",
|
||||
status: "warn",
|
||||
});
|
||||
expect(report.stages[0]!.headline).toMatch(/could not run/);
|
||||
} finally {
|
||||
fs.rmSync(base, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user