Security hardening and safe-by-default APIs
This release patches several security vulnerabilities and introduces new APIs that make it easier to build secure applications with Lightning.New features
- Trusted proxy configuration — You can now set
TrustedProxiesin your app config to specify which proxy IPs (as CIDRs) are allowed to setX-Real-IPandX-Forwarded-Forheaders. This prevents IP spoofing from untrusted clients. - Secure cookie setter —
SetCookieWithConfig()lets you set cookies withHttpOnly,Secure, andSameSiteattributes in a single call. See Context — cookies. - Safe file serving —
FileFromSafeDir()serves files from a directory while preventing path traversal attacks. Use this instead of manually resolving file paths. - Safe redirects —
RedirectSafe()validates the target URL against a host whitelist before redirecting, protecting against open redirect vulnerabilities. - Helmet middleware — The new
Helmet()middleware automatically sets security response headers (e.g.,X-Content-Type-Options,X-Frame-Options). It is now included by default when usingDefaultApp(). See built-in middleware. - Debug endpoint authentication — Debug endpoints now require a token set via
Config.DebugToken, so they are no longer publicly accessible.
Breaking changes
RemoteAddr()no longer trusts forwarded headers by default —X-Real-IPandX-Forwarded-Forare only used when the request comes from an IP in yourTrustedProxieslist. Update your app config if you run behind a reverse proxy.SetCookie()is deprecated — UseSetCookieWithConfig()instead for full control over cookie security attributes.DefaultApp()now includes Helmet middleware — If you useDefaultApp(), security headers are set automatically. Remove any manually added security-header middleware to avoid duplicates.
Bug fixes
- Fixed a path traversal vulnerability in
Static()file serving where crafted URLs could access files outside the root directory. - Fixed template rendering errors leaking internal details to clients — errors are now sanitized before being returned.
- Fixed
Content-Dispositionheader injection in file downloads. - Fixed JSON encoding failures silently returning 404 instead of 500.
Fasthttp backend and simplified cookie API
Lightning now uses fasthttp under the hood, delivering significantly faster request handling and lower memory usage. The minimum Go version is now 1.25.New features
- Graceful shutdown — Call
RunGraceful()to automatically handleSIGINT/SIGTERMand drain in-flight requests before exiting. A newShutdown()method lets you trigger this programmatically. - Request body size limit — Set
MaxRequestBodySizein your app config to cap incoming request bodies and protect against oversized payloads. - New context helpers —
IsAjax(),IsWebSocket(),AcceptedLanguages(), andRemoteAddr()are now available on the Context object, making it easier to inspect incoming requests. - HTTP constants — Use built-in constants for status codes (
lightning.StatusOK), HTTP methods (lightning.MethodGet), MIME types (lightning.MIMEApplicationJSON), and header keys (lightning.HeaderContentType) instead of hard-coding strings. JSONError()helper — Return structured JSON error responses in a single call. See Context — error response.
Performance improvements
- Faster route matching — Route lookups are now constant-time instead of linear, which matters most when you have many routes at the same path depth.
- Context pooling — Contexts are reused via
sync.Pool, reducing garbage collection pressure under high load. - Middleware caching — Route groups cache their combined middleware chain so it isn’t rebuilt on every request.
Breaking changes
- Cookie API simplified —
Cookie()now returns astring(previously a fasthttp cookie object) andCookies()returnsmap[string]string. This aligns cookies with the same pattern used byQuery(),Param(), andHeader(). See Context — cookies. - Debug mode off by default — Set
Config.Debug = trueexplicitly if you need debug output. - Deprecated methods removed —
ParamString()andQueryString()have been removed. UseParam()andQuery()instead.
Bug fixes
- Fixed a crash when merging a nil config.
- Fixed
X-Forwarded-Forparsing to correctly extract the first IP from a comma-separated list. - Fixed context pool reuse bug where per-request data was not being cleared between requests.
- Fixed a dangling-pointer bug in the internal cookie reader.
- Fixed route matching issues with wildcard routes.