Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When edit data should id of data be stored in session

I have list of posts that any user can edit.
When I enter edit mode of the post in a hidden field I store PostId.
Now I see that this is actually bad because user can change that hidden field and update some other post.

Is the session the only alternative to keep id of post that user edit, or there is some better tactic?

Because my is really bad :(

like image 782
1110 Avatar asked Dec 17 '25 14:12

1110


1 Answers

There's a better tactic:

Before updating the record check if the record that the user is trying to update belongs to the currently authenticated user.

You could write a custom authorize attribute that does this task for you. Here's an example.

like image 89
Darin Dimitrov Avatar answered Dec 20 '25 04:12

Darin Dimitrov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!