Skip to content

fix(cli): enforce project-root realpath containment in format - #2486

Open
rafal-hawrylak wants to merge 2 commits into
mainfrom
fix/format-realpath-containment
Open

rafal-hawrylak wants to merge 2 commits into
mainfrom
fix/format-realpath-containment

Conversation

@rafal-hawrylak

Copy link
Copy Markdown
Collaborator

dataform format now resolves every matched file to its real path and refuses files outside the project directory. Before this, symlinks under definitions or includes and --actions patterns containing parent-directory segments could read or overwrite files outside the project.

Behavior change: projects that symlink files from outside the project directory now get a per-file error and exit code 1 from dataform format.

The containment check from ModuleResolver moves to common/vm/path_utils so both callers share it.

dataform format now resolves every matched file to its real path and refuses files outside the project directory. Before this, symlinks under definitions or includes and --actions patterns containing parent-directory segments could read or overwrite files outside the project.

Behavior change: projects that symlink files from outside the project directory now get a per-file error and exit code 1 from dataform format.

The containment check from ModuleResolver moves to common/vm/path_utils so both callers share it.
@rafal-hawrylak
rafal-hawrylak requested a review from a team as a code owner November 24, 2026 14:25
@rafal-hawrylak
rafal-hawrylak requested review from Ford544, apilaskowski and mbiernacik and removed request for a team November 24, 2026 14:25
try {
const filePath = path.resolve(argv.projectDir, filename);
// Symbolic links and ".." patterns must not reach files outside the project.
if (!isRealPathContained(fs.realpathSync(filePath), realProjectRoot)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also honor the project's allowedExternalPaths, like ModuleResolver.isPathContained? Otherwise projects that compile fine with shared external includes now fail format. Separately: consider resolving once and using the real path for the read/write too, so a symlink swap between the check and formatFile can't redirect the write.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants