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:
@@ -3,6 +3,7 @@ package service
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -591,19 +592,20 @@ func (s *userServiceImpl) IsBlockedBatch(ctx context.Context, blockerID string,
|
||||
|
||||
// GetFollowingList 获取关注列表(字符串参数版本)
|
||||
func (s *userServiceImpl) GetFollowingList(ctx context.Context, userID, page, pageSize string) ([]*model.User, error) {
|
||||
// 转换字符串参数为整数
|
||||
pageInt := 1
|
||||
pageSizeInt := 20
|
||||
if page != "" {
|
||||
_, err := fmt.Sscanf(page, "%d", &pageInt)
|
||||
if err != nil {
|
||||
if v, err := strconv.Atoi(page); err != nil || v < 1 {
|
||||
pageInt = 1
|
||||
} else {
|
||||
pageInt = v
|
||||
}
|
||||
}
|
||||
if pageSize != "" {
|
||||
_, err := fmt.Sscanf(pageSize, "%d", &pageSizeInt)
|
||||
if err != nil {
|
||||
if v, err := strconv.Atoi(pageSize); err != nil || v < 1 {
|
||||
pageSizeInt = 20
|
||||
} else {
|
||||
pageSizeInt = v
|
||||
}
|
||||
}
|
||||
|
||||
@@ -613,19 +615,20 @@ func (s *userServiceImpl) GetFollowingList(ctx context.Context, userID, page, pa
|
||||
|
||||
// GetFollowersList 获取粉丝列表(字符串参数版本)
|
||||
func (s *userServiceImpl) GetFollowersList(ctx context.Context, userID, page, pageSize string) ([]*model.User, error) {
|
||||
// 转换字符串参数为整数
|
||||
pageInt := 1
|
||||
pageSizeInt := 20
|
||||
if page != "" {
|
||||
_, err := fmt.Sscanf(page, "%d", &pageInt)
|
||||
if err != nil {
|
||||
if v, err := strconv.Atoi(page); err != nil || v < 1 {
|
||||
pageInt = 1
|
||||
} else {
|
||||
pageInt = v
|
||||
}
|
||||
}
|
||||
if pageSize != "" {
|
||||
_, err := fmt.Sscanf(pageSize, "%d", &pageSizeInt)
|
||||
if err != nil {
|
||||
if v, err := strconv.Atoi(pageSize); err != nil || v < 1 {
|
||||
pageSizeInt = 20
|
||||
} else {
|
||||
pageSizeInt = v
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user