是否需要使用修改号来屏蔽查询字符串中的 ID?
我的同事坚持认为使用全局修改号来屏蔽查询字符串 ID 是一个好主意。
public static readonly int ModificationNumber = 9081234;
还有其他地方:
_addressID = Convert.ToInt32(Request.QueryString["AddressId"]) - ModificationNumber;
我似乎无法理解这个问题。如果有人想尝试一些网址黑客攻击,那么修改号根本没有任何区别。
还有其他原因可以使网站更安全吗?
此外,是否有明确的原因导致这种情况不好?在我看来,全局变量越少越好。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
IMVHO 你的同事有点走在正确的轨道上,但并不完全正确。
需要遵循的一个好规则是,永远不应该在查询字符串中暴露实际 ID,因为这提供了有关数据库结构的线索,并且使某人更容易执行 SQL 注入类型攻击(他们可以定位特定记录,因为他们知道 ID)。
所以你的同事正在尝试实现这一目标,尽管是以一种非常迂回的方式。就我个人而言,我不会这样做,因为聪明的攻击者迟早会弄清楚你在做什么,然后算出神奇数字是什么。它也没有真正做任何事情来防止针对特定记录的 SQL 注入攻击,因为生成的数字无论如何都可能与现有密钥匹配。如果您依靠这种方法来避免 SQL 攻击,那么您就需要解决更深层次的问题。
编辑
提及替代方案可能是一件公平的事情。
当您使用 C# 并从查询字符串中提取参数时,我假设您使用的是 ASP.NET。在这种情况下,重要的ID可以保存在Session或Cache中。您可以将一堆项目存储在自定义数据对象中,然后将其存储在 Session 中(这样就不必跟踪大量 ID,您只需要知道一个即可)。 ASP.NET 为您管理 Web 应用程序的会话,它对于每个用户来说都是唯一的,当您从一个页面转换到另一个页面时,您可以使用它来存储内容。
如果您手动跟踪会话或使用数据库来保存会话相关信息,那么您仍然可以使用生成的 GUID 作为其键将上述数据对象序列化到数据库中,并将该 GUID 附加到查询字符串(只有一个令人难以置信的如果用户弄乱 GUID 来尝试假设其他人的会话,则成功的机会很低,您可以通过连接两个 GUID 作为密钥来进一步降低成功率,等等)。
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.).