Skip to content

Fix path traversal vulnerability in init-from-code template file download - #6839

Closed
trangevi with Copilot wants to merge 1 commit into
trangevi/init-from-codefrom
copilot/sub-pr-6828
Closed

Fix path traversal vulnerability in init-from-code template file download#6839
trangevi with Copilot wants to merge 1 commit into
trangevi/init-from-codefrom
copilot/sub-pr-6828

Conversation

Copilot AI commented Feb 20, 2026

Copy link
Copy Markdown
Contributor

Paths from the GitHub API tree response were passed directly to os.WriteFile and os.MkdirAll without sanitization, allowing a malicious repository to write files outside the working directory.

Changes

  • Path validation on ingestion: Before adding entries to the files slice, each path from the GitHub tree API is now sanitized and validated:
    • filepath.Clean() normalizes the path
    • filepath.IsAbs() rejects absolute paths
    • strings.HasPrefix(cleanPath, "..") rejects directory traversal attempts
  • Clean path stored in struct: templateFileInfo.Path now holds only the validated cleanPath, so all downstream uses—os.MkdirAll, os.WriteFile—operate on safe values
// Guard against path traversal or unexpected absolute paths
cleanPath := filepath.Clean(entry.Path)
if filepath.IsAbs(cleanPath) || strings.HasPrefix(cleanPath, "..") {
    return fmt.Errorf("invalid path in repository tree: %s", entry.Path)
}

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Address feedback from PR #6828 on init from code flow Fix path traversal vulnerability in init-from-code template file download Feb 20, 2026
Copilot AI requested a review from trangevi February 20, 2026 23:11
@trangevi trangevi closed this Feb 20, 2026
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.

2 participants