mirror of
https://github.com/openai/codex-security.git
synced 2026-11-25 19:45:59 +08:00
Merge main into mdangelo/codex/scan-instruction-digest
This commit is contained in:
@@ -174,6 +174,10 @@ Keep the published notes easy to scan:
|
||||
- Start with a short overview and the main user-facing highlights. Use bold
|
||||
topic labels to make the bullets easy to skim. Put secondary improvements
|
||||
in a `<details>` block when they would crowd out upgrade guidance.
|
||||
- When bundled instructions change how scans discover or validate findings
|
||||
or assign severity, describe the change in the highlights or upgrade notes.
|
||||
Name the affected scan modes and behaviors or finding categories. If a
|
||||
benchmark measured the effect, report the result and its scope.
|
||||
- Keep breaking changes and required upgrade actions visible. Long migration
|
||||
procedures can go in a clearly named `<details>` block under the relevant
|
||||
upgrade note. Keep code fences, tables, and lists intact.
|
||||
|
||||
@@ -25,6 +25,7 @@ export class DeepScanNonRetryableError extends Error {
|
||||
|
||||
const USAGE_LIMIT_MESSAGES = new Set([
|
||||
"Quota exceeded. Check your plan and billing details.",
|
||||
"To use Codex with your ChatGPT plan, upgrade to Plus: https://chatgpt.com/explore/plus.",
|
||||
"Your workspace is out of credits. Add credits to continue.",
|
||||
"Your workspace is out of credits. Ask your workspace owner to refill in order to continue.",
|
||||
"You hit your spend cap set in your workspace. Increase your spend cap to continue.",
|
||||
|
||||
@@ -107,6 +107,7 @@ function testWorkerErrorClassificationPreservesExplicitFailures() {
|
||||
function testUsageLimitClassification() {
|
||||
for (const message of [
|
||||
"Quota exceeded. Check your plan and billing details.",
|
||||
"To use Codex with your ChatGPT plan, upgrade to Plus: https://chatgpt.com/explore/plus.",
|
||||
"Your workspace is out of credits. Add credits to continue.",
|
||||
"Your workspace is out of credits. Ask your workspace owner to refill in order to continue.",
|
||||
"You hit your spend cap set in your workspace. Increase your spend cap to continue.",
|
||||
|
||||
@@ -154,6 +154,7 @@ test("a duplicate stops the loop and every observation survives", async () => {
|
||||
const alias = {
|
||||
...base,
|
||||
title: "A different description",
|
||||
severity: { level: "critical" as const },
|
||||
provenance: { source: "local_plugin" },
|
||||
};
|
||||
const { terminal, draft, started } = await scanLoop([[base], [alias]], {
|
||||
@@ -164,16 +165,22 @@ test("a duplicate stops the loop and every observation survives", async () => {
|
||||
assert.deepEqual(started, [0, 1]);
|
||||
assert.equal(terminal.terminalReason, "saturated");
|
||||
assert.equal(draft.findings.length, 1);
|
||||
assert.deepEqual(draft.findings[0].severity, base.severity);
|
||||
assert.deepEqual(
|
||||
draft.findings[0].provenance.sourceFindings?.map((x) => x.finding.title),
|
||||
[base.title, alias.title],
|
||||
);
|
||||
assert.deepEqual(
|
||||
draft.findings[0].provenance.sourceFindings?.map((x) => x.finding.severity),
|
||||
[base.severity, alias.severity],
|
||||
);
|
||||
});
|
||||
|
||||
test("an exact repeat of a merged source saturates without another comparison", async () => {
|
||||
const alias = {
|
||||
...base,
|
||||
title: "Another description of the same sink",
|
||||
severity: { level: "medium" as const },
|
||||
locations: [...base.locations, { path: "caller.py", startLine: 12 }],
|
||||
};
|
||||
const { terminal, draft } = await scanLoop([[base, alias], [alias]], {
|
||||
@@ -182,9 +189,11 @@ test("an exact repeat of a merged source saturates without another comparison",
|
||||
comparisons: [[[0, 1]]],
|
||||
});
|
||||
assert.equal(terminal.terminalReason, "saturated");
|
||||
assert.equal(draft.findings.length, 1);
|
||||
assert.deepEqual(draft.findings[0].severity, base.severity);
|
||||
assert.deepEqual(
|
||||
draft.findings.map((f) => f.provenance.sourceFindings?.length),
|
||||
[3],
|
||||
draft.findings[0].provenance.sourceFindings?.map((x) => x.finding.severity),
|
||||
[base.severity, alias.severity, alias.severity],
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ Keep unfinished requested work and essential in-scope proof gaps in `reviewState
|
||||
|
||||
Standard and diff drafts use `{ surfaces, explicitExclusions, deferred }`. Give surfaces meaningful labels and schema-defined dispositions, preserving saved surface IDs in updates. Retain reasons and evidence for rejected, not-applicable, and follow-up work. Open questions may be strings or `{ question, followUpPrompt? }` objects. An open question does not prevent the configured review from finishing.
|
||||
|
||||
Preserve each saved deferred `id` or `candidateId`, use each deferred ID only once, and copy IDs assigned by the draft response into later updates. Close a generic saved task in the final Standard or diff draft with `reviewState.resolvedDeferred: [{ id, reason }]`; keep unfinished tasks deferred and update linked surfaces by ID. Candidate-linked tasks close through findings or terminal dispositions. Deep parents cannot close worker tasks; original checkpoints remain unchanged.
|
||||
Preserve each saved deferred `id` or `candidateId`, use each deferred ID only once, and copy IDs assigned by the draft response into later updates. Omitting a saved task from the final draft does not by itself close it. Close a generic saved task in the final Standard or diff draft with `reviewState.resolvedDeferred: [{ id, reason }]`; keep unfinished tasks deferred and update linked surfaces by ID. Candidate-linked tasks close through findings or terminal dispositions. Deep parents cannot close worker tasks; original checkpoints remain unchanged.
|
||||
|
||||
The workbench assigns IDs to new surfaces and derives a finding's `identity` when omitted. Review notes do not measure file coverage; do not add reviewed-surface tables or file-coverage claims to the report. Omit host-owned target/scope metadata, `reviewState.inventoryStrategy`, `reviewState.receiptRefs`, and each active finding's `findingId`, `occurrenceId` and `fingerprints` from semantic drafts. SDK-authored canonical files follow `scan-contract.md` and the SDK's supplied metadata.
|
||||
|
||||
|
||||
Generated
+9
@@ -0,0 +1,9 @@
|
||||
lockfileVersion: '9.0'
|
||||
|
||||
settings:
|
||||
autoInstallPeers: true
|
||||
excludeLinksFromLockfile: false
|
||||
|
||||
importers:
|
||||
|
||||
.: {}
|
||||
@@ -58,7 +58,8 @@ an integer from 1 through 10 (default: 3), validated before any host work.
|
||||
For each record the CLI emits that many sequential `method: "review.run"` requests,
|
||||
each with a unique request ID and params containing `requestId`, `stage: "severity-classification"`, explicit
|
||||
`model` and `effort`, `trustedInstructions`, untrusted report/rubric `prompt`, and
|
||||
an output JSON `schema`. The host must authorize the requested model and effort,
|
||||
an output JSON `schema`. The SDK and CLI forward the `effort` string unchanged.
|
||||
The host must authorize the requested model and effort,
|
||||
create a fresh independent review context, preserve the instruction/data boundary,
|
||||
and disable tools, repository access, browsing, and source inspection.
|
||||
A managed-agent host can execute this request directly in its existing session
|
||||
|
||||
@@ -2328,9 +2328,11 @@ or the [Bedrock workflow](https://github.com/openai/codex-security/blob/main/exa
|
||||
|
||||
### Local pre-commit checks
|
||||
|
||||
`install-hook` checks staged and unstaged changes, blocking the commit on scan
|
||||
failure or findings at/above its threshold (`high` by default). Use required CI
|
||||
for enforcement; local hooks are optional.
|
||||
The generated hook runs a `--working-tree` scan and blocks the commit on scan
|
||||
failure or findings at or above its threshold (`high` by default). It uses the
|
||||
checkout's normal index for staged and unstaged changes, so it can include changes
|
||||
outside a partial commit and miss content staged only in a separate index.
|
||||
Use required CI for enforcement because local hooks are optional.
|
||||
|
||||
Install the CLI outside the target repository and run that copy directly. `npx`
|
||||
can select a repository-local package. Before installation, inspect:
|
||||
@@ -2348,11 +2350,12 @@ codex-security install-hook /path/to/repository
|
||||
```
|
||||
|
||||
To migrate an existing generated hook, verify it is a regular file used only by
|
||||
this repository and contains only the generated command. Preserve its severity.
|
||||
The installer can update older `npx` hooks when the severity matches. New hooks
|
||||
record absolute Node/CLI paths. If those change, back up and remove the verified
|
||||
generated hook, then reinstall with the same threshold. Restore the backup if
|
||||
installation fails. The installer respects `core.hooksPath`.
|
||||
this repository and contains only the generated commands. Rerun `install-hook`
|
||||
with `--fail-on-severity` set to its original threshold. It recognizes the legacy
|
||||
`npx` hook and supported earlier templates with matching absolute Node and CLI
|
||||
paths. If it refuses to overwrite the verified hook, back it up, remove it and
|
||||
reinstall with the same threshold. Restore the backup if installation fails. The installer
|
||||
respects `core.hooksPath`.
|
||||
|
||||
## Import SonarQube Cloud issues
|
||||
|
||||
|
||||
@@ -46,15 +46,7 @@ export const classifySeverityRecordsInputSchema = z
|
||||
version: z.literal(1),
|
||||
rubric: severityRubricSnapshotSchema.optional(),
|
||||
model: text,
|
||||
effort: z.enum([
|
||||
"minimal",
|
||||
"low",
|
||||
"medium",
|
||||
"high",
|
||||
"xhigh",
|
||||
"max",
|
||||
"ultra",
|
||||
]),
|
||||
effort: z.string(),
|
||||
records: z.array(
|
||||
z
|
||||
.object({
|
||||
|
||||
@@ -230,6 +230,8 @@ async function discover(
|
||||
if (entry.name.startsWith("~$")) continue;
|
||||
// macOS writes "._" metadata files when copying to other filesystems.
|
||||
if (entry.name.startsWith("._")) continue;
|
||||
// LibreOffice keeps a ".~lock.<name>#" file next to each open document.
|
||||
if (/^\.~lock\..+#$/s.test(entry.name)) continue;
|
||||
if (!DOCUMENT_EXTENSIONS.has(extname(path).toLowerCase())) {
|
||||
const bytes = await readFile(path, {
|
||||
flag: constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0),
|
||||
|
||||
@@ -12,7 +12,7 @@ import { capture, dependencies } from "./cli-fixtures.js";
|
||||
|
||||
const hash = (value: string) =>
|
||||
createHash("sha256").update(value, "utf8").digest("hex");
|
||||
function input(): ClassifySeverityRecordsInput & {
|
||||
function input(effort = "high"): ClassifySeverityRecordsInput & {
|
||||
rubric: NonNullable<ClassifySeverityRecordsInput["rubric"]>;
|
||||
} {
|
||||
const markdown =
|
||||
@@ -23,7 +23,7 @@ function input(): ClassifySeverityRecordsInput & {
|
||||
version: 1,
|
||||
rubric: { revision: 4, markdown, sha256: hash(markdown) },
|
||||
model: "synthetic-model",
|
||||
effort: "high",
|
||||
effort,
|
||||
records: [
|
||||
{
|
||||
id: "canonical-one",
|
||||
@@ -46,8 +46,9 @@ function answer(request: SeverityClassificationReviewRequest) {
|
||||
};
|
||||
}
|
||||
|
||||
test("binds assessments to exact UTF-8 snapshots without rewriting the original report", async () => {
|
||||
const original = input();
|
||||
const efforts = ["", "\t", " synthetic-effort "];
|
||||
test.each(efforts)("preserves UTF-8 records and effort %p", async (effort) => {
|
||||
const original = input(effort);
|
||||
const before = structuredClone(original);
|
||||
const requests: SeverityClassificationReviewRequest[] = [];
|
||||
const result = await classifySeverityRecords(original, {
|
||||
@@ -55,7 +56,7 @@ test("binds assessments to exact UTF-8 snapshots without rewriting the original
|
||||
async run(request) {
|
||||
requests.push(request);
|
||||
expect(request.model).toBe(original.model);
|
||||
expect(request.effort).toBe("high");
|
||||
expect(request.effort).toBe(original.effort);
|
||||
expect(JSON.parse(request.prompt).rubric).toEqual([
|
||||
original.rubric.markdown,
|
||||
]);
|
||||
@@ -89,6 +90,8 @@ test("binds assessments to exact UTF-8 snapshots without rewriting the original
|
||||
});
|
||||
|
||||
test.each([
|
||||
"missing-effort",
|
||||
"numeric-effort",
|
||||
"rubric-hash",
|
||||
"finding-hash",
|
||||
"duplicate",
|
||||
@@ -99,6 +102,8 @@ test.each([
|
||||
"unsafe-revision",
|
||||
])("rejects %s before any host work", async (scenario) => {
|
||||
const data = input();
|
||||
if (scenario === "missing-effort") Reflect.deleteProperty(data, "effort");
|
||||
if (scenario === "numeric-effort") Reflect.set(data, "effort", 1);
|
||||
if (scenario === "rubric-hash") data.rubric.markdown += " ";
|
||||
if (scenario === "finding-hash") data.records[0]!.findingJson += " ";
|
||||
if (scenario === "duplicate") data.records.push(data.records[0]!);
|
||||
@@ -296,7 +301,7 @@ test.each([
|
||||
capture().stream,
|
||||
deps,
|
||||
);
|
||||
const params: ClassifySeverityRecordsInput = input();
|
||||
const params: ClassifySeverityRecordsInput = input("none");
|
||||
if (scenario === "default-rubric") delete params.rubric;
|
||||
const completed = [
|
||||
"completed",
|
||||
|
||||
@@ -847,16 +847,22 @@ describe("scan knowledge bases", () => {
|
||||
expect(documents).toContain("Boundary � case.\n");
|
||||
});
|
||||
|
||||
test("skips Office owner files while a document is open", async () => {
|
||||
test("skips Office owner files and LibreOffice lock files during discovery", async () => {
|
||||
const root = await temporaryDirectory();
|
||||
await writeFile(join(root, "policy.docx"), docx("Access policy."));
|
||||
await writeFile(join(root, "~$policy.docx"), new Uint8Array(162).fill(1));
|
||||
await writeFile(
|
||||
join(root, ".~lock.policy.docx#"),
|
||||
",Example User,example-host,01.01.2026 09:00,file:///home/example/.config/libreoffice/4;",
|
||||
);
|
||||
await writeFile(join(root, ".~lock.#"), "Named document");
|
||||
|
||||
const knowledgeBase = await prepareKnowledgeBase([root]);
|
||||
temporaryDirectories.track(knowledgeBase.path);
|
||||
|
||||
expect(await extractedDocuments(knowledgeBase.path)).toEqual([
|
||||
expect((await extractedDocuments(knowledgeBase.path)).sort()).toEqual([
|
||||
"Access policy.\n",
|
||||
"Named document",
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
@@ -250,6 +250,27 @@ describe("worker progress events", () => {
|
||||
messageEvent(["Example:", "```text", dispatchMarker, "```"].join("\n")),
|
||||
),
|
||||
).toBeNull();
|
||||
|
||||
const liveDispatch = {
|
||||
phase: "validation",
|
||||
planned: 2,
|
||||
started: 2,
|
||||
} as const;
|
||||
const message = messageEvent(
|
||||
[
|
||||
"~~~text",
|
||||
progressMarker,
|
||||
dispatchMarker,
|
||||
"~~~",
|
||||
liveMarker,
|
||||
`CODEX_SECURITY_WORKER_STATUS ${JSON.stringify(liveDispatch)}`,
|
||||
].join("\n"),
|
||||
);
|
||||
expect(scanProgressUpdatesFromEvent(message)).toEqual([liveProgress]);
|
||||
expect(workerStatusFromEvent(message)).toEqual({
|
||||
kind: "dispatch",
|
||||
...liveDispatch,
|
||||
});
|
||||
});
|
||||
|
||||
test("rejects malformed or overstated file progress", () => {
|
||||
|
||||
Reference in New Issue
Block a user