Skip to content

fix(template): never write a rendered path outside the output directory - #185

Merged
Ilyes512 merged 3 commits into
mainfrom
fix/GH-183-bounds-check-rendered-paths
Nov 24, 2026
Merged

Ilyes512 merged 3 commits into
mainfrom
fix/GH-183-bounds-check-rendered-paths

Conversation

@Ilyes512

Copy link
Copy Markdown
Member

Closes #183

Summary

  • Every rendered file and directory path must pass filepath.IsLocal; a .. that stays inside is kept (a/../b/x.txt → b/x.txt)
  • Local templates skip an escaping file, or a directory with its subtree, with a warning naming the source and rendered path
  • Cloned templates (specs use <git-url>, and registered templates whose metadata records a remote repository, so template download + template use is covered) abort naming every escaping path; nothing reaches the target
  • template validate reports escaping paths rendered with the schema defaults and sets the new exit bit 16

Decisions and skipped steps

  • The open question from the issue is not implemented: a user-supplied value (--arg, --values, prompt) that makes a path escape is skipped with a warning for local templates, not an error; attributing a rendered path to its input source would need its own design
  • A registered template without __metadata.json is treated as local
  • On Unix an absolute rendered path is still skipped silently by the existing empty-segment check, which IsLocal runs after (as the issue specifies) so conditional directories keep working; nothing is written outside the output. Filed as An absolute rendered file name is dropped silently on Unix #184

…ry (GH-183)

Execute requires filepath.IsLocal on every rendered path. A local template skips an escaping file or directory subtree with a warning; a cloned template (specs use <git-url>, or a registry entry with a remote repository) aborts naming every such path, before anything reaches the target.
…H-183)

template validate warns about each path that renders outside the output with the schema defaults and sets exit bit 16.
@Ilyes512
Ilyes512 merged commit d050145 into main Nov 24, 2026
8 checks passed
@Ilyes512
Ilyes512 deleted the fix/GH-183-bounds-check-rendered-paths branch November 24, 2026 16:31
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.

Rendered file names are not bounds-checked: a template can write outside the output directory

1 participant