release: v0.5.1 — error pipeline, security hardening (audit fixes) - #15
Merged
Conversation
TDD: 9 tests written BEFORE implementation, all pass. - Add ErrorHandler type and Router.SetErrorHandler() - Default handler maps: Problem→status, ValidationErrors→422, binding errors→400/415, unknown→500 without details - Add c.written flag to prevent double-write on late errors - Update existing tests: validation 500→422, binding 500→400 Fixes critical audit finding: every error was plain-text 500.
F2: Group() now appends parent middleware instead of replacing.
Child groups always inherit parent middleware chain.
Prevents auth bypass when nesting groups with explicit middleware.
TDD: TestGroup_ChildInheritsParentMiddleware — trace verified.
F3: Shutdown() now drains active connections (server.Shutdown) BEFORE
calling cleanup callbacks (db.Close). Prevents active requests
from using closed resources.
F4: OPTIONS preflight now reaches middleware without explicit route.
handleNotFound runs middleware chain for OPTIONS when handleOPTIONS
enabled and path exists for other methods.
Added Vary: Origin header on all CORS responses.
TDD: 3 tests (preflight without route, no middleware, Vary header).
F5: MaxBytesReader wraps request body in adaptGenericHandler.
Default limit 4MB, configurable via SetMaxBodySize().
MaxBytesError mapped to 413 in defaultErrorHandler.
TDD: 5 tests (large→413, normal→200, custom, zero disables, plain unaffected).
… F7)
F6: Remove c.DB(), c.SSE(), c.WebSocket() stubs from Context.
c.DB() had broken context key (type declared inside function body).
SSE/WS stubs always returned ErrStreamNotImported.
Users should use plugin helpers: database.GetDB(c), stream.SSEUpgrade(c).
F7: handleWithGroupMiddleware now writes RouteInfo to r.routes.
Group routes appear in OpenAPI spec.
405 Method Not Allowed now includes Allow header (RFC 9110).
F8: RateLimit default KeyFunc now uses RemoteAddr instead of trusting
X-Forwarded-For/X-Real-IP headers. Prevents XFF spoofing bypass.
To use proxy headers, set KeyFunc explicitly with trusted proxy logic.
F10: Replace encoding/json/v2 imports with encoding/json.
Go 1.27 makes json/v2 the default — explicit import unnecessary.
Changed: openapi.go, openapi_test.go, examples/07-sse-notifications.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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
Security hardening and critical bug fixes identified by independent audit (Claude Fable 5.1).
Critical Fixes
Security
Removed (broken stubs)
c.DB()→ usedatabase.GetDB(c)c.SSE()→ usestream.SSEUpgrade(c, handler)c.WebSocket()→ usestream.WebSocketUpgrade(c, handler, opts)Test plan