Skip to content

Commit

Permalink
security fix: disallow editing threads and posts by other users
Browse files Browse the repository at this point in the history
  • Loading branch information
ltheinrich committed Feb 12, 2019
1 parent 2f1af2d commit a4af732
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion internal/app/handlers/editpost.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ func EditPost(request map[string]interface{}, username string, auth bool) interf
}

// insert into database
_, err = db.DB.Exec("UPDATE posts SET content = $1 FROM users WHERE posts.id = $2 AND users.username = $3;",
_, err = db.DB.Exec(`UPDATE posts SET content = $1 FROM users
WHERE posts.author = users.id AND posts.id = $2 AND users.username = $3;`,
content, postID, username)
if err != nil {
// print and return error
Expand Down
2 changes: 1 addition & 1 deletion internal/app/handlers/editthread.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func EditThread(request map[string]interface{}, username string, auth bool) inte

// insert into database
_, err = db.DB.Exec(`UPDATE threads SET threadname = $1, content = $2 FROM users
WHERE threads.id = $3 AND users.username = $4;`,
WHERE threads.author = users.id AND threads.id = $3 AND users.username = $4;`,
title, content, threadID, username)
if err != nil {
// print and return error
Expand Down

0 comments on commit a4af732

Please sign in to comment.