fix: add explicite validation check for empty url, title and content length
This commit is contained in:
@@ -130,6 +130,11 @@ func (h *PostHandler) CreatePost(w http.ResponseWriter, r *http.Request) {
|
||||
url := security.SanitizeURL(req.URL)
|
||||
content := security.SanitizePostContent(req.Content)
|
||||
|
||||
if url == "" {
|
||||
SendErrorResponse(w, "Invalid URL", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if title == "" && h.titleFetcher != nil {
|
||||
titleCtx, cancel := context.WithTimeout(r.Context(), 7*time.Second)
|
||||
defer cancel()
|
||||
@@ -160,6 +165,16 @@ func (h *PostHandler) CreatePost(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if len(title) > 200 {
|
||||
SendErrorResponse(w, "Title must be at most 200 characters", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if len(content) > 10000 {
|
||||
SendErrorResponse(w, "Content must be at most 10000 characters", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
post := &database.Post{
|
||||
Title: title,
|
||||
URL: url,
|
||||
|
||||
Reference in New Issue
Block a user