PHP 的安全性如何?
我对 PHP 编码有点陌生,我知道如果您没有清理 PHP 代码,恶意用户可能会攻击网站。我想知道他们是否需要数据输入框(例如文件提交或用户名/密码输入字段)?
像“include (header.php)”这样的命令是否也需要某种安全性,或者它们本质上是安全的?
I am somewhat new to PHP coding and I am aware that malicious users can hack a website if you have not sanitized your PHP code. What I am wondering is whether they need a data entry box (like for file submissions, or user-name/password entry fields)?.
Do commands like "include (header.php)" also need some sort of security or are they innately safe?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
就像任何其他语言一样,PHP 代码与程序员编写的代码一样安全。
与任何其他语言一样,单个(甚至常见)安全风险数量过多且详细,无法包含在 StackOverflow 答案中。
查找一本涵盖安全 PHP 编码的书。
Just like any other language, PHP code is as secure as the programmer writes it.
Also like any other language, individual (and even common) security risks are too numerous and detailed to include in a StackOverflow answer.
Find a book which covers Secure PHP coding.
不要相信用户。
非常安全
意味着您需要考虑如何设置 $someFile 。如果您使用用户提供给您的任何数据来设置 $someFile 的值,您最好对其进行清理。
Don't trust the user.
is quite safe
means you want to think about how $someFile gets set. If you use any data that was given to you by a user to set $someFile's value, you'd better sanitize it.
引用 RSnake 在 2006 年 sla.ckers.org 上的帖子:
来源:http://sla.ckers.org/forum/read.php?2 ,3976
其中很好地介绍了 Hardened PHP 项目 Suhosin http://www.hardened-php .net/suhosin/ 和 Esser 的 PHP Bug 月项目 http://www.php-security。组织/
To quote RSnake from a sla.ckers.org post back in 2006:
source: http://sla.ckers.org/forum/read.php?2,3976
Which introduces nicely the Hardened PHP project, Suhosin http://www.hardened-php.net/suhosin/ and Esser's Month of PHP Bugs project http://www.php-security.org/
PHP 与任何事物一样安全。但不是默认的,它依赖于程序员的技能。与 .NET 不同,.NET 默认情况下有助于提高安全性。
包含是安全的,只是如果路径是动态生成的,请小心。
下面的内容是无害的(取决于 myfile.php 中的代码)
PHP is as secure as anything. But not by default, it relies on the skills of the programmer. Unlike .NET which tends to help out with security by default.
Includes are safe just be careful if the paths are being dyanmically generated.
The below is harmless (depending on the code in myfile.php)
关于数据输入框,应该关注 SQL 注入攻击、溢出、错误字符等。查看诸如
filter_var()
、mysql_real_escape_string()
、等函数pg_escape_string() 对于初学者来说。
Regarding data entry boxes, one should be concerned about SQL injection attacks, overflow, bad chars, etc. Check out functions like
filter_var()
,mysql_real_escape_string()
,pg_escape_string()
for starters.同意这里每个人的观点 - PHP 本身并不比任何其他语言更安全或更不安全。
不过,您应该深入研究您的
php.ini
文件。您可能应该了解所有指令。这是很多人很早就犯错误的地方。Agree with everyone here - PHP is not really more or less secure in and of itself than any other language.
You should look deeply into your
php.ini
file though. You should probably learn about all of the directives. This is where a lot of people make mistakes early on.您的问题相当广泛和笼统,但要解决您提出的具体观点:
相对安全,但
可能是一个危险的安全漏洞,具体取决于
$header
的分配方式以及是否已清理。Your question is rather broad and general but to address a specific point you made:
is relatively safe but
is potentially a dangerous security hole depending on how
$header
was assigned and if it's been sanitized.具体回答这个问题,PHP 作为一种语言是非常安全的。对于语言本身,建议您使用最新的稳定版本以保持基于语言的安全性。 php 维护者是创建和修复错误的人;)
To answer the question specifically, PHP as a language is very secure. For the language itself, it is recommended that you use the latest stable build to keep on top of language-based security. The php maintainers are the ones that create and fix bugs ;)