Skip to content

The fastest browser for AI agents to run browser automation, built for sharing your logged-in browser state with your AI agents, like Codex or Claude Code, without disturbing you. Zero cost, zero config.

fix(tools): validate issue identifiers before they become paths

Zhuowei Wangd8508894fc89
diff --git a/tools/linear-autofix/src/cli.mjs b/tools/linear-autofix/src/cli.mjs
index 977a970..573b6f9 100755
--- a/tools/linear-autofix/src/cli.mjs
+++ b/tools/linear-autofix/src/cli.mjs
@@ -2,6 +2,7 @@
import { config } from "./config.mjs";
import * as linear from "./linear.mjs";
import {
+ assertIdentifier,
load,
loadAll,
remove,
@@ -57,8 +58,13 @@ async function logged(label, fn) {
async function one(identifier) {
if (!identifier) throw new Error("issue identifier required");
+ assertIdentifier(identifier);
const issue = await linear.fetchIssue(identifier);
if (!issue) throw new Error(`Linear has no issue ${identifier}`);
+ if (issue.identifier !== identifier)
+ throw new Error(
+ `Linear resolved ${identifier} to ${issue.identifier}; use the canonical identifier`,
+ );
return { issue, record: reconcile(upsertFromIssue(issue), issue) };
}
@@ -68,11 +74,18 @@ async function one(identifier) {
* labels. The remote branch goes only with --remote, and only when no PR on
* it is open.
*/
-async function reset(identifier, deleteRemote) {
- if (!identifier) throw new Error("issue identifier required");
+async function reset(requested, deleteRemote) {
+ if (!requested) throw new Error("issue identifier required");
+ assertIdentifier(requested);
+ const issue = await linear.fetchIssue(requested);
+ if (!issue) throw new Error(`Linear has no issue ${requested}`);
+ // Every path below is built from Linear's canonical identifier, not from argv.
+ const identifier = assertIdentifier(issue.identifier);
+ if (identifier !== requested)
+ throw new Error(
+ `Linear resolved ${requested} to ${identifier}; rerun with the canonical identifier`,
+ );
const record = load(identifier);
- const issue = await linear.fetchIssue(identifier);
- if (!issue) throw new Error(`Linear has no issue ${identifier}`);
const branch = record?.branch ?? issue.branchName;
const ref = {
id: issue.id,
@@ -164,7 +177,7 @@ async function main([command, arg]) {
case "reset":
return reset(arg, process.argv.includes("--remote"));
case "retry": {
- const record = load(arg);
+ const record = load(assertIdentifier(arg));
if (!record) throw new Error(`no record for ${arg}`);
record.consecutiveErrors = 0;
const open = await github.findPr(record.branch);
diff --git a/tools/linear-autofix/src/state.mjs b/tools/linear-autofix/src/state.mjs
index 0f24cb6..f425f3f 100644
--- a/tools/linear-autofix/src/state.mjs
+++ b/tools/linear-autofix/src/state.mjs
@@ -22,8 +22,18 @@ export function ensureStateDir() {
fs.mkdirSync(path.join(config.stateDir, "runs"), { recursive: true });
}
+const IDENTIFIER = /^[A-Z][A-Z0-9]{0,15}-\d{1,8}$/;
+
+/** A Linear identifier such as CITRO-2908; anything else is refused before it reaches a path. */
+export function assertIdentifier(identifier) {
+ if (typeof identifier !== "string" || !IDENTIFIER.test(identifier)) {
+ throw new Error(`invalid issue identifier: ${JSON.stringify(identifier)}`);
+ }
+ return identifier;
+}
+
export function recordPath(identifier) {
- return path.join(issuesDir(), `${identifier}.json`);
+ return path.join(issuesDir(), `${assertIdentifier(identifier)}.json`);
}
export function load(identifier) {
@@ -186,7 +196,7 @@ export function runDir(identifier, stage) {
const dir = path.join(
config.stateDir,
"runs",
- identifier,
+ assertIdentifier(identifier),
`${new Date().toISOString().replace(/[:.]/g, "-")}-${stage}`,
);
fs.mkdirSync(dir, { recursive: true });
@@ -194,7 +204,7 @@ export function runDir(identifier, stage) {
}
export function worktreePath(identifier) {
- return path.join(config.stateDir, "worktrees", identifier);
+ return path.join(config.stateDir, "worktrees", assertIdentifier(identifier));
}
export function truncate(text, max = 160) {
diff --git a/tools/linear-autofix/src/tick.test.mjs b/tools/linear-autofix/src/tick.test.mjs
index eac9877..d0d175e 100644
--- a/tools/linear-autofix/src/tick.test.mjs
+++ b/tools/linear-autofix/src/tick.test.mjs
@@ -108,3 +108,20 @@ test("the tick lock is exclusive, stale locks are reclaimed and the STOP file is
assert.equal(state.stopRequested(), true);
state.setStop(false);
});
+
+test("identifiers are validated before they become paths", () => {
+ assert.throws(
+ () => state.recordPath("../etc/passwd"),
+ /invalid issue identifier/,
+ );
+ assert.throws(
+ () => state.worktreePath("CITRO-1/../x"),
+ /invalid issue identifier/,
+ );
+ assert.throws(
+ () => state.assertIdentifier("citro-1"),
+ /invalid issue identifier/,
+ );
+ assert.equal(state.assertIdentifier("CL-556"), "CL-556");
+ assert.equal(state.assertIdentifier("CITRO-2908"), "CITRO-2908");
+});