Skip to content
Merged
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
5 changes: 3 additions & 2 deletions scripts/graphify-cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
} from "./graphify-output-sanitize.mjs";
import {
hasPrivateLocalPath,
revealsMachineIdentity,
sanitizeKnownMetaKimHomeAliases,
} from "./graphify-private-path.mjs";
import {
Expand Down Expand Up @@ -688,7 +689,7 @@ function checkGraphFreshness(cwd = process.cwd(), runtimeBinding = null) {
}

const reportRaw = readFileSync(reportPath, "utf8");
if (hasPrivateLocalPath(reportRaw)) {
if (revealsMachineIdentity(reportRaw)) {
fail("GRAPH_REPORT.md exposes a private local path; rebuild after sanitizing upstream output.");
return false;
}
Expand Down Expand Up @@ -892,7 +893,7 @@ function stampGraphFreshness(cwd = process.cwd(), runtimeBinding = null) {
if (existsSync(reportPath)) {
const reportRaw = readFileSync(reportPath, "utf8");
const sanitizedReport = sanitizeKnownMetaKimHomeAliases(reportRaw);
if (hasPrivateLocalPath(sanitizedReport)) {
if (revealsMachineIdentity(sanitizedReport)) {
fail("GRAPH_REPORT.md exposes a private local path; refusing to stamp unsafe output.");
return false;
}
Expand Down
12 changes: 12 additions & 0 deletions scripts/graphify-private-path.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ export function hasPrivateLocalPath(value) {
);
}

// Identity-bearing paths only: a drive letter, a UNC host, or an absolute home
// root all embed a real user or machine name. A bare `~/` does not — it is
// byte-identical on every machine, so documentation that legitimately writes
// `~/.claude/hooks/` is not a leak. `hasPrivateLocalPath` stays broader on
// purpose: its tilde branch is the fail-closed backstop for home-relative
// strings that `sanitizeKnownMetaKimHomeAliases` refused to rewrite.
export function revealsMachineIdentity(value) {
return typeof value === "string" &&
/(?:(?:^|[^A-Za-z0-9_])[A-Za-z]:[\\/]|\\\\[^\\\s]+\\|\/(?:Users|home|root)\/)/u
.test(value);
}

export function sanitizeKnownMetaKimHomeAliases(value) {
if (typeof value !== "string" || !value.includes("~/.meta-kim")) return value;
return value.replace(
Expand Down
27 changes: 27 additions & 0 deletions tests/setup/graphify-output-sanitize.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from "../../scripts/graphify-output-sanitize.mjs";
import {
hasPrivateLocalPath,
revealsMachineIdentity,
sanitizeKnownMetaKimHomeAliases,
} from "../../scripts/graphify-private-path.mjs";

Expand Down Expand Up @@ -197,6 +198,32 @@ describe("Graphify upstream output sanitizer", () => {
assert.equal(hasPrivateLocalPath("~/.meta-kim/../private"), true);
});

test("report identity check flags real user paths but not documented home aliases", () => {
// GRAPH_REPORT.md faithfully quotes comments from tracked repository files,
// so a documented `~/.claude/...` reference must not fail the report gate.
assert.equal(
revealsMachineIdentity(
"- code:bash (# Detect the Python hook path — it lives in ~/.claude/hooks/)",
),
false,
);
assert.equal(revealsMachineIdentity("~/"), false);
assert.equal(revealsMachineIdentity("~\\AppData"), false);
assert.equal(revealsMachineIdentity("file:///~/notes"), false);
assert.equal(revealsMachineIdentity("https://www.aiking.dev/"), false);

assert.equal(revealsMachineIdentity("/Users/Kim/private.txt"), true);
assert.equal(revealsMachineIdentity("C:/Users/Kim/private.txt"), true);
assert.equal(revealsMachineIdentity("path=C:\\Users\\Kim\\private.txt"), true);
assert.equal(revealsMachineIdentity("\\\\server\\share\\private.txt"), true);
assert.equal(revealsMachineIdentity("/home/kim/private.txt"), true);
assert.equal(revealsMachineIdentity("/root/.config/private"), true);

// The broader predicate keeps its fail-closed backstop for home-relative
// strings that the alias sanitizer refused to rewrite.
assert.equal(hasPrivateLocalPath("~/.meta-kim/../private"), true);
});

test("rewrites both Graphify hyperedge reference surfaces", () => {
const hyperedge = {
id: "Team-Group",
Expand Down