Closed
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens repository template expansion to prevent writes through symlinked directories in the generated path, addressing a symlink-based path traversal risk during .gitea/template processing.
Changes:
- Add a per-path-component symlink check (
ensureNoSymlinkInPath) before writing substituted template files. - Extend
TestProcessGiteaTemplateFilewith a new case covering a symlinked destination directory pointing outside the temp repo.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| services/repository/generate.go | Adds ensureNoSymlinkInPath and uses it to block template writes into symlinked paths. |
| services/repository/generate_test.go | Adds a regression test ensuring symlinked directories cannot cause out-of-tree writes. |
Comments suppressed due to low confidence (1)
services/repository/generate.go:183
ensureNoSymlinkInPatherrors are currently swallowed (return nil) which can hide real filesystem problems (e.g. permission/IO errors) and silently drop a templated file aftertmpFullPathhas already been removed. Consider only skipping on the specific “symlink detected / escapes base” conditions (and optionally logging), while returning unexpected errors to fail the template processing.
if err := ensureNoSymlinkInPath(tmpDir, newLocalPath); err != nil {
return nil
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
|
Fix path resolving #36734 |
wxiaoguang
reviewed
Feb 24, 2026
| generatedContent := generateExpansion(ctx, string(content), templateRepo, generateRepo) | ||
| substSubPath := filePathSanitize(generateExpansion(ctx, tmpDirSubPath, templateRepo, generateRepo)) | ||
| newLocalPath := filepath.Join(tmpDir, substSubPath) | ||
| if err := ensureNoSymlinkInPath(tmpDir, newLocalPath); err != nil { |
Contributor
There was a problem hiding this comment.
The check is incomplete
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.
os.Lstatwill only check the symlink file. But it cannot avoid some directory of the file path is a symlink. This PR fix the possible symlink directory.