Ignore symlinked pull request templates#164
Open
skarim wants to merge 1 commit into
Open
Conversation
Template discovery in internal/pr read candidate template paths with os.ReadFile, which follows symlinks. A pull request template that is a symlink (for example .github/pull_request_template.md pointing to a file outside the repository) would therefore be read through to its target, and that target's contents would be used as the PR body by `gh stack submit` and `gh stack link`. Reuse cli/cli's githubtemplate package (already a dependency) for template discovery instead of the hand-rolled path list. It is the same code `gh pr create` uses, and it ignores symlinked templates, so only regular template files inside the repository are read. FindTemplate keeps the same signature, so the submit and link callers are unchanged. Two behavior changes come with the switch: - YAML front-matter is stripped from the template, matching `gh pr create`. - Template filename matching is slightly broader; hyphenated and non-.md variants are now recognized. Add tests for FindTemplate and for the `gh stack submit --auto` and `gh stack link` PR-creation flows to confirm symlinked templates are not followed.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a subtle information-disclosure / correctness issue in PR template discovery. gh stack submit and gh stack link prefill a new PR body from the repository's pull request template; the previous implementation in internal/pr/template.go read candidate paths with os.ReadFile, which follows symlinks — so a symlinked pull_request_template.md pointing outside the repo would be read through to its target. The fix reuses cli/cli's githubtemplate package (the same code gh pr create uses), which ignores symlinked templates while keeping FindTemplate's signature intact.
Changes:
- Replaced the manual candidate-path list +
os.ReadFileloop withgithubtemplate.FindLegacy+githubtemplate.ExtractContents(trimmed), so symlinked templates are skipped. - Side effects of the reuse: YAML front-matter is now stripped (matching
gh pr create), and filename matching is broadened to hyphenated/non-.mdvariants. - Added tests for symlink-ignoring, front-matter stripping, and hyphenated names at the unit level, plus end-to-end coverage in
submitandlink.
Show a summary per file
| File | Description |
|---|---|
internal/pr/template.go |
Delegates FindTemplate to githubtemplate.FindLegacy/ExtractContents, dropping the symlink-following os.ReadFile loop. |
internal/pr/template_test.go |
Adds unit tests for symlink-ignored, front-matter-stripped, and hyphenated-name templates. |
cmd/submit_test.go |
Adds submit --auto test confirming a symlinked template is not read into the PR body (footer fallback used). |
cmd/link_test.go |
Adds link test confirming a symlinked template is not read into the PR body (footer fallback used). |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Medium
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
gh stack submitandgh stack linkprefill a new PR's body from the repository's pull request template. Template discovery ininternal/prread each candidate path withos.ReadFile, which follows symlinks. A template that is a symlink — for example.github/pull_request_template.mdpointing to a file outside the repository — was therefore read through to its target, and that file's contents were used as the PR body.This reuses
cli/cli'sgithubtemplatepackage (already a dependency) for template discovery instead of the hand-rolled path list. It's the same codegh pr createuses, and it skips symlinked templates, so only regular template files inside the repository are read.FindTemplatekeeps the same signature, so thesubmitandlinkcallers are unchanged.Behavior
submit/linkfall back to the default PR body (commit message + footer) as if no template were present.githubtemplate:gh pr create.pull-request-template.md) and non-.mdvariants are now recognized.Changes
internal/pr/template.go:FindTemplatenow delegates togithubtemplate.FindLegacy+githubtemplate.ExtractContents(trimmed), replacing the manual candidate-path list andos.ReadFileloop. Symlinked templates are skipped.Testing
internal/pr/template_test.go:cmd/submit_test.go/cmd/link_test.go:gh stack submit --autoandgh stack linkcases confirming a symlinked template is not read into the created PR body and the default footer body is used instead.Stack created with GitHub Stacks CLI • Give Feedback 💬