feat: enhance security with IP banning, ownership checks, and SSRF protection
Add comprehensive security improvements across the application: - **IP-based login protection**: Implement IP ban system tracking login failures, auto-banning after threshold exceeded - **Ownership verification**: Add userID parameter to Delete/Update operations for posts and comments to prevent unauthorized modifications - **SSRF protection**: Add URL and resolved host validation for image URLs in chat and OpenAI client - **SQL injection prevention**: Add EscapeLikeWildcard utility to escape special characters in LIKE queries - **HTTP security**: Configure server timeouts and add security headers middleware - **Rate limiting**: Refactor to support configurable duration and per-endpoint rate limits for auth routes - **Error handling**: Standardize error responses using HandleError and proper error types
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"with_you/internal/model"
|
||||
"with_you/internal/pkg/netutil"
|
||||
)
|
||||
|
||||
// ValidateChatMessageImageSegments 校验聊天消息中的图片段:禁止 data:/base64 内联,仅允许引用本站 S3 公开前缀下的 URL。
|
||||
@@ -45,6 +46,12 @@ func (s *UploadService) ValidateChatMessageImageSegments(segments model.MessageS
|
||||
if u.Host == "" {
|
||||
return fmt.Errorf("图片地址无效")
|
||||
}
|
||||
if err := netutil.ValidateURL(urlStr); err != nil {
|
||||
return fmt.Errorf("图片地址不安全: %w", err)
|
||||
}
|
||||
if err := netutil.CheckResolvedHost(u.Hostname()); err != nil {
|
||||
return fmt.Errorf("图片地址不安全: %w", err)
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(urlStr, prefix) {
|
||||
return fmt.Errorf("图片必须使用本站上传接口生成的资源地址")
|
||||
|
||||
Reference in New Issue
Block a user