使用 .txt 文件作为元标记数据库安全吗?
Is using a .txt file as database of meta tags secure?
我遇到 "printing" 之前的变量 snippet that uses the meta_tags.txt as a database of meta tags for its website's pages. I was planning to implement it in one of my projects. I am also planning in using HTMLPurifier。
作为一个安全狂,这种方法安全吗?还是我必须添加额外的安全措施来防止其他恶意攻击?也许,MySQL table 而不是文本文档?
我看到使用此方法的唯一风险是,如果您希望保护敏感信息,请确保通过 Apache 的 .htaccess
保护该文件,如果该文件包含任何以后或您想要为用户群、时事通讯等其他事物建立数据库
例如:
<files "file.txt">
deny from all
</files>
并放置在服务器的 webroot 之外。
但是,使用文本文件作为数据库需要大量工作,但在更新、删除、搜索等修改时,您可能需要考虑一下您的选择。
其中之一是使用数据库和准备好的语句也是一个不错的选择,并且更易于管理。
参考文献:
- http://dev.mysql.com/doc/refman/5.7/en/sql-syntax.html
- https://en.wikipedia.org/wiki/Prepared_statement
- http://php.net/manual/en/pdo.prepared-statements.php
- http://php.net/manual/en/mysqli.prepare.php
平面文件数据库引用:
- https://en.wikipedia.org/wiki/Flat_file_database
- http://www.sqlite.org/ (works well with PHP http://php.net/sqlite)
JSON也是另一种选择:
htaccess 文件名前带有 .
(点)的是您的朋友。
至少在 Apache/Linux 环境下。
只需在每个 .txt 文件的当前名称前添加一个点,这样您就可以生成该文件 system/hidden。
而不是 /my/dir/outside/root/mymetadb.txt
- /my/dir/outside/root/.mymetadb.txt
然后将其添加到您的主 .htaccess 文件中。
RewriteEngine On
RewriteBase /
RewriteRule (^\.|/\.) - [F]
RewriteBase /
可能是不必要的。
在此之后,无论是目录还是文件,每一个都以一个点开头,最终用户将 forbidden/unreachable。
如果您只有服务器 webroot 访问权限,并且确实需要文本数据库文件,那么这是理想的选择。
考虑自定义数据库文件,考虑 .php 文件而不是普通的 .txt。
您可以通过 file_get_contents
、require
读取自定义 .mydb.php
文件,通常需要时 var_export($contents)
进入。 :)
我遇到 "printing" 之前的变量 snippet that uses the meta_tags.txt as a database of meta tags for its website's pages. I was planning to implement it in one of my projects. I am also planning in using HTMLPurifier。
作为一个安全狂,这种方法安全吗?还是我必须添加额外的安全措施来防止其他恶意攻击?也许,MySQL table 而不是文本文档?
我看到使用此方法的唯一风险是,如果您希望保护敏感信息,请确保通过 Apache 的 .htaccess
保护该文件,如果该文件包含任何以后或您想要为用户群、时事通讯等其他事物建立数据库
例如:
<files "file.txt">
deny from all
</files>
并放置在服务器的 webroot 之外。
但是,使用文本文件作为数据库需要大量工作,但在更新、删除、搜索等修改时,您可能需要考虑一下您的选择。
其中之一是使用数据库和准备好的语句也是一个不错的选择,并且更易于管理。
参考文献:
- http://dev.mysql.com/doc/refman/5.7/en/sql-syntax.html
- https://en.wikipedia.org/wiki/Prepared_statement
- http://php.net/manual/en/pdo.prepared-statements.php
- http://php.net/manual/en/mysqli.prepare.php
平面文件数据库引用:
- https://en.wikipedia.org/wiki/Flat_file_database
- http://www.sqlite.org/ (works well with PHP http://php.net/sqlite)
JSON也是另一种选择:
htaccess 文件名前带有 .
(点)的是您的朋友。
至少在 Apache/Linux 环境下。
只需在每个 .txt 文件的当前名称前添加一个点,这样您就可以生成该文件 system/hidden。
而不是 /my/dir/outside/root/mymetadb.txt
- /my/dir/outside/root/.mymetadb.txt
然后将其添加到您的主 .htaccess 文件中。
RewriteEngine On
RewriteBase /
RewriteRule (^\.|/\.) - [F]
RewriteBase /
可能是不必要的。
在此之后,无论是目录还是文件,每一个都以一个点开头,最终用户将 forbidden/unreachable。
如果您只有服务器 webroot 访问权限,并且确实需要文本数据库文件,那么这是理想的选择。
考虑自定义数据库文件,考虑 .php 文件而不是普通的 .txt。
您可以通过 file_get_contents
、require
读取自定义 .mydb.php
文件,通常需要时 var_export($contents)
进入。 :)