Fix path traversal vulnerability in init_from_code template file download - #6830
Merged
Merged
Conversation
…tacks Co-authored-by: trangevi <26490000+trangevi@users.noreply.github.com>
Co-authored-by: trangevi <26490000+trangevi@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] WIP Address feedback on 'init from code' flow implementation
Fix path traversal vulnerability in init_from_code template file download
Feb 20, 2026
trangevi
approved these changes
Feb 20, 2026
trangevi
marked this pull request as ready for review
February 20, 2026 22:36
trangevi
requested review from
JeffreyCA,
hemarina,
rajeshkamal5050,
tg-msft,
therealjohn,
trrwilson,
vhvb1989,
wbreza and
weikanglim
as code owners
February 20, 2026 22:36
rajeshkamal5050
approved these changes
Feb 20, 2026
trangevi
added a commit
that referenced
this pull request
Feb 24, 2026
* Add support for init from code Signed-off-by: trangevi <trangevi@microsoft.com> * Code comment Signed-off-by: trangevi <trangevi@microsoft.com> * Addressing some comments Signed-off-by: trangevi <trangevi@microsoft.com> * make sure src is provided for local code story for now Signed-off-by: trangevi <trangevi@microsoft.com> * some fixes Signed-off-by: trangevi <trangevi@microsoft.com> * Add manual defaulting Signed-off-by: trangevi <trangevi@microsoft.com> * Refactoring a bunch based on expected experience Signed-off-by: trangevi <trangevi@microsoft.com> * broken spinner Signed-off-by: trangevi <trangevi@microsoft.com> * Remove env var print * Add support for --project-id Signed-off-by: trangevi <trangevi@microsoft.com> * Missing env var Signed-off-by: trangevi <trangevi@microsoft.com> * Address feedback Signed-off-by: trangevi <trangevi@microsoft.com> * Switch to public repo Signed-off-by: trangevi <trangevi@microsoft.com> * Changes for existing ACR Signed-off-by: trangevi <trangevi@microsoft.com> * More for existing ACR support Signed-off-by: trangevi <trangevi@microsoft.com> * app insights changes Signed-off-by: trangevi <trangevi@microsoft.com> * Point to branch for now Signed-off-by: trangevi <trangevi@microsoft.com> * tests Signed-off-by: trangevi <trangevi@microsoft.com> * Integrate with azd extension model handling Signed-off-by: trangevi <trangevi@microsoft.com> * Move model handling Signed-off-by: trangevi <trangevi@microsoft.com> * Update cli/azd/extensions/azure.ai.agents/internal/cmd/init_from_code.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Proper http client handling Signed-off-by: trangevi <trangevi@microsoft.com> * Remove custom string matching helpers in favor of strings.Contains (#6829) * Initial plan * Replace containsString/searchString with strings.Contains in test file Co-authored-by: trangevi <26490000+trangevi@users.noreply.github.com> * Revert unrelated go.mod/go.sum changes Co-authored-by: trangevi <26490000+trangevi@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: trangevi <26490000+trangevi@users.noreply.github.com> * cspell Signed-off-by: trangevi <trangevi@microsoft.com> * Fix path traversal vulnerability in init_from_code template file download (#6830) * Initial plan * Use filepath.Clean() for path validation to prevent path traversal attacks Co-authored-by: trangevi <26490000+trangevi@users.noreply.github.com> * Revert unrelated go.mod/go.sum changes Co-authored-by: trangevi <26490000+trangevi@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: trangevi <26490000+trangevi@users.noreply.github.com> * fix: capture error from loadAiCatalog in selectNewModel (#6831) * Initial plan * fix: capture error from loadAiCatalog in selectNewModel Co-authored-by: trangevi <26490000+trangevi@users.noreply.github.com> * fix: revert go.mod/go.sum changes and add user-facing error message for loadAiCatalog failure Co-authored-by: trangevi <26490000+trangevi@users.noreply.github.com> * fix: remove fmt.Printf from loadAiCatalog error path Co-authored-by: trangevi <26490000+trangevi@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: trangevi <26490000+trangevi@users.noreply.github.com> * Code review Signed-off-by: trangevi <trangevi@microsoft.com> * Put the status check before attempting to use the response Signed-off-by: trangevi <trangevi@microsoft.com> * Fix path handling Signed-off-by: trangevi <trangevi@microsoft.com> * Remove unused code Signed-off-by: trangevi <trangevi@microsoft.com> * cspell Signed-off-by: trangevi <trangevi@microsoft.com> * Address PR comment Signed-off-by: trangevi <trangevi@microsoft.com> --------- Signed-off-by: trangevi <trangevi@microsoft.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: trangevi <26490000+trangevi@users.noreply.github.com>
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.
f.Pathfrom the GitHub API tree response was written directly viaos.WriteFilewith only a weakstrings.Contains(entry.Path, "..")guard, which doesn't catch normalized traversal patterns likeinfra/./../../etc/passwd.Changes
strings.Contains(entry.Path, "..")withfilepath.Clean()normalization followed bystrings.HasPrefix(cleanPath, "..")andfilepath.IsAbs(cleanPath)checks — catches traversal attempts that survive raw string matchingtemplateFileInfo.Pathso all downstream uses (os.Stat, download URL construction,os.MkdirAll,os.WriteFile) operate on the normalized value rather than the raw API response string💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.