feat: Fail fast at boot when handlers and spec disagree#88
Merged
Conversation
The default exception handler routed MissingOperationHandlerException to a bare 500 at request time, so an OpenAPI operation declared in the spec but missing from the handler map only surfaced when a client hit it. ZAP picked this up against the example launcher and flagged seven Server Error / Application Error Disclosure findings. Validate handler/spec wiring at OpenApiServer.Builder.build() and throw IllegalStateException with the offending operationIds when: - a spec operationId has no registered handler, or - a handler is registered for an operationId not in the spec. Once the boot check is in place the dispatch-time null check, the MissingOperationHandlerException class, and its unit test are unreachable, so they are deleted. The example ServerLauncher now registers stub handlers for every operation in src/test/resources/openapi.json so the demo (and the ZAP scan) covers the full surface. ServerBaseTest grows a stubAllHandlers helper so the existing tests can keep registering the subset they care about and pick up stubs for the rest. Re-running ZAP against the updated launcher: no Server Error / no Application Error Disclosure findings; only header hardening warnings remain.
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.
The default exception handler routed MissingOperationHandlerException to a bare 500 at request time, so an OpenAPI operation declared in the spec but missing from the handler map only surfaced when a client hit it. ZAP picked this up against the example launcher and flagged seven Server Error / Application Error Disclosure findings.
Validate handler/spec wiring at OpenApiServer.Builder.build() and throw IllegalStateException with the offending operationIds when:
Once the boot check is in place the dispatch-time null check, the MissingOperationHandlerException class, and its unit test are unreachable, so they are deleted.
The example ServerLauncher now registers stub handlers for every operation in src/test/resources/openapi.json so the demo (and the ZAP scan) covers the full surface. ServerBaseTest grows a stubAllHandlers helper so the existing tests can keep registering the subset they care about and pick up stubs for the rest.
Re-running ZAP against the updated launcher: no Server Error / no Application Error Disclosure findings; only header hardening warnings remain.