Skip to content

Commit ee2e29d

Browse files
fix(miner): reject path-traversal repo segments in 4 remaining normalizeRepoFullName parsers
contribution-profile-cache.ts, prediction-ledger.ts, replay-snapshot.ts and run-state.ts each defined normalizeRepoFullName but only checked "one slash, both halves non-empty" — a `.`/`..`/control-char owner or repo segment (e.g. "owner/..", "../repo", tab/newline in a segment) passed through and was persisted as a SQLite key / echoed back through the sibling CLIs. #5831 and #7525 already rolled isValidRepoSegment out to the other ten normalizeRepoFullName siblings for exactly this reason; these four were missed. Import and call isValidRepoSegment on both segments, matching the established pattern (claim-ledger.ts, governor-state.ts, portfolio-queue.ts, ...). Add a per-store regression test covering a `.`/`..`/control-char segment. Closes #7795
1 parent 8329069 commit ee2e29d

8 files changed

Lines changed: 27 additions & 0 deletions

packages/loopover-miner/lib/contribution-profile-cache.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
resolveLocalStoreDbPath,
1515
} from "./local-store.js";
1616
import { applySchemaMigrations } from "./schema-version.js";
17+
import { isValidRepoSegment } from "./repo-clone.js";
1718
import {
1819
CONTRIBUTION_PROFILE_CACHE_PURGE_SPEC,
1920
purgeStoreByRepo,
@@ -58,6 +59,7 @@ function normalizeRepoFullName(repoFullName: unknown): string {
5859
const [owner, repo, extra] = repoFullName.trim().split("/");
5960
if (!owner || !repo || extra !== undefined)
6061
throw new Error("invalid_repo_full_name");
62+
if (!isValidRepoSegment(owner) || !isValidRepoSegment(repo)) throw new Error("invalid_repo_full_name");
6163
return `${owner}/${repo}`;
6264
}
6365

packages/loopover-miner/lib/prediction-ledger.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { DatabaseSync } from "node:sqlite";
22
import { normalizeLocalStoreDbPath, openLocalStoreAdapter, resolveLocalStoreDbPath } from "./local-store.js";
33
import { applySchemaMigrations } from "./schema-version.js";
4+
import { isValidRepoSegment } from "./repo-clone.js";
45
import {
56
PREDICTION_LEDGER_PURGE_SPEC,
67
PREDICTION_LEDGER_RETENTION_SPEC,
@@ -87,6 +88,7 @@ function normalizeRepoFullName(repoFullName: string): string {
8788
if (typeof repoFullName !== "string") throw new Error("invalid_repo_full_name");
8889
const [owner, repo, extra] = repoFullName.trim().split("/");
8990
if (!owner || !repo || extra !== undefined) throw new Error("invalid_repo_full_name");
91+
if (!isValidRepoSegment(owner) || !isValidRepoSegment(repo)) throw new Error("invalid_repo_full_name");
9092
return `${owner}/${repo}`;
9193
}
9294

packages/loopover-miner/lib/replay-snapshot.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { join } from "node:path";
22
import { removeWorktree } from "@loopover/engine";
33
import type { WorktreeExecFn, WorktreeRemoveResult } from "@loopover/engine";
44
import { openLocalStoreAdapter, resolveLocalStoreDbPath, normalizeLocalStoreDbPath } from "./local-store.js";
5+
import { isValidRepoSegment } from "./repo-clone.js";
56

67
// Freeze/snapshot mechanism for historical replay targets (#3010). Given a repo and a commit SHA T, exports:
78
// (a) the full working tree checked out AT T via a DETACHED git worktree -- the same isolation primitive
@@ -72,6 +73,7 @@ function normalizeRepoFullName(repoFullName: string): string {
7273
if (typeof repoFullName !== "string") throw new Error("invalid_repo_full_name");
7374
const [owner, repo, extra] = repoFullName.trim().split("/");
7475
if (!owner || !repo || extra !== undefined) throw new Error("invalid_repo_full_name");
76+
if (!isValidRepoSegment(owner) || !isValidRepoSegment(repo)) throw new Error("invalid_repo_full_name");
7577
return `${owner}/${repo}`;
7678
}
7779

packages/loopover-miner/lib/run-state.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { DEFAULT_FORGE_CONFIG } from "./forge-config.js";
33
import { normalizeLocalStoreDbPath, openLocalStoreAdapter, resolveLocalStoreDbPath } from "./local-store.js";
44
import { applySchemaMigrations } from "./schema-version.js";
55
import { RUN_STATE_PURGE_SPEC, purgeStoreByRepo } from "./store-maintenance.js";
6+
import { isValidRepoSegment } from "./repo-clone.js";
67

78
export type RunState = "idle" | "discovering" | "planning" | "preparing";
89

@@ -57,6 +58,7 @@ function normalizeRepoFullName(repoFullName: string): string {
5758
const trimmed = repoFullName.trim();
5859
const [owner, repo, extra] = trimmed.split("/");
5960
if (!owner || !repo || extra !== undefined) throw new Error("invalid_repo_full_name");
61+
if (!isValidRepoSegment(owner) || !isValidRepoSegment(repo)) throw new Error("invalid_repo_full_name");
6062
return `${owner}/${repo}`;
6163
}
6264

test/unit/miner-contribution-profile-cache.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ describe("contribution-profile cache store (#6797)", () => {
158158
expect(() => store.put({ repoFullName: 42 } as never)).toThrow(
159159
"invalid_repo_full_name",
160160
);
161+
// #7795: a `.`/`..`/control-char owner or repo segment must be rejected, matching the sibling stores.
162+
expect(() => store.get("../etc")).toThrow("invalid_repo_full_name");
163+
expect(() => store.get("owner/..")).toThrow("invalid_repo_full_name");
164+
expect(() => store.get("owner/re\tpo")).toThrow("invalid_repo_full_name");
161165
});
162166

163167
it("exposes module-level get/put helpers backed by the default DB path", () => {

test/unit/miner-prediction-ledger.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ describe("miner prediction ledger (#4263)", () => {
6868
it("rejects invalid inputs field by field", () => {
6969
const ledger = tempLedger();
7070
expect(() => ledger.appendPrediction({ ...VALID, repoFullName: "no-slash" })).toThrow(/invalid_repo_full_name/);
71+
// #7795: `.`/`..`/control-char segments must be rejected, matching the sibling stores.
72+
expect(() => ledger.appendPrediction({ ...VALID, repoFullName: "../etc" })).toThrow(/invalid_repo_full_name/);
73+
expect(() => ledger.appendPrediction({ ...VALID, repoFullName: "owner/.." })).toThrow(/invalid_repo_full_name/);
74+
expect(() => ledger.appendPrediction({ ...VALID, repoFullName: "own\ter/repo" })).toThrow(/invalid_repo_full_name/);
7175
expect(() => ledger.appendPrediction({ ...VALID, targetId: 0 })).toThrow(/invalid_target_id/);
7276
expect(() => ledger.appendPrediction({ ...VALID, conclusion: "" })).toThrow(/invalid_conclusion/);
7377
expect(() => ledger.appendPrediction({ ...VALID, engineVersion: "" })).toThrow(/invalid_engine_version/);

test/unit/miner-replay-snapshot.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@ describe("exportReplaySnapshot (#3010)", () => {
160160
expect(snapshot.readme).toEqual({ filename: "README.md", content: "# hello\n" });
161161
});
162162

163+
it("rejects a `.`/`..`/control-char repo segment before touching the store (#7795)", () => {
164+
const store = tempStore();
165+
expect(() => store.getSnapshot("../etc", "abc123")).toThrow("invalid_repo_full_name");
166+
expect(() => store.getSnapshot("owner/..", "abc123")).toThrow("invalid_repo_full_name");
167+
expect(() => store.getSnapshot("ow\tner/repo", "abc123")).toThrow("invalid_repo_full_name");
168+
});
169+
163170
it("returns the cached snapshot on a repeat export of the same (repo, commit) pair, without calling git again", async () => {
164171
const store = tempStore();
165172
const first = scriptedExec(happyPathScripts());

test/unit/miner-run-state.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ describe("loopover-miner run-state store (#2289)", () => {
129129
try {
130130
expect(() => store.getRunState("not-a-full-name")).toThrow("invalid_repo_full_name");
131131
expect(() => store.setRunState("owner/repo/extra", "idle")).toThrow("invalid_repo_full_name");
132+
// #7795: `.`/`..`/control-char segments must be rejected, matching the sibling stores.
133+
expect(() => store.setRunState("../etc", "idle")).toThrow("invalid_repo_full_name");
134+
expect(() => store.setRunState("owner/..", "idle")).toThrow("invalid_repo_full_name");
135+
expect(() => store.getRunState("ow\tner/repo")).toThrow("invalid_repo_full_name");
132136
expect(() => store.setRunState("owner/repo", "blocked" as never)).toThrow("invalid_run_state");
133137
expect(store.getRunState("owner/repo")).toBeNull();
134138
} finally {

0 commit comments

Comments
 (0)