mirror of
https://github.com/openai/codex-security.git
synced 2026-12-03 20:26:45 +08:00
* feat(cli): add independently reviewed dependency checks * Compare frozen Python advisory versions as releases * fix(cli): bind unnamed root manifests to observed services * test(cli): evaluate dependency investigations across public fixtures * test(sdk): bound the budget wait after the mock scan starts * test(cli): exercise MCP evidence and missing caller access * Bind graded citations to the approved use evidence * test: restore dependency investigation quality controls * fix(cli): restore dependency investigation and report compatibility * test: grade malformed dependency baseline answers * fix(cli): scope headless tool access to the investigator * test(cli): lock down reviewer and external evidence tool access * fix(cli): keep linked evidence tied to its originating call * Reconcile application mappings and expose original evidence hashes * test: verify selected catalog rows against original replies * fix(cli): recover incomplete reviews and preserve selected evidence rows * fix(cli): preserve wire evidence and verify finding citations * Finalize from approved submissions and explain remaining uses * fix(cli): restore coordinator recovery, independent review and report contracts * Review withdrawals under the original dependency assessment ID * test(cli): compare trace progress with completed search scopes * Recheck dependency coverage after concurrent investigation changes * Preserve exploratory scope explanations during dependency review * feat(cli): track shared source work in dependency investigations * Include shared source work in final coverage checks * Require deciding evidence on the caller it establishes * Preserve generic MCP search outcomes and scopes in dependency reports * Share pinned source notes between dependency investigators * Ship the source worklist and search audit modules * refactor(cli): name the dependency coordinator for its ability to resume * refactor(cli): simplify the tools for dependency investigations * fix(cli): keep investigation tool arguments visible to Codex and reuse the evidence store * fix(cli): send missing verdict citations back to the reviewer * fix(cli): verify caller bindings and input flow across investigation steps * fix(cli): require direct citations for asserted runtime facts on every use * test(cli): verify failed catalog lookups without a timed source scan --------- Co-authored-by: utsav-oai <348536218+utsav-oai@users.noreply.github.com>
171 lines
5.4 KiB
TypeScript
171 lines
5.4 KiB
TypeScript
import { isRecord } from "../../sdk/typescript/src/record.ts";
|
|
import { catalogServer, catalogTool, type MappingCase } from "./cases.mts";
|
|
|
|
const catalogCitation = `${catalogServer}/${catalogTool}`;
|
|
|
|
export function gradeMapping(c: MappingCase, snapshots: readonly unknown[]) {
|
|
const errors: string[] = [];
|
|
const applications: { name: string; scope?: string }[] = [];
|
|
const replies = snapshots.filter(isRecord);
|
|
const states = replies
|
|
.map((reply) => reply.service_resolution)
|
|
.filter(isRecord);
|
|
const revision = Math.max(
|
|
...states.map(({ revision }) =>
|
|
typeof revision === "number" ? revision : -1,
|
|
),
|
|
);
|
|
const query = replies.findLast(
|
|
(reply) =>
|
|
isRecord(reply.service_resolution) &&
|
|
reply.service_resolution.revision === revision &&
|
|
isRecord(reply.node) &&
|
|
reply.node.kind === "file" &&
|
|
reply.node.name === c.path,
|
|
);
|
|
const state = query?.service_resolution;
|
|
const configured = c.catalog !== undefined;
|
|
if (
|
|
!query ||
|
|
!isRecord(state) ||
|
|
state.catalog_configured !== configured ||
|
|
state.pending !== 0 ||
|
|
state.truncated ||
|
|
query.truncated ||
|
|
query.service_lookup !== (configured ? "checked" : undefined) ||
|
|
!Array.isArray(query.evidence)
|
|
) {
|
|
const latest = states.findLast((state) => state.revision === revision);
|
|
if (typeof latest?.pending === "number" && latest.pending > 0) {
|
|
const paths = Array.isArray(latest.paths)
|
|
? latest.paths.filter((path) => typeof path === "string")
|
|
: [];
|
|
errors.push(
|
|
`Pending service lookups (${latest.pending})${paths.length ? ` for ${paths.join(", ")}` : ""}`,
|
|
);
|
|
} else {
|
|
errors.push(
|
|
`Missing complete graph query for ${c.path} at the final revision`,
|
|
);
|
|
}
|
|
return { pass: false, errors, applications };
|
|
}
|
|
const expected = c.expected.applications;
|
|
const isExpected = (name: unknown, scope: unknown) =>
|
|
expected.some(
|
|
(app) => app.name === name && `${catalogServer}:${app.id}` === scope,
|
|
);
|
|
const evidence = query.evidence.filter(isRecord);
|
|
const uses = [];
|
|
for (const { from, relation, to, source } of evidence) {
|
|
if (
|
|
relation !== "uses" ||
|
|
!isRecord(from) ||
|
|
from.kind !== "service" ||
|
|
typeof from.name !== "string" ||
|
|
!isRecord(to)
|
|
)
|
|
continue;
|
|
const coversFile = to.kind === "file" && to.name === c.path;
|
|
const coversDirectory =
|
|
to.kind === "directory" &&
|
|
typeof to.name === "string" &&
|
|
(to.name === "." || c.path.startsWith(to.name + "/"));
|
|
if (!coversFile && !coversDirectory) continue;
|
|
const scope = typeof from.scope === "string" ? from.scope : undefined;
|
|
const name = from.name;
|
|
uses.push({ name, scope, source });
|
|
if (applications.some((app) => app.name === name && app.scope === scope))
|
|
continue;
|
|
applications.push({ name, ...(scope && { scope }) });
|
|
if (!isExpected(name, scope))
|
|
errors.push(`Unexpected application ${name} (${scope ?? "unscoped"})`);
|
|
}
|
|
if (
|
|
configured &&
|
|
replies.some(
|
|
({ services }) =>
|
|
Array.isArray(services) &&
|
|
services
|
|
.filter(isRecord)
|
|
.some(({ name, scope }) => !isExpected(name, scope)),
|
|
)
|
|
) {
|
|
errors.push("Graph contains a service outside the expected applications");
|
|
}
|
|
for (const { name, id } of expected) {
|
|
if (
|
|
!uses.some(
|
|
(use) =>
|
|
use.name === name &&
|
|
use.scope === `${catalogServer}:${id}` &&
|
|
use.source === `${catalogCitation}#${id}`,
|
|
)
|
|
) {
|
|
errors.push(`Missing catalog evidence for ${name} (${id})`);
|
|
}
|
|
}
|
|
const noService = evidence.some(
|
|
({ from, relation, source }) =>
|
|
relation === "no_service_found" &&
|
|
isRecord(from) &&
|
|
from.kind === "file" &&
|
|
from.name === c.path &&
|
|
source === catalogCitation,
|
|
);
|
|
if (configured && !expected.length && !noService) {
|
|
errors.push(`Missing cited no_service_found result for ${c.path}`);
|
|
}
|
|
if (
|
|
!configured &&
|
|
(replies.some(
|
|
(reply) =>
|
|
typeof reply.services_found === "number" && reply.services_found > 0,
|
|
) ||
|
|
evidence.some(
|
|
({ from, to, relation }) =>
|
|
relation === "no_service_found" ||
|
|
(isRecord(from) && from.kind === "service") ||
|
|
(isRecord(to) && to.kind === "service"),
|
|
))
|
|
) {
|
|
errors.push("Unconfigured graph decided a service identity or absence");
|
|
}
|
|
return { pass: errors.length === 0, errors, applications };
|
|
}
|
|
|
|
// Only host-captured graph replies establish the identity and scope of an
|
|
// application. The investigator's generated reasoning is not a graph record.
|
|
export function graphReplies(report: unknown): unknown[] {
|
|
if (
|
|
!isRecord(report) ||
|
|
!Array.isArray(report.checks) ||
|
|
report.checks.length !== 1
|
|
)
|
|
return [];
|
|
const check = report.checks[0];
|
|
if (
|
|
!isRecord(check) ||
|
|
!isRecord(check.claimEvidence) ||
|
|
!isRecord(check.claimEvidence.receipts)
|
|
)
|
|
return [];
|
|
const replies = [];
|
|
for (const row of Object.values(check.claimEvidence.receipts)) {
|
|
if (
|
|
!isRecord(row) ||
|
|
row.server !== "dependency_investigation" ||
|
|
![
|
|
"query_codex_security_graph",
|
|
"trace_codex_security_code",
|
|
"resolve_codex_security_services",
|
|
].includes(String(row.tool)) ||
|
|
!isRecord(row.result)
|
|
)
|
|
continue;
|
|
const data = row.result.structuredContent ?? row.result;
|
|
if (isRecord(data)) replies.push(data);
|
|
}
|
|
return replies;
|
|
}
|