Skip to content

fix: patch security vulnerabilities (v0.11.0) - #25

Merged
kk0829 merged 3 commits into
mainfrom
fix/security-vulnerabilities
Apr 15, 2026
Merged

kk0829 merged 3 commits into
mainfrom
fix/security-vulnerabilities

Conversation

@kk0829

@kk0829 kk0829 commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fix path traversal in Static() file serving and add FileFromSafeDir() for safe file access
  • Fix IP spoofing by introducing TrustedProxies config with CIDR validation for X-Real-IP / X-Forwarded-For
  • Add SetCookieWithConfig() with HttpOnly, Secure, SameSite support; Helmet() middleware for security headers; RedirectSafe() with host whitelist

Breaking Changes

  • RemoteAddr() no longer trusts X-Real-IP / X-Forwarded-For by default — requires TrustedProxies config
  • SetCookie(key, value) deprecated in favor of SetCookieWithConfig
  • DefaultApp() now registers Helmet() middleware

Full Changelog

Security Fixes

  • Path traversal in Static() and File() — resolved path validated against root directory
  • IP address spoofing — X-Real-IP / X-Forwarded-For only trusted from configured proxies
  • Debug endpoint exposure — token-based authentication via Config.DebugToken
  • Template error information leakage — errors sanitized before returning to client
  • Open redirect — new RedirectSafe() with host whitelist
  • Content-Disposition header injection — filename escaping
  • Cookie missing security attributes — new CookieConfig with HttpOnly, Secure, SameSite

New APIs

  • Config.TrustedProxies []string — CIDR whitelist
  • Config.DebugToken string — debug endpoint auth
  • ctx.SetCookieWithConfig(CookieConfig) — secure cookie setter
  • ctx.FileFromSafeDir(safeDir, path) — safe file serving
  • ctx.RedirectSafe(code, url, hosts...) — safe redirect
  • Helmet() middleware — security response headers

Test Coverage

  • 84.6% → 96.1% (+30 test cases)

- Fix path traversal in Static file serving and add FileFromSafeDir
- Fix IP spoofing via TrustedProxies config with CIDR validation
- Add CookieConfig with HttpOnly/Secure/SameSite support
- Protect debug endpoint with configurable token auth
- Sanitize template errors to prevent info leakage
- Add RedirectSafe with host whitelist validation
- Return 500 instead of silent 404 on JSON encoding failure
- Prevent Content-Disposition header injection in file downloads
- Add Helmet middleware for security response headers
@kk0829
kk0829 merged commit c5efdaa into main Apr 15, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants