Skip to content

Potential fix for code scanning alert no. 3: Uncontrolled data used in path expression#24

Merged
KrisPowers merged 3 commits into
mainfrom
alert-autofix-3
May 24, 2026
Merged

Potential fix for code scanning alert no. 3: Uncontrolled data used in path expression#24
KrisPowers merged 3 commits into
mainfrom
alert-autofix-3

Conversation

@KrisPowers

Copy link
Copy Markdown
Member

Potential fix for https://github.com/Command-IDE/cmd-ide/security/code-scanning/3

The safest fix without changing intended preview functionality is to enforce a base directory constraint in previewFileHandler:

  1. Keep converting URL path to filesystem path as today (Windows/Unix handling).
  2. Canonicalize both the requested path and a trusted base directory with filepath.Abs + filepath.Clean.
  3. Reject requests unless the requested path is inside the base directory.
  4. Continue serving with http.ServeFile only after this check.

For this file, the most practical base directory available from shown code is the current working directory (os.Getwd()), which preserves expected “preview project files” behavior while preventing arbitrary filesystem reads.
Changes required in app/preview_server.go:

  • Add imports: os and strings.
  • In previewFileHandler, replace the current filepath.IsAbs-only validation block with canonicalization + containment check (strings.HasPrefix with path-separator-safe prefix logic).

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…n path expression

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@KrisPowers KrisPowers self-assigned this May 24, 2026
Comment thread app/preview_server.go Fixed
…ed in path expression'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Comment thread app/preview_server.go Fixed
…ed in path expression'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@KrisPowers KrisPowers marked this pull request as ready for review May 24, 2026 21:46
@KrisPowers KrisPowers merged commit c8585d9 into main May 24, 2026
6 checks passed
@KrisPowers KrisPowers deleted the alert-autofix-3 branch May 24, 2026 21:46
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