CakeFest 2024: The Official CakePHP Conference

设计数据库

第一步一般都是创建数据库,除非是使用第三方的数据库服务。当创建一个数据库的时候,会指定一个所有者来执行和新建语句。通常,只有所有者(或超级用户)才有权对数据库中的对象进行任意操作。如果想让其他用户使用,就必须赋予他们权限。

应用程序永远不要使用数据库所有者或超级用户帐号来连接数据库,因为这些帐号可以执行任意的操作,比如说修改数据库结构(例如删除一个表)或者清空整个数据库的内容。

应该为程序的每个方面创建不同的数据库帐号,并赋予对数据库对象的极有限的权限。仅分配给能完成其功能所需的权限,避免同一个用户可以完成另一个用户的事情。这样即使攻击者利用程序漏洞取得了数据库的访问权限,也最多只能做到和该程序一样的影响范围。

鼓励用户不要把所有的事务逻辑都用 web 应用程序(即用户的脚本)来实现。最好用视图(view)、触发器(trigger)或者规则(rule)在数据库层面完成。当系统升级的时候,需要为数据库开辟新的接口,这时就必须重做所有的数据库客户端。除此之外,触发器还可以透明和自动地处理字段,并在调试程序和跟踪事实时提供有用的信息。

add a note

User Contributed Notes 1 note

up
-45
krystian at jablonowski dot eu
2 years ago
It's a good practice to create a user account with absolutely minimal permissions. Whenever You need to select those permissions by columns or tables remember that some rules don't apply to security measures on Your server, like "We are all adults here" or "KISS - Keep It Simple Stupid". Personally, I prefer to create a minimal amount of users with only the necessary authorization to manipulate or collect data from DB.
Remember, that leak of data can have tremendous consequences, and rebuilding the trust of Your users is extremely hard to accomplish.
To Top