Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/typescript/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function errorMessage(error: unknown): string {
export function safeErrorMessage(error: unknown): string {
const message = errorMessage(error);
const recognizableCredential =
/(?:\b(?:sk-(?:proj-)?|github_pat_|gh[pousr]_|npm_)\S+|\b(?:bearer|basic|token)(?:\s|%20|\+)+\S+|:\/\/[^\s/@]+@|-----BEGIN [A-Z ]*PRIVATE KEY(?: BLOCK)?-----)/iu.test(
/(?:\b(?:sk-(?:proj-)?|github_pat_|gh[pousr]_|npm_)\S+|\b(?:bearer|basic)(?:\s|%20|\+)+\S+|(?:^|[:="'\r\n])\s*token(?:\s|%20|\+)+\S+|:\/\/[^\s/@]+@|-----BEGIN [A-Z ]*PRIVATE KEY(?: BLOCK)?-----)/iu.test(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep redacting tokens that follow ordinary prose

When an error embeds a credential as request failed with token SYNTHETIC_SECRET or invalid access token SYNTHETIC_SECRET, the revised expression no longer matches because token is preceded by whitespace rather than the start of the string or one of :="'. safeErrorMessage consequently returns the credential unchanged at persistence and display boundaries, regressing the previous word-boundary protection; distinguish noun phrases such as “token cache” without requiring credential-bearing token VALUE phrases to follow special punctuation.

AGENTS.md reference: sdk/typescript/AGENTS.md:L23-L23

Useful? React with 👍 / 👎.

message,
);
const assignments = message.matchAll(
Expand Down
5 changes: 2 additions & 3 deletions sdk/typescript/src/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
import {
CodexSecurityError,
ConfigurationError,
errorMessage,
safeErrorMessage,
} from "./errors.js";
import {
Expand Down Expand Up @@ -504,7 +503,7 @@ export async function publishScanInternal(
dependencies.recordPublishedIssues ?? recordPublishedIssues
)(preparedScan, handoffResults.created, environment);
} catch (cause) {
persistenceFailure = { cause, detail: errorMessage(cause) };
persistenceFailure = { cause, detail: safeErrorMessage(cause) };
}
}
result.counts.created = result.created.length;
Expand Down Expand Up @@ -538,7 +537,7 @@ export async function publishScanInternal(
try {
await saveReceipt(result, environment);
} catch (error) {
const detail = errorMessage(error);
const detail = safeErrorMessage(error);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve ordinary receipt failure diagnostics

When receipt storage fails with an ordinary diagnostic containing the noun token, such as the newly tested Synthetic token cache unavailable, safeErrorMessage mistakes the following word for a credential and replaces the entire actionable I/O error with [redacted]. No credential value is present in this scenario, so operators lose the cause of a failed recovery receipt; narrow the credential match or retain the original diagnostic for these local persistence failures.

AGENTS.md reference: AGENTS.md:L21-L24

Useful? React with 👍 / 👎.

throw new CodexSecurityError(
`${reason} and its partial receipt could not be saved: ${detail}. ${recoveryDetails}`,
{ cause: error },
Expand Down
6 changes: 6 additions & 0 deletions sdk/typescript/tests-ts/errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ describe("error messages", () => {
test("omits credential-bearing messages at output boundaries", () => {
for (const message of [
"request failed: token=SYNTHETIC_TOKEN",
"token SYNTHETIC_TOKEN",
"request failed: token SYNTHETIC_TOKEN",
'{"message":"token SYNTHETIC_TOKEN"}',
"Authorization: Bearer sk-proj-SYNTHETIC_KEY_123",
'upstream failed: {"clientSecret":"correct horse battery staple"}',
JSON.stringify(JSON.stringify({ clientSecret: "SYNTHETIC_SECRET" })),
Expand All @@ -98,6 +101,9 @@ describe("error messages", () => {
);
expect(safeErrorMessage("author=Michael")).toBe("author=Michael");
expect(safeErrorMessage("signal=active")).toBe("signal=active");
expect(safeErrorMessage("Synthetic token cache unavailable")).toBe(
"Synthetic token cache unavailable",
);
expect(safeErrorMessage("design=complete")).toBe("design=complete");
expect(safeErrorMessage('worker 1: rg -n "password" src/login.ts')).toBe(
'worker 1: rg -n "password" src/login.ts',
Expand Down
95 changes: 94 additions & 1 deletion sdk/typescript/tests-ts/publication-integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,100 @@ describe("database-backed Linear publication integration", () => {
expect(await artifactDigests(completed.scanDirectory)).toEqual(sealed);
});

test("retains uncertain mutations when events.jsonl already exists without losing verified SQLite publications", async () => {
const completed = await fixture(2);
const sealed = await artifactDigests(completed.scanDirectory);
const stdout = capture();
const stderr = capture();
const cli = dependencies({ environment: completed.environment });
let handoffFile = "";
let events = "";

cli.publishScan = async (directory, options) =>
publishScanInternal(directory, options, {
environment: completed.environment,
resolveCodex: () => ({ command: "synthetic-codex" }),
runCodex: async (_command, _args, prompt) => {
const payload = await publicationPayload(prompt);
handoffFile = payload.handoffFile;
await writeFile(
join(dirname(handoffFile), "events.jsonl"),
"Existing event log\n",
{ flag: "wx", mode: 0o600 },
);
events = payload.batches[0]!.map((finding, index) =>
JSON.stringify({
type: "item.completed",
item: {
id: `tool-${index}`,
type: "mcp_tool_call",
server: "codex_apps",
tool: "linear.save_issue",
arguments:
index === 0
? finding.arguments
: { ...finding.arguments, priority: 4 },
status: "completed",
result: {
content: [],
structured_content: { identifier: `SEC-${901 + index}` },
},
},
}),
).join("\n");
return { exitCode: 0, stdout: events, stderr: "" };
},
});

expect(
await main(
[
"publish",
"scan",
completed.scanDirectory,
"--to",
"linear",
"--linear-team",
OPTIONS.teamId,
"--project",
OPTIONS.projectId,
"--json",
],
stdout.stream,
stderr.stream,
cli,
),
).toBe(2);

expect(stdout.text()).toBe("");
expect(stderr.text()).toContain(
"could not verify every completed mutation",
);
expect(stderr.text()).toContain(handoffFile);
expect(
storedPublications(completed).map(({ external_id }) => external_id),
).toEqual(["SEC-901"]);
const receipt = JSON.parse(
await readFile(receiptPath(completed), "utf8"),
) as PublishScanResult;
expect(receipt.indeterminate).toBe(true);
expect(receipt.counts).toEqual({ findings: 2, created: 1, failed: 1 });
expect(receipt.created[0]?.issueIdentifier).toBe("SEC-901");
const eventFiles = (await readdir(dirname(handoffFile))).filter(
(name) => name.startsWith("events-") && name.endsWith(".jsonl"),
);
expect(eventFiles).toHaveLength(1);
const eventsFile = join(dirname(handoffFile), eventFiles[0]!);
expect(await readFile(eventsFile, "utf8")).toBe(`${events}\n`);
expect(receipt.warnings).toContainEqual(
expect.stringContaining(eventsFile),
);
expect(
await readFile(join(dirname(handoffFile), "events.jsonl"), "utf8"),
).toBe("Existing event log\n");
expect(await artifactDigests(completed.scanDirectory)).toEqual(sealed);
});

test.each([false, true])(
"keeps conflicting connector identities out of CLI history and retains recovery evidence with skipExisting=%s",
async (skipExisting) => {
Expand Down Expand Up @@ -1218,7 +1312,6 @@ for (;;) Atomics.wait(waiter, 0, 0, 1000);`,
killTestProcess(descendantPid);
}
}, 30_000);

test("recovers verified SQLite publications before an interrupted CLI exits", async () => {
const completed = await fixture(3);
const sealed = await artifactDigests(completed.scanDirectory);
Expand Down
Loading
Loading