mirror of
https://github.com/R0m1k3/FlowReader.git
synced 2026-10-23 23:28:06 +02:00
fix(backend): harden security and speed up feeds and article API
Security: - WebSocket events are routed to their owner only (no cross-user leak); hub close is idempotent (fixes double-close panic), adds ping/pong and write deadlines. - Session tokens stored as SHA-256 (migration 008 keeps sessions valid); single-query auth middleware puts the user in the request context. - Client IP only trusts X-Forwarded-For from TRUSTED_PROXIES; rate limiter map is bounded; per-user limit on AI summaries. - Argon2id at OWASP minimum with a concurrency cap; constant-time login for unknown emails; atomic first-admin bootstrap; REGISTRATION_ENABLED. - CSP/HSTS/COOP headers, same-origin guard on mutations, body size limits, wider SSRF denylist, bounded feed/page/AI response reads, generic errors. - Upgrade chi, pgx, x/net, x/text, x/crypto (known CVEs); commit go.sum. Performance: - List endpoints return a plain-text excerpt and reading time instead of full HTML; content is sanitized once at ingest (legacy rows backfilled). - Keyset pagination on (sort_at, id) with matching partial indexes; redundant indexes dropped (migration 007). - Fetcher: bounded worker pool, conditional GET (ETag/Last-Modified), exponential backoff, dedupe before insert, column-safe truncation, retention-aware ingest, per-user refresh coalescing. - Read/favorite/read-all are single ownership-scoped statements. - gzip compression, immutable caching for hashed assets, path-safe SPA handler, server timeouts; expired sessions purged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d037e2be34
commit
03e57e4308
40 files changed
+2231
-1898
No files matched your search
@@ -6,16 +6,21 @@ import (
|
||||
)
|
||||
|
||||
// ContentSanitizer handles HTML sanitization for articles.
|
||||
// A bluemonday policy is safe for concurrent use once built.
|
||||
type ContentSanitizer struct {
|
||||
policy *bluemonday.Policy
|
||||
}
|
||||
|
||||
// NewContentSanitizer creates a new sanitizer with a "UGCPolicy" (safe for user-generated content).
|
||||
func NewContentSanitizer() *ContentSanitizer {
|
||||
// Using UGCPolicy allows common tags (b, i, p, img, etc.) but strips dangerous ones.
|
||||
return &ContentSanitizer{
|
||||
policy: bluemonday.UGCPolicy(),
|
||||
}
|
||||
// UGCPolicy allows common tags (b, i, p, img, figure, table…) but strips
|
||||
// scripts, styles, event handlers and non-http(s)/mailto links.
|
||||
policy := bluemonday.UGCPolicy()
|
||||
// Article links open in a new tab instead of navigating away from the
|
||||
// reader (rel="noopener noreferrer nofollow" is added automatically).
|
||||
policy.AddTargetBlankToFullyQualifiedLinks(true)
|
||||
policy.RequireNoReferrerOnFullyQualifiedLinks(true)
|
||||
return &ContentSanitizer{policy: policy}
|
||||
}
|
||||
|
||||
// Sanitize cleans the HTML content.
|
||||
|
||||
Reference in new issue
Block a user