对数据库连接应用最小权限

发布于 2024-11-26 02:03:59 字数 142 浏览 0 评论 0原文

我注意到大多数 FOSS 应用程序(例如 Wordpress)仅使用一组已被授予所有权限的数据库凭据。这似乎违反了最小特权原则。

在编写这样的应用程序时,使用多个帐户是否会更好,例如,一个帐户仅用于 SELECT 查询,另一个帐户用于 UPDATE 等?

I've noticed that most FOSS applications (Wordpress, for example) only uses a single set of database credentials that have been granted all permissions. This seems like it violates the principle of least privilege.

In writing such an application, would it be better to use several accounts, for example, an account only for SELECT queries, another for UPDATE, etc?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

千年*琉璃梦 2024-12-03 02:03:59

绝对违反了最小特权原则。让我们回到定义

在信息安全、计算机科学等领域,
最小特权原则,又称最小特权原则
特权或最小特权,要求在特定的
计算环境的抽象层,每个模块(例如
基于我们所在层的进程、用户或程序
考虑到)必须能够仅访问此类信息并且
其合法目的所需的资源。

在您的 WordPress 示例中,公共用户使用 SQL 帐户从数据库中检索数据,该帐户还能够更改或删除该数据。该用户的“最低权限”不包括更改该数据的访问权限,无论该数据是直接位于表上还是通过存储过程。这绝对不符合“仅访问其合法目的所必需的信息和资源”的规定。。

SQL环境中的风险主要是SQL注入。一个小缺陷,如果该公共帐户有权造成损害,那么你最终会遇到各种各样的问题。是的,应该验证输入,是的,应该对查询进行参数化,但这是额外的一层防御,可以为您提供一些额外的保险。

我在 OWASP 中专门讨论了这一点.NET 开发人员前 10 名第 1 部分:注入

This is definitely a violation of the principle of least privilege. Let's go back to the definition:

In information security, computer science, and other fields, the
principle of least privilege, also known as the principle of minimal
privilege or just least privilege, requires that in a particular
abstraction layer of a computing environment, every module (such as a
process, a user or a program on the basis of the layer we are
considering) must be able to access only such information and
resources that are necessary to its legitimate purpose.

In your Wordpress example, a public user is retrieving data from the database with a SQL account which also has the ability to change or delete that data. The "least privilege" for this user would not include access to change that data whether it be directly on the table of via a stored procedure. This is definitely not compliant with "access only such information and resources that are necessary to its legitimate purpose".

The risk in a SQL environment is primarily SQL injection. One little flaw and if that public account has the rights to do damage then you end up with all sorts of problems. Yes, input should be validated, yes queries should be parameterised but this is one additional layer of defence that gives you some extra insurance.

I talk about this specifically in OWASP Top 10 for .NET developers part 1: Injection.

笑饮青盏花 2024-12-03 02:03:59

我想如果只是为了维护问题的话,情况会更糟。一个用户意味着凭据位于一处,并且可以在同一位置为每台服务器更新它们。此外,大多数框架都假设设置一个凭据来统治所有框架,虽然允许两个以上的凭据并不太难,但更烦人。

有一些好处是,如果您有一个用户具有仅选择权限,则您不必担心 SQL 注入(当然不是在 Bobby Tables 级别),但即使这样也不能保证,所以无论如何你都必须清理你的数据输入(他们仍然可以基于 select 进行注入攻击......)。

I'd imagine it would be worse, if only for maintenance issues. One user means credentials are one place and they can be updated for each server in exactly one place. Further, most frameworks work with the assumption of one credentials set to rule them all, and while it isn't too difficult to allow for two+, it is more annoying.

There is some benefit in that if you have one user with select only privileges, you don't have to worry about SQL injection quite as much (certainly not on a Bobby Tables level), but even that is no guarantee, so you'd have to be sanitizing your data input anyway (they could still do injection attacks based on select...).

岁吢 2024-12-03 02:03:59

最佳实践是向存储过程授予权限,而不是在表级别授予权限。

The best practice is to grant privileges to stored procedures rather than at the table level.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文