Skip to content

Fix: CWE 428 - #2168

Merged
stenya merged 2 commits into
developmentfrom
fix/s43_LPE_CWE-428
May 18, 2026
Merged

Fix: CWE 428#2168
stenya merged 2 commits into
developmentfrom
fix/s43_LPE_CWE-428

Conversation

@stenya

@stenya stenya commented May 18, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes

    • Windows service now performs automatic registry self-healing on startup to correct path configuration issues.
  • Chores

    • Version updated to 2.1.19 across all components.
    • Improved Windows service installation script for proper service deployment.

Review Change Stack

stenya added 2 commits May 11, 2026 15:09
- Update NSIS installer to register service with properly quoted executable path
- Add runtime self-heal in portmaster-core on Windows service startup to protect users who update via in-app updater without re-running the installer

safing/portmaster-shadow#43
@stenya stenya self-assigned this May 18, 2026
@coderabbitai

coderabbitai Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR adds Windows service registry self-heal logic to PortmasterCore, updates the NSIS installer to properly quote service paths during installation, and bumps the desktop application version to 2.1.19 across Angular and Cargo manifests.

Changes

Service Path Registry Management and Release

Layer / File(s) Summary
Windows service registry self-heal
cmds/portmaster-core/main_windows.go
Adds Windows registry and service-specific imports, integrates a Windows service check into runPlatformSpecifics, and implements ensureQuotedServiceImagePath() to detect unquoted service ImagePath entries in the registry, verify the executable matches the currently running binary, and rewrite the path with proper quoting while preserving any trailing arguments.
Service installation path quoting
desktop/tauri/src-tauri/templates/nsis/install_hooks.nsh
Updates the NSIS post-install hook to pass the service binary path and --log-dir argument to SimpleSC::InstallService using properly quoted and escaped string formatting, ensuring the service ImagePath is registered with correct quoting at installation time.
Release version updates
desktop/angular/package.json, desktop/tauri/src-tauri/Cargo.toml
Version fields are incremented from 2.1.18 to 2.1.19 in both the Angular package manifest and the Tauri/Rust Cargo manifest.

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Fix: CWE 428' is vague and cryptic—it references a CWE (Common Weakness Enumeration) identifier without explaining what the actual vulnerability or fix entails. Provide a more descriptive title that explains the specific issue being fixed, such as 'Fix CWE-428 insecure Windows service path quoting' to clarify the nature of the change for reviewers scanning the history.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/s43_LPE_CWE-428

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@stenya stenya added this to the v2.1.19 milestone May 18, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cmds/portmaster-core/main_windows.go`:
- Around line 68-73: The code uses strings.Index on imagePath to find ".exe"
which can match occurrences in parent folder names; change this to search for
".exe" only after the last path separator so we detect the executable boundary
correctly. Concretely, compute lastSep := strings.LastIndexAny(imagePath, `\/`),
then call strings.Index on strings.ToLower(imagePath[lastSep+1:]) (adjusting
exeEnd relative to the whole string) to set exeEnd, and keep the same error
handling if no .exe is found; update references to exeEnd/imagePath accordingly
so truncation and subsequent matching use the boundary-aware index.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f7de2ae2-4965-45ae-aee4-d2bf68a1237c

📥 Commits

Reviewing files that changed from the base of the PR and between c036e41 and 2e4b3e9.

⛔ Files ignored due to path filters (2)
  • desktop/angular/package-lock.json is excluded by !**/package-lock.json
  • desktop/tauri/src-tauri/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • cmds/portmaster-core/main_windows.go
  • desktop/angular/package.json
  • desktop/tauri/src-tauri/Cargo.toml
  • desktop/tauri/src-tauri/templates/nsis/install_hooks.nsh

Comment on lines +68 to +73
// Unquoted path detected. Locate the end of the executable (.exe boundary).
exeEnd := strings.Index(strings.ToLower(imagePath), ".exe")
if exeEnd < 0 {
return fmt.Errorf("ImagePath contains no .exe, skipping fix: %s", imagePath)
}
exeEnd += len(".exe")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Use boundary-aware executable parsing to avoid self-heal false negatives

Line 69 takes the first .exe anywhere in ImagePath. If a parent folder contains .exe (for example C:\foo.exe\Portmaster\portmaster-core.exe ...), Line 75 truncates the path and Line 85 fails the match, so the vulnerable unquoted value is never repaired.

Suggested patch
-	// Unquoted path detected. Locate the end of the executable (.exe boundary).
-	exeEnd := strings.Index(strings.ToLower(imagePath), ".exe")
+	// Unquoted path detected. Locate the executable boundary (.exe followed by
+	// whitespace or end-of-string), not just the first ".exe" substring.
+	lowerPath := strings.ToLower(imagePath)
+	exeEnd := -1
+	for i := 0; i < len(lowerPath); {
+		idx := strings.Index(lowerPath[i:], ".exe")
+		if idx < 0 {
+			break
+		}
+		idx += i
+		boundary := idx + len(".exe")
+		if boundary == len(lowerPath) || lowerPath[boundary] == ' ' || lowerPath[boundary] == '\t' {
+			exeEnd = boundary
+			break
+		}
+		i = idx + 1
+	}
 	if exeEnd < 0 {
 		return fmt.Errorf("ImagePath contains no .exe, skipping fix: %s", imagePath)
 	}
-	exeEnd += len(".exe")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Unquoted path detected. Locate the end of the executable (.exe boundary).
exeEnd := strings.Index(strings.ToLower(imagePath), ".exe")
if exeEnd < 0 {
return fmt.Errorf("ImagePath contains no .exe, skipping fix: %s", imagePath)
}
exeEnd += len(".exe")
// Unquoted path detected. Locate the executable boundary (.exe followed by
// whitespace or end-of-string), not just the first ".exe" substring.
lowerPath := strings.ToLower(imagePath)
exeEnd := -1
for i := 0; i < len(lowerPath); {
idx := strings.Index(lowerPath[i:], ".exe")
if idx < 0 {
break
}
idx += i
boundary := idx + len(".exe")
if boundary == len(lowerPath) || lowerPath[boundary] == ' ' || lowerPath[boundary] == '\t' {
exeEnd = boundary
break
}
i = idx + 1
}
if exeEnd < 0 {
return fmt.Errorf("ImagePath contains no .exe, skipping fix: %s", imagePath)
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmds/portmaster-core/main_windows.go` around lines 68 - 73, The code uses
strings.Index on imagePath to find ".exe" which can match occurrences in parent
folder names; change this to search for ".exe" only after the last path
separator so we detect the executable boundary correctly. Concretely, compute
lastSep := strings.LastIndexAny(imagePath, `\/`), then call strings.Index on
strings.ToLower(imagePath[lastSep+1:]) (adjusting exeEnd relative to the whole
string) to set exeEnd, and keep the same error handling if no .exe is found;
update references to exeEnd/imagePath accordingly so truncation and subsequent
matching use the boundary-aware index.

@stenya
stenya merged commit b5153a3 into development May 18, 2026
9 of 13 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.

1 participant