security: login rate limiting, fix health endpoint, harden error handling

- Fix health endpoint returning null time (use time.Now() instead of context value)
- Add LoginRateLimiter: 5 attempts per 15min window, 5min block on brute-force
- Apply rate limiting to login/register endpoints
- Move reset-password to authenticated routes (was unauthenticated — critical vuln)
- Limit response body sizes on proxy/external API calls (prevent memory exhaustion)
- Sanitize error messages in agent chat endpoint (don't leak internal errors)
- Record login success/failure for rate limiting tracking
This commit is contained in:
shinchan-zhai
2026-03-23 09:43:20 +08:00
parent 84758e2942
commit f28f0e340c
6 changed files with 160 additions and 12 deletions

View File

@@ -287,7 +287,7 @@ func fetchStockQuote(code string) (*StockQuote, error) {
if err != nil { return nil, err }
defer resp.Body.Close()
reader := transform.NewReader(resp.Body, simplifiedchinese.GBK.NewDecoder())
reader := transform.NewReader(io.LimitReader(resp.Body, 256*1024), simplifiedchinese.GBK.NewDecoder())
body, err := io.ReadAll(reader)
if err != nil { return nil, err }