Skip to content

Fix: Prevent HTTP server panic on missing directories and synchronize concurrent state access - #5

Open
mertcano wants to merge 1 commit into
Kalshi:masterfrom
mertcano:mertcano-patch-2
Open

Fix: Prevent HTTP server panic on missing directories and synchronize concurrent state access#5
mertcano wants to merge 1 commit into
Kalshi:masterfrom
mertcano:mertcano-patch-2

Conversation

@mertcano

Copy link
Copy Markdown

Description

This PR addresses high-severity Go HTTP server vulnerabilities within the goconvey repository, specifically resolving a filesystem nil-pointer panic and concurrent state race conditions.

Vulnerabilities & Security Defects Remediated:

  • Filesystem Panic Vector (web/server/api/server.go): os.Stat returned a nil file-info value for missing paths, but the previous implementation inspected info.IsDir() before verifying the error. The code has been reordered to check errors first, returning a controlled 404 Not Found response for missing or non-directory paths instead of crashing.
  • Concurrent State Races (web/server/api/server.go): Shared server states (currentRoot, latest, and paused) were read and modified concurrently from independent request and watcher routines without synchronization. A sync.RWMutex has been introduced to safely protect access, and results are now serialized from a thread-safe snapshot.
  • Regression Coverage (web/server/api/server_test.go): Added a targeted unit test (TestAdjustRootRejectsMissingDirectoryWithoutPanic) to explicitly verify that a missing root directory returns HTTP 404 with an explanatory message and does not panic.

… concurrent state access

### Description
This PR addresses high-severity Go HTTP server vulnerabilities within the `goconvey` repository, specifically resolving a filesystem nil-pointer panic and concurrent state race conditions.

**Vulnerabilities & Security Defects Remediated:**
* **Filesystem Panic Vector (`web/server/api/server.go`):** `os.Stat` returned a nil file-info value for missing paths, but the previous implementation inspected `info.IsDir()` before verifying the error. The code has been reordered to check errors first, returning a controlled `404 Not Found` response for missing or non-directory paths instead of crashing.
* **Concurrent State Races (`web/server/api/server.go`):** Shared server states (`currentRoot`, `latest`, and `paused`) were read and modified concurrently from independent request and watcher routines without synchronization. A `sync.RWMutex` has been introduced to safely protect access, and results are now serialized from a thread-safe snapshot.
* **Regression Coverage (`web/server/api/server_test.go`):** Added a targeted unit test (`TestAdjustRootRejectsMissingDirectoryWithoutPanic`) to explicitly verify that a missing root directory returns HTTP 404 with an explanatory message and does not panic.
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