Fix: Prevent HTTP server panic on missing directories and synchronize concurrent state access - #5
Open
mertcano wants to merge 1 commit into
Open
Fix: Prevent HTTP server panic on missing directories and synchronize concurrent state access#5mertcano wants to merge 1 commit into
mertcano wants to merge 1 commit into
Conversation
… 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.
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.
Description
This PR addresses high-severity Go HTTP server vulnerabilities within the
goconveyrepository, specifically resolving a filesystem nil-pointer panic and concurrent state race conditions.Vulnerabilities & Security Defects Remediated:
web/server/api/server.go):os.Statreturned a nil file-info value for missing paths, but the previous implementation inspectedinfo.IsDir()before verifying the error. The code has been reordered to check errors first, returning a controlled404 Not Foundresponse for missing or non-directory paths instead of crashing.web/server/api/server.go): Shared server states (currentRoot,latest, andpaused) were read and modified concurrently from independent request and watcher routines without synchronization. Async.RWMutexhas been introduced to safely protect access, and results are now serialized from a thread-safe snapshot.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.