MySQL 登录信息的安全存储?

发布于 2024-08-12 17:07:05 字数 206 浏览 5 评论 0原文

首先,我意识到不存在完全安全的解决方案(即使有,它的可用性也很糟糕)。

也就是说,如何保护您的 MySQL 数据库不被下载您的代码并进行挑选的人破坏?根据我使用 PHP 的经验,似乎有必要在某个时候将其存储在代码中,这会为我发送标志。我可以看到重构以混淆变量、常量和(用户定义的)函数名称可能是有益的,但最终仍然可以跟踪它并找到包含数据库登录信息的文件。

有想法吗?

First off, I realize that there is no such thing as a perfectly secure solution (and even if there were, its usability would be crap).

That said, how do you protect your MySQL database from being compromised by someone downloading your code and picking through it? Based on my experience with PHP, it seems obligatory to store it within the code at some point or another, which sends up flags for me. I can see where refactoring to obfuscate variable, constant, and (user-defined) function names could be beneficial, but in the end it'd still be possible to trace through it and find the file with the DB login information.

Ideas?

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

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

发布评论

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

评论(3

樱花细雨 2024-08-19 17:07:05

通常,MySQL 身份验证信息存储在外部配置文件中。基于 Web 的应用程序使用的 MySQL 用户被授予有限的权限,例如 SELECT、INSERT、UPDATE、DELETE,但未授予 ALTER、DROP、DELETE 等权限。如果您想向公众发布代码,您不会包含您的私有配置文件,而是包含通用/指导/最小配置文件。

以加密格式存储 MySQL 身份验证信息有点愚蠢,因为您还需要在本地存储私钥/未加密。如果未经身份验证的用户可以轻松查看服务器上的代码或配置文件,那么问题不在于代码,而在于您的服务器设置和配置。配置。

Usually the MySQL auth information is stored in an external configuration file. The MySQL user used by the web-based app is given limited permissions such as SELECT, INSERT, UPDATE, DELETE and not given permissions such as ALTER, DROP, DELETE. If you want to release the code to the public you would not include your private config file, but a generic/instructional/minimal config file instead.

Storing the MySQL auth info in an encrypted format is somewhat silly, as you'd need to store the private key / unencryption locally as well. If it is trivial for an unauthenticated user to view the code or configuration files on your server the problem isn't the code - it's your server setup & config.

物价感观 2024-08-19 17:07:05

通过在 Web 根目录之外存储任何硬编码信息(在配置文件或脚本中)以及抑​​制(在生产代码上)错误消息,可以提高安全性。这样,您的用户就不会看到 userValidate() 只需要三个参数

Security can be assisted by storing any hard-coded information (in config files or scripts) outside of the web-root, and by suppressing (on the production code) error messages. That way, hopefully, your users won't see that userValidate() expects exactly three paramaters.

十级心震 2024-08-19 17:07:05

pygorex1 是正确的,您应该使用外部配置文件,其中“外部”表示 Web 根目录之外的文件。因此,即使您的 Web 服务器中存在允许用户查看源代码的配置错误,他们也无法看到数据库凭据,因为无法通过浏览器直接访问它们。

pygorex1 在用户权限上也是正确的。将 mysql 用户的访问权限限制在最低限度始终是首选。即使黑客获得了您的 mysql 密码和用户名,如果用户权限仅限于 SELECT 查询等,他也无法造成重大损害。他忘记提到的一件事是,mysql 用户应该只被允许从 localhost(或从 Web 应用程序所在的任何主机)登录,切勿在允许的主机中使用通配符。

pygorex1 is correct, you should use external configuration files where "external" means a file outside the web root. So even if there would be a configuration error in your web server which would allow the user to see your source code, they would not be able to see the database credentials since they cannot be accessed directly via the browser.

pygorex1 is also right on the user permissions. Limiting the mysql user's access to a minimum is always preferred. Even if a hacker would get the your mysql password and username, he would not be able to do significant damage if the user permissions are only limited to eg SELECT-queries. One thing he forgot to mention was that the mysql user should only be allowed to log in from localhost (or from whatever host the web application is on), never use wildcards in the allowed hosts.

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