fix: API security hardening and stability improvements#5
Open
Daymarvi wants to merge 1 commit into
Open
Conversation
- Add RouteName input validation: reject non-alphanumeric characters to prevent injection via API query strings (returns HTTP 400) - Wrap request processing in try/catch to prevent a single failed request from crashing the entire API listener (returns HTTP 500) - Wrap HttpListener lifecycle in try/finally to ensure cleanup on unhandled exception (prevents port remaining blocked) - Fix EventLog handle leak: Dispose() EventLog objects in Write-Log when using AdditionalFields (prevents handle exhaustion)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR improves the WinBGP API security and stability with 4 changes:
Changes
Input validation on RouteName (Security)
RouteNamecontaining non-alphanumeric characters (;,|,', spaces, etc.)Request processing try/catch (Stability)
HttpListener try/finally (Resource leak)
$listener.Stop()and$listener.Close()are always called, even on unhandled exceptionEventLog Dispose (Memory leak)
[System.Diagnostics.EventLog]::new()in Write-Log with AdditionalFields was never disposed$NewEvent.Dispose()to prevent handle exhaustion in long-running serviceTest Results
Tested on proper server (WinBGP service running, 3 active routes):
RouteName=test;evilRouteName=test|whoamiRouteName=test'dropEvent Log evidence from winbgp -logs
17/06/2026 07:56:36 Warning API rejected invalid RouteName 'test'drop' from '127.0.0.1'
17/06/2026 07:56:30 Warning API rejected invalid RouteName 'test|whoami' from '127.0.0.1'
17/06/2026 07:56:15 Warning API rejected invalid RouteName 'test;evil' from '127.0.0.1'
Files changed
src/WinBGP-API.ps1