Skip to content

Fix critical security vulnerabilities and stability issues#14

Merged
axetroy merged 6 commits into
masterfrom
copilot/review-code-for-improvements
Jan 20, 2026
Merged

Fix critical security vulnerabilities and stability issues#14
axetroy merged 6 commits into
masterfrom
copilot/review-code-for-improvements

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 20, 2026

Addressed multiple security vulnerabilities, crash scenarios, and resource management issues identified through comprehensive code analysis.

Security Fixes

  • Command injection in PTY operations: Shell environment variables were concatenated without escaping. Now properly escaped per shell type (bash/zsh use '"'"', PowerShell doubles quotes, CMD escapes special chars with ^)
  • PATH corruption: Duplicate pathDir entries caused incorrect binary resolution. Removed redundant append
  • Error silencing: Version constraint matching errors were ignored with _, masking failures. Now propagated with context

Stability Fixes

  • Panic on startup: os.UserHomeDir() failure caused panic. Now falls back to temp directory
  • Array bounds panic: cache.go accessed n[1] without length validation. Added bounds check and skip malformed entries
  • Infinite loop: Parent process traversal had no exit condition. Added 100-iteration limit and PID 1 check
  • Filename corruption: Trailing space in Linux ARM64 target broke file paths

Resource Management

  • Defer ordering: Environment variables restored before being set. Moved defer after assignment
  • Goroutine leak: Reader goroutine cleanup had race condition. Separated stop/done channels for proper synchronization
  • File cleanup timing: Downloaded archives deleted before extraction errors could be investigated. Now removed only on success
  • ContentLength handling: Progress bar creation didn't handle -1 (unknown size). Added validation

Code Quality

  • Standardized error wrapping using pkg/errors for stack traces
  • Added error checking for critical write operations
  • Removed redundant permission logic (already set on file creation)

Example of escaping fix:

// Before - vulnerable to injection
ptmx.Write([]byte(fmt.Sprintf("export %s='%s'", k, v)))

// After - shell-specific escaping
escapedValue := strings.Replace(v, "'", "'\"'\"'", -1)
ptmx.Write([]byte(fmt.Sprintf("export %s='%s'", k, escapedValue)))
Original prompt

请检查代码中有哪些需要完善和修改的地方


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 5 commits January 20, 2026 07:49
Co-authored-by: axetroy <9758711+axetroy@users.noreply.github.com>
…andling

Co-authored-by: axetroy <9758711+axetroy@users.noreply.github.com>
…istency

Co-authored-by: axetroy <9758711+axetroy@users.noreply.github.com>
Co-authored-by: axetroy <9758711+axetroy@users.noreply.github.com>
Co-authored-by: axetroy <9758711+axetroy@users.noreply.github.com>
Copilot AI changed the title [WIP] Review code for improvements and modifications Fix critical security vulnerabilities and stability issues Jan 20, 2026
Copilot AI requested a review from axetroy January 20, 2026 08:02
@axetroy axetroy marked this pull request as ready for review January 20, 2026 08:26
@axetroy axetroy merged commit 352018a into master Jan 20, 2026
8 checks passed
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