我应该遮掩主键值吗? [英] Should I obscure primary key values?

查看:77
本文介绍了我应该遮掩主键值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个Web应用程序,其前端是高度专业的搜索引擎.搜索是在主URL上进行的,当用户单击搜索结果以获得更详细的显示时,该用户将转到子目录.该传递是作为GET请求完成的,主键在查询字符串中传递.我似乎记得在某处读过,向用户公开主键不是一个好主意,所以我决定实现可逆加密.

I'm building a web application where the front end is a highly-specialized search engine. Searching is handled at the main URL, and the user is passed off to a sub-directory when they click on a search result for a more detailed display. This hand-off is being done as a GET request with the primary key being passed in the query string. I seem to recall reading somewhere that exposing primary keys to the user was not a good idea, so I decided to implement reversible encryption.

我开始怀疑我是否只是偏执.可逆加密(base64)可能会被任何想尝试的人轻易破坏,使URL变得非常难看,并且比原本的URL还要长.我是否应该放弃加密并以明文形式发送我的主密钥?

I'm starting to wonder if I'm just being paranoid. The reversible encryption (base64) is probably easily broken by anybody who cares to try, makes the URLs very ugly, and also longer than they otherwise would be. Should I just drop the encryption and send my primary keys in the clear?

推荐答案

您正在做的基本上是混淆.可逆加密的(并且base64并不真正算作加密)主键仍然是主键.

What you're doing is basically obfuscation. A reversible encrypted (and base64 doesn't really count as encryption) primary key is still a primary key.

您正在阅读的内容归结为:您通常不希望主键在系统外具有任何含义.这称为技术主键,而不是自然主键.这就是为什么您可能使用自动编号字段而不是SSN(称为自然主键)作为患者ID的原因.

What you were reading comes down to this: you generally don't want to have your primary keys have any kind of meaning outside the system. This is called a technical primary key rather than a natural primary key. That's why you might use an auto number field for Patient ID rather than SSN (which is called a natural primary key).

一般来说,技术主键优于自然主键,因为看起来恒定的事物会发生变化,这可能会引起问题.甚至国家也可以存在或不存在.

Technical primary keys are generally favoured over natural primary keys because things that seem constant do change and this can cause problems. Even countries can come into existence and cease to exist.

如果您确实拥有技术性的主键,则不希望通过赋予它们以其他方式没有的含义来使其成为自然的主键.我认为可以将主键放在URL中,但是安全性是一个单独的主题.如果某人可以更改该URL并访问他们不应该访问的内容,则这是一个安全问题,需要通过身份验证和授权来处理.

If you do have technical primary keys you don't want to make them de facto natural primary keys by giving them meaning they didn't otherwise have. I think it's fine to put a primary key in a URL but security is a separate topic. If someone can change that URL and get access to something they shouldn't have access to then it's a security problem and needs to be handled by authentication and authorization.

有些人会认为用户永远都不会看到它们.我认为您不需要走那么远.

Some will argue they should never be seen by users. I don't think you need to go that far.

这篇关于我应该遮掩主键值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆