数据库凭据以纯文本形式存储可以吗? [英] Is it okay that database credentials are stored in plain text?

查看:17
本文介绍了数据库凭据以纯文本形式存储可以吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,Django 数据库主机/用户/密码以纯文本形式存储在项目 settings.py 文件中.

By default, the Django database host/user/password are stored in the project settings.py file in plain text.

目前我似乎想不出更好的方法,但这似乎违反了密码存储的最佳做法.当然,如果攻击者可以访问设置文件,那么一切都可能已经丢失.即使文件被加密,到那时攻击者也可能有办法解密它.

I can't seem to think of a better way at the moment, but this seems to be against best practices for password storage. Granted, if an attacker has access to the settings file, then all is probably already lost. Even if the the file were encrypted, the attacker would probably have the means to decrypt it by then.

这样好吗?

推荐答案

您说得对,将密码存储在明文和 settings.py 文件中是不安全的.您可以通过以下方式提高安全性:

You are correct that storing passwords in plaintext and in a settings.py file is not good security. You could increase security by:

  • 正确设置权限(这取决于您的设置).理想情况下,只有 python 应该能够读取该文件.

  • Setting the permissions correctly (this will depend on your set up). Ideally only python should be able to read the file.

将文件存储在 wwwhtdocs 根目录之外.如果此时攻击者仍然可以访问它们,那么无论如何你都被搞砸了.

Storing the file out of the www or htdocs root. If at this point an attacker still has access to them, you are screwed anyways.

为了增加安全性,您可以使用对称加密(例如:AES)对连接设置进行加密.将密钥存储在其他地方.因此,即使有人设法访问了连接设置,他们仍然需要找到密钥.主要缺点是现在你必须重写连接方法.

For added security, you can encrypt the connection settings using symmetric encryption (eg: AES). Store the key somewhere else. So even if someone managed to access the connection settings, they'd still need to find the key. The main drawback is that now you have to rewrite the connection method.

这篇关于数据库凭据以纯文本形式存储可以吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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