Storing Model ID in ASP.NET MVC ViewModel, Security issues

情到浓时终转凉″ 提交于 2019-12-06 01:04:18

I do it through a method of encrypted sessionKey this encrypted key holds user details such as ID etc. the hidden field for ID is always zero on the form and this is changed to the ID of my user.UserId.

I have a user model (user) and that model is populated with the decrypted data from the session it is how i deal with userlevel etc.

my unencrypted string looks like this: userid||email||datetimelogin||users-GUID||Real Name||userlevel

this then gets encrypted with there own private key at 255.

Just a thought, good point though i guess for most it is quite easy to forget that people could fiddle with the ID.

the idea above by zasz is perfectly valid too but then you would have to build a view model to account for the extra field of GUID and to account for the missing UserId field.

This is a common problem. It is best solved by not sending the UserID to the client side. Since you do not want to use the server side session, and want to protect your app from malignant users, you have to simulate a session with a Database table. Put your UserId and Random GUID into the table when the user logs in. Make sure this table has only one row for any given UserId (my attempt to simplify - when the user logs in later again update the existing row with a new guid).

Now send the GUID to the client as part of the ViewModel. When updated email etc comes back with the original guid, consult our table to resolve the guid back into user id. Note that this is sort of a rudimentary session, and achieves tamper-proofing. Tampering a GUID to find some other users Guid is nigh-on impossible.

As you rightly feel, sending our DB identitys for any model not only user to the client side as input hidden fields is a bad idea, and every hacker's breakfast as soon as he wakes up, is to look at hidden input fields and tinker around with it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!