Skip to main content
SecurityFeatureBreaking change
v0.11.0

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 TrustedProxies in your app config to specify which proxy IPs (as CIDRs) are allowed to set X-Real-IP and X-Forwarded-For headers. This prevents IP spoofing from untrusted clients.
  • Secure cookie setter — SetCookieWithConfig() lets you set cookies with HttpOnly, Secure, and SameSite attributes 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 using DefaultApp(). 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-IP and X-Forwarded-For are only used when the request comes from an IP in your TrustedProxies list. Update your app config if you run behind a reverse proxy.
  • SetCookie() is deprecated — Use SetCookieWithConfig() instead for full control over cookie security attributes.
  • DefaultApp() now includes Helmet middleware — If you use DefaultApp(), 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-Disposition header injection in file downloads.
  • Fixed JSON encoding failures silently returning 404 instead of 500.
FeaturePerformanceBreaking change
v0.9.0
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 handle SIGINT/SIGTERM and drain in-flight requests before exiting. A new Shutdown() method lets you trigger this programmatically.
  • Request body size limit — Set MaxRequestBodySize in your app config to cap incoming request bodies and protect against oversized payloads.
  • New context helpers — IsAjax(), IsWebSocket(), AcceptedLanguages(), and RemoteAddr() 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 a string (previously a fasthttp cookie object) and Cookies() returns map[string]string. This aligns cookies with the same pattern used by Query(), Param(), and Header(). See Context — cookies.
  • Debug mode off by default — Set Config.Debug = true explicitly if you need debug output.
  • Deprecated methods removed — ParamString() and QueryString() have been removed. Use Param() and Query() instead.

Bug fixes

  • Fixed a crash when merging a nil config.
  • Fixed X-Forwarded-For parsing 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.