Skip to content

Commit e52ecc7

Browse files
fix(miner): apply isValidRepoSegment to four normalizeRepoFullName parsers (#7795)
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent e7e10e7 commit e52ecc7

8 files changed

Lines changed: 28 additions & 0 deletions

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
openLocalStoreAdapter,
1414
resolveLocalStoreDbPath,
1515
} from "./local-store.js";
16+
import { isValidRepoSegment } from "./repo-clone.js";
1617
import { applySchemaMigrations } from "./schema-version.js";
1718
import {
1819
CONTRIBUTION_PROFILE_CACHE_PURGE_SPEC,
@@ -58,6 +59,8 @@ 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))
63+
throw new Error("invalid_repo_full_name");
6164
return `${owner}/${repo}`;
6265
}
6366

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { DatabaseSync } from "node:sqlite";
22
import { normalizeLocalStoreDbPath, openLocalStoreAdapter, resolveLocalStoreDbPath } from "./local-store.js";
3+
import { isValidRepoSegment } from "./repo-clone.js";
34
import { applySchemaMigrations } from "./schema-version.js";
45
import {
56
PREDICTION_LEDGER_PURGE_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
@@ -1,6 +1,7 @@
11
import type { DatabaseSync } from "node:sqlite";
22
import { DEFAULT_FORGE_CONFIG } from "./forge-config.js";
33
import { normalizeLocalStoreDbPath, openLocalStoreAdapter, resolveLocalStoreDbPath } from "./local-store.js";
4+
import { isValidRepoSegment } from "./repo-clone.js";
45
import { applySchemaMigrations } from "./schema-version.js";
56
import { RUN_STATE_PURGE_SPEC, purgeStoreByRepo } from "./store-maintenance.js";
67

@@ -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: path-traversal / invalid-character segments must fail closed like claim-ledger (#5831).
162+
expect(() => store.get("../etc")).toThrow("invalid_repo_full_name");
163+
expect(() => store.get("o/..")).toThrow("invalid_repo_full_name");
164+
expect(() => store.put({ repoFullName: "o baz/a" } as never)).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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ describe("miner prediction ledger (#4263)", () => {
7575
expect(() => ledger.appendPrediction({ ...VALID, readinessScore: Number.NaN })).toThrow(/invalid_readiness_score/);
7676
});
7777

78+
it("REGRESSION (#7795): rejects path-traversal or invalid-character repo segments", () => {
79+
const ledger = tempLedger();
80+
expect(() => ledger.appendPrediction({ ...VALID, repoFullName: "../etc" })).toThrow(/invalid_repo_full_name/);
81+
expect(() => ledger.appendPrediction({ ...VALID, repoFullName: "o/.." })).toThrow(/invalid_repo_full_name/);
82+
expect(() => ledger.appendPrediction({ ...VALID, repoFullName: "o baz/a" })).toThrow(/invalid_repo_full_name/);
83+
});
84+
7885
it("scopes readPredictions by repo, preserving insertion order", () => {
7986
const ledger = tempLedger();
8087
ledger.appendPrediction({ ...VALID, repoFullName: "owner/repo-a", targetId: 1 });

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,10 @@ describe("exportReplaySnapshot (#3010)", () => {
341341

342342
await expect(exportReplaySnapshot({ repoPath: "/repo", repoFullName: "noslash", commitSha: "a" }, deps)).rejects.toThrow("invalid_repo_full_name");
343343
await expect(exportReplaySnapshot({ repoPath: "/repo", repoFullName: "a/b/c", commitSha: "a" }, deps)).rejects.toThrow("invalid_repo_full_name");
344+
// #7795: path-traversal / invalid-character segments must fail closed like claim-ledger (#5831).
345+
await expect(exportReplaySnapshot({ repoPath: "/repo", repoFullName: "../etc", commitSha: "a" }, deps)).rejects.toThrow("invalid_repo_full_name");
346+
await expect(exportReplaySnapshot({ repoPath: "/repo", repoFullName: "o/..", commitSha: "a" }, deps)).rejects.toThrow("invalid_repo_full_name");
347+
await expect(exportReplaySnapshot({ repoPath: "/repo", repoFullName: "o baz/a", commitSha: "a" }, deps)).rejects.toThrow("invalid_repo_full_name");
344348
});
345349

346350
it("assertExecResult falls back to a generic exit-code message when stderr is entirely absent", async () => {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ describe("loopover-miner run-state store (#2289)", () => {
131131
expect(() => store.setRunState("owner/repo/extra", "idle")).toThrow("invalid_repo_full_name");
132132
expect(() => store.setRunState("owner/repo", "blocked" as never)).toThrow("invalid_run_state");
133133
expect(store.getRunState("owner/repo")).toBeNull();
134+
// #7795: path-traversal / invalid-character segments must fail closed like claim-ledger (#5831).
135+
expect(() => store.getRunState("../etc")).toThrow("invalid_repo_full_name");
136+
expect(() => store.setRunState("o/..", "idle")).toThrow("invalid_repo_full_name");
137+
expect(() => store.setRunState("o baz/a", "idle")).toThrow("invalid_repo_full_name");
134138
} finally {
135139
store.close();
136140
}

0 commit comments

Comments
 (0)