Skip to content

Commit

Permalink
Security fix: any user can delete any feed
Browse files Browse the repository at this point in the history
Regression introduced in commit 51fb949.
  • Loading branch information
fguillot committed May 7, 2021
1 parent fa49bca commit 32439ca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion storage/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ func (s *Storage) RemoveFeed(userID, feedID int64) error {
}
}

if _, err := s.db.Exec(`DELETE FROM feeds WHERE id=$1`, feedID); err != nil {
if _, err := s.db.Exec(`DELETE FROM feeds WHERE id=$1 AND user_id=$2`, feedID, userID); err != nil {
return fmt.Errorf(`store: unable to delete feed #%d: %v`, feedID, err)
}

Expand Down
6 changes: 6 additions & 0 deletions ui/feed_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import (

func (h *handler) removeFeed(w http.ResponseWriter, r *http.Request) {
feedID := request.RouteInt64Param(r, "feedID")

if !h.store.FeedExists(request.UserID(r), feedID) {
html.NotFound(w, r)
return
}

if err := h.store.RemoveFeed(request.UserID(r), feedID); err != nil {
html.ServerError(w, r, err)
return
Expand Down

0 comments on commit 32439ca

Please sign in to comment.