Skip to content
Closed
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 src/signals/local-branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ function firstCommitTitle(messages: string[] | undefined): string | undefined {

function safeRepoPath(path: string): string {
/* v8 ignore next -- Empty path fallback protects malformed local-git adapters; path redaction is covered by local branch tests. */
return /^(\/Users\/|\/home\/|\/tmp\/|[A-Z]:\/Users\/)/i.test(String(path).replace(/\\/g, "/")) ? "[local path hidden]" : String(path || "(unknown path)").replace(/\\/g, "/");
return /^(\/Users\/|\/home\/|\/root\/|\/tmp\/|[A-Z]:\/Users\/)/i.test(String(path).replace(/\\/g, "/")) ? "[local path hidden]" : String(path || "(unknown path)").replace(/\\/g, "/");
}

export function isTestFile(file: string): boolean {
Expand Down
2 changes: 1 addition & 1 deletion src/signals/redaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// intentionally NOT collapsed onto `PUBLIC_UNSAFE_TERMS`.
export const PUBLIC_UNSAFE_TERMS = String.raw`reward\w*|score\w*|wallet|hotkey|coldkey|mnemonic|farming|payout|ranking|raw[-_\s]?trust|trust[-_\s]?score|private[-_\s]?reviewability|reviewability`;

export const PUBLIC_UNSAFE_PATTERN = new RegExp(String.raw`\b(${PUBLIC_UNSAFE_TERMS})\b|/Users/|/home/|/tmp/|[A-Z]:[\\/]Users[\\/]`, "i");
export const PUBLIC_UNSAFE_PATTERN = new RegExp(String.raw`\b(${PUBLIC_UNSAFE_TERMS})\b|/Users/|/home/|/root/|/tmp/|[A-Z]:[\\/]Users[\\/]`, "i");

/** True iff `text` contains nothing that must stay private — i.e. it is safe to surface on a public GitHub surface. */
export function isPublicSafeText(text: string): boolean {
Expand Down
22 changes: 22 additions & 0 deletions test/unit/local-branch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,28 @@ describe("local branch analysis", () => {
expect(JSON.stringify(analysis.prPacket)).not.toMatch(/reward|score|wallet|hotkey|farming|payout|ranking|trust score|\/Users\/example/i);
});

it("hides a /root/ changed-file path from the public PR packet (regression for #1375)", () => {
const analysis = buildLocalBranchAnalysis({
input: {
login: "oktofeesh1",
repoFullName: repo.fullName,
changedFiles: [{ path: "/root/work/src/cache.ts", additions: 12, deletions: 2, status: "modified" }],
validation: [{ command: "npm test -- cache", status: "passed" }],
},
repo,
issues: [],
pullRequests: [],
profile,
outcomeHistory,
scoringSnapshot,
scoringProfile,
});

expect(analysis.prPacket.markdown).toContain("[local path hidden]");
expect(analysis.prPacket.markdown).not.toContain("/root/work");
expect(JSON.stringify(analysis.prPacket)).not.toContain("/root/work");
});

it("removes Windows home paths from public PR packet title and validation lines", () => {
const analysis = buildLocalBranchAnalysis({
input: {
Expand Down
7 changes: 7 additions & 0 deletions test/unit/redaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,18 @@ describe("isPublicSafeText (#542 shared public/private boundary)", () => {
it("rejects local filesystem paths (posix and Windows)", () => {
expect(isPublicSafeText("/Users/alice/project")).toBe(false);
expect(isPublicSafeText("/home/bob/repo")).toBe(false);
expect(isPublicSafeText("/root/repo")).toBe(false);
expect(isPublicSafeText("/tmp/scratch")).toBe(false);
expect(isPublicSafeText("C:\\Users\\carol\\repo")).toBe(false);
expect(isPublicSafeText("C:/Users/carol/repo")).toBe(false);
});

it("rejects /root/ home paths so a container/CI working tree cannot leak (regression for #1375)", () => {
// The root user's home was the one local-path family the canonical boundary omitted, even though
// miner-dashboard-recommendations.ts already treats /root/ as local. Repro from the issue:
expect(isPublicSafeText("/root/project/src/index.ts")).toBe(false);
});

it("is case-insensitive", () => {
expect(isPublicSafeText("WALLET")).toBe(false);
expect(isPublicSafeText("Payout")).toBe(false);
Expand Down