开发者

Is a Modification Number to mask an Id in a query string necessary?

My coworker is insisting that the use of a global modification number to mask query string IDs is a good idea.

public static readonly int ModificationNumber = 9081234;

And Elsewhere:

_addressID = Convert.ToInt32(Request.QueryString["AddressId"]) - ModificationNumber;

I can't seem to get my head around this. If someone wanted to try some url hacking then a modification number makes no difference at all.

Are there other reasons this would开发者_运维百科 make a site more secure?

Furthermore, are there explicit reasons this is bad? In my mind the less globals the better.


IMVHO your colleague is kind of on the right track, but not quite.

A good rule to follow is that you should never expose actual IDs in the query string, as that gives a clue as to the structure of your database, and makes it just that little bit easier for someone to carry out a SQL injection type attack (they can target specific records because they know the ID).

So your colleague is attempting to achieve this, albeit in a very round-about way. Personally I wouldn't do it this way because it will simply be a matter of time before a smart attacker works out what you are doing and then works out what the magic number is. It also doesn't really do anything to prevent a SQL injection attack against specific records, as the generated number may match an existing key anyway. If you are relying on this methodology to avoid SQL attacks then you have deeper issues that need to be addressed.

Edit

Mentioning an alternative is probably a fair thing to do. As you are using C# and pulling parameters out of the querystring, I will assume you are using ASP.NET. In that case, important IDs can be kept in Session or the Cache. You can store a bunch of items in a custom data object, which you then store in Session (this saves having to keep track of lots of IDs, you just need to know one). ASP.NET manages the web app's Session for you, it is unique to each user, and you can use it to store stuff when you transition from page to page.

If you are manually tracking session or using a database to keep your session related info then you can still serialize the aforementioned data object into the database using a generated GUID as its key, and append that GUID to the query string (there is only an incredibly low chance of success if a user messes with a GUID to try and assume someone else's session, you can lower that chance even further by concatenating two GUIDs as a key, etc.).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜