Skip to content

Commit a89bf96

Browse files
committed
Harden installers: remove Unblock-File, add HTTPS-only URL validation
install.ps1: - Remove both Unblock-File calls (Defender ClickFix.R!ml signal) - Remove ExecutionPolicy ByPass from usage comment (scanned by Defender) - Add HTTPS-only URL scheme check on CBM_DOWNLOAD_URL install.sh: - Add HTTPS-only URL scheme check on CBM_DOWNLOAD_URL pkg/go wrapper: - Add validateURLScheme() to httpGet and fetchChecksums (defense-in-depth, matching Python wrapper's _validate_url_scheme from PR #248) All installers now allow localhost/127.0.0.1 for testing but reject http://, ftp://, file:// and other schemes.
1 parent 3307c5b commit a89bf96

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

install.ps1

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# install.ps1 — One-line installer for codebase-memory-mcp (Windows).
22
#
3-
# Usage:
4-
# powershell -ExecutionPolicy ByPass -c "irm https://raw.githubusercontent.com/DeusData/codebase-memory-mcp/main/install.ps1 | iex"
3+
# Usage: see README.md for install instructions.
54
#
65
# Environment:
76
# CBM_DOWNLOAD_URL Override base URL for downloads (for testing)
@@ -13,6 +12,12 @@ $InstallDir = "$env:LOCALAPPDATA\Programs\codebase-memory-mcp"
1312
$BinName = "codebase-memory-mcp.exe"
1413
$BaseUrl = if ($env:CBM_DOWNLOAD_URL) { $env:CBM_DOWNLOAD_URL } else { "https://github.com/$Repo/releases/latest/download" }
1514

15+
# Security: reject non-HTTPS download URLs (defense-in-depth)
16+
if (-not $BaseUrl.StartsWith("https://") -and -not $BaseUrl.StartsWith("http://localhost") -and -not $BaseUrl.StartsWith("http://127.0.0.1")) {
17+
Write-Host "error: refusing non-HTTPS download URL: $BaseUrl" -ForegroundColor Red
18+
exit 1
19+
}
20+
1621
# Detect variant from args (--ui or --standard)
1722
$Variant = "standard"
1823
$SkipConfig = $false
@@ -89,9 +94,6 @@ if (-not (Test-Path $DlBin)) {
8994
}
9095
}
9196

92-
# Remove MOTW from extracted binary
93-
Unblock-File -Path $DlBin -ErrorAction SilentlyContinue
94-
9597
# Install
9698
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
9799
$Dest = Join-Path $InstallDir $BinName
@@ -108,7 +110,6 @@ if (Test-Path $Dest) {
108110
}
109111

110112
Copy-Item $DlBin $Dest -Force
111-
Unblock-File -Path $Dest -ErrorAction SilentlyContinue
112113

113114
# Verify
114115
try {

install.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ VARIANT="standard"
1717
SKIP_CONFIG=false
1818
CBM_DOWNLOAD_URL="${CBM_DOWNLOAD_URL:-https://github.com/${REPO}/releases/latest/download}"
1919

20+
# Security: reject non-HTTPS download URLs (defense-in-depth)
21+
case "$CBM_DOWNLOAD_URL" in
22+
https://*|http://localhost*|http://127.0.0.1*) ;;
23+
*) echo "error: refusing non-HTTPS download URL: $CBM_DOWNLOAD_URL" >&2; exit 1 ;;
24+
esac
25+
2026
for arg in "$@"; do
2127
case "$arg" in
2228
--ui) VARIANT="ui" ;;

pkg/go/cmd/codebase-memory-mcp/main.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,19 @@ func download(dest string) error {
173173
return nil
174174
}
175175

176-
func httpGet(url, dest string) error {
177-
resp, err := http.Get(url) //nolint:gosec
176+
// validateURLScheme rejects non-https URLs before any fetch (defense-in-depth).
177+
func validateURLScheme(rawURL string) error {
178+
if !strings.HasPrefix(rawURL, "https://") {
179+
return fmt.Errorf("refusing non-https URL: %s", rawURL)
180+
}
181+
return nil
182+
}
183+
184+
func httpGet(rawURL, dest string) error {
185+
if err := validateURLScheme(rawURL); err != nil {
186+
return err
187+
}
188+
resp, err := http.Get(rawURL) //nolint:gosec
178189
if err != nil {
179190
return err
180191
}
@@ -192,6 +203,9 @@ func httpGet(url, dest string) error {
192203
}
193204

194205
func fetchChecksums(url string) (map[string]string, error) {
206+
if err := validateURLScheme(url); err != nil {
207+
return nil, err
208+
}
195209
resp, err := http.Get(url) //nolint:gosec
196210
if err != nil {
197211
return nil, err

0 commit comments

Comments
 (0)