fix(config): validate HTTP_PORT range and harden Windows browser launch - #1198
fix(config): validate HTTP_PORT range and harden Windows browser launch#1198nmgaston wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1198 +/- ##
==========================================
+ Coverage 50.09% 50.12% +0.03%
==========================================
Files 146 146
Lines 13552 13561 +9
==========================================
+ Hits 6789 6798 +9
Misses 6171 6171
Partials 592 592 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR tightens runtime configuration validation and adjusts Windows browser launching to avoid cmd start mis-parsing URLs, improving robustness for local UI startup.
Changes:
- Added HTTP port validation in
config.NewConfig()and unit tests for valid/invalid port values. - Hardened the Windows
cmd /c startinvocation by adding the required empty title argument, and updated related tests.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| config/config.go | Adds HTTP port validation to prevent invalid HTTP_PORT values from reaching runtime URL/listener setup. |
| config/config_test.go | Adds targeted tests for port validation and NewConfig() failure on invalid ports. |
| cmd/app/browser.go | Updates Windows browser launch args to include the required empty title parameter for start. |
| cmd/app/browser_test.go | Updates Windows expectations to match the revised browser launch invocation. |
Suppressed comments (1)
cmd/app/browser_test.go:46
- This Windows expectation should match the (quoted) URL argument passed to
cmd /c startso the test accurately validates the hardened invocation.
mockCmdExecutor.On("Execute", "cmd", []string{windowsCmdFlag, windowsCmdStart, windowsCmdTitle, "http://localhost:8080"}).Return(nil)
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
9ff24db to
b036586
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
Suppressed comments (5)
config/config.go:343
- The port validation errors currently read as if the value necessarily came from the HTTP_PORT env var, but
ConsoleConfig.Portcan also come from config.yml/defaults. Rewording these to refer to the HTTP port while still mentioning HTTP_PORT makes the failure less misleading.
ErrPortNotNumeric = errors.New("HTTP_PORT must be a decimal integer")
ErrPortOutOfRange = errors.New("HTTP_PORT must be in range 1–65535")
cmd/app/browser_test.go:33
- If the Windows implementation is updated to use
rundll32 url.dll,FileProtocolHandler(matching pkg/tray/tray.go), the expected args in this helper should be updated accordingly; otherwise launchBrowser tests will drift from the hardened behavior.
case "windows":
return "cmd", []string{windowsCmdFlag, windowsCmdStart, windowsCmdTitle, "\"" + url + "\""}
cmd/app/browser_test.go:47
- The Windows openBrowser test expectation should align with the safer
rundll32 url.dll,FileProtocolHandlerinvocation if openBrowser is updated accordingly.
mockCmdExecutor.On("Execute", "cmd", []string{windowsCmdFlag, windowsCmdStart, windowsCmdTitle, "\"http://localhost:8080\""}).Return(nil)
cmd/app/browser.go:68
- Even with the empty title argument, using
cmd /c startis still a shell-mediated launch. Switching torundll32 url.dll,FileProtocolHandlermatches the existing implementation in pkg/tray/tray.go and avoids cmd.exe parsing entirely.
case "windows":
cmd = "cmd"
args = []string{windowsCmdFlag, windowsCmdStart, windowsCmdTitle, "\"" + url + "\""}
cmd/app/browser.go:52
- This Windows browser-launch path is still built around
cmd /c start, which is harder to reason about safely (metacharacter parsing / quoting rules) and duplicates logic that the codebase already avoids elsewhere by usingrundll32 url.dll,FileProtocolHandler(e.g., pkg/tray/tray.go:137-141). Consider switching this helper to the same approach.
This issue also appears on line 66 of the same file.
// windowsCmdFlag is the /c flag passed to cmd.exe to run a command and exit.
// windowsCmdStart is the Windows shell verb that opens a URL in the default browser.
// windowsCmdTitle is the mandatory empty window-title argument required by `start` to
// prevent it from interpreting the URL as the window title, which can cause unexpected
// command parsing on Windows when the URL contains special characters.
62f19a3 to
16cb56f
Compare
PR: HTTP Port Validation & Windows Browser Launch Hardening
Summary
This PR adds early HTTP port validation during configuration loading and hardens
Windows browser launch argument handling.
The goal is to fail fast on malformed externally supplied port values
(for example from
HTTP_PORTenv var), instead of allowing invalid values toreach later runtime networking/browser paths.
Problem
Malformed
HTTP_PORTvalues are accepted during config load andcan fail later during listen/open-browser flows with less actionable errors.
Example Observed on Windows:
App starts config/init flow
Later fails with:
What Changed
1. Early HTTP_PORT Validation in Config Load
config.goinsideNewConfigafter env overlayErrPortNotNumericErrPortOutOfRangevalidatePorthelper2. Windows Browser Launch Hardening
Updated Windows browser command args in
browser.goto include requiredempty title argument for
start:Files Changed
config.govalidatePorthelper and sentinel errorsbrowser.gocmd /c startValidation Rules
818199999ErrPortOutOfRangeabcErrPortNotNumeric8181& calcErrPortNotNumeric-1ErrPortOutOfRangeErrPortNotNumericTesting
Port Validation
HTTP_PORTto invalid values and verify app fails fast with clear errorHTTP_PORTto valid value and verify app starts normallyWindows Browser Launch
cmd /c start "" <url>is used on Windows