Skip to content
Closed
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
9 changes: 8 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node
import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { dirname, join, basename } from "node:path";
import { dirname, join, basename, isAbsolute, normalize } from "node:path";
import pc from "picocolors";
import { diff } from "./diff.js";
import { parseContent, keyRowsByColumn, detectFormat, type Format } from "./parse.js";
Expand Down Expand Up @@ -279,6 +279,13 @@ function parseArgs(argv: string[]): Args {

function readInput(file: string): string {
if (file === "-") return readFileSync(0, "utf8");
// Reject relative path-traversal sequences (e.g. "../../etc/passwd") so a
// path derived from untrusted input (git diff output, workflow args) can't
// escape the intended working directory. Explicit absolute paths are still
// honored, since pointing confdiff at a file elsewhere on disk is expected.
if (!isAbsolute(file) && normalize(file).split(/[/\\]/).includes("..")) {
fail(`cannot read "${file}": path traversal is not allowed`);
}
try {
return readFileSync(file, "utf8");
} catch (e) {
Expand Down
Loading