应用程序的安全性非常重要,解决安全问题的方法有很多,但一个有效的入门方法是解决 OWASP(开放 Web 应用程序安全项目)确定的十大安全问题。在本文中,我们将介绍当前应用程序的十大安全漏洞。
OWASP 是一个致力于 Web 应用程序安全的国际组织,社区每四年发布一次OWASP Top 10报告,其中概述了 Web 应用程序最紧迫的安全问题。我们将从 PHP 开发人员的角度审视这些漏洞,但它们与使用任何编程语言构建应用程序都相关。
OWASP 安全漏洞:概述和比较
2021 年 OWASP Top 10 列表列出了 10 个最危险的 Web 应用程序安全漏洞。如果我们将当前列表与 2017 年列表进行比较,我们可以看到列表中仍然存在一些安全漏洞,但位置不同,并且列表中还包含一些新的安全漏洞。
下表比较了 2017 年和 2021 年的列表。(2021 年列表中引入的安全漏洞以粗体标出,其余的只是重新排列)
2017 OWASP Top 10 | 2021 OWASP Top 10 |
---|---|
#1 – Injection | #1 – Broken Access Control |
#2 – Broken Authentication | #2 – Cryptographic Failures |
#3 – Sensitive Data Exposure | #3 – Injection |
#4 – XML External Entities (XXE) | #4 – Insecure Design |
#5 – Broken Access Control | #5 – Security Misconfiguration |
#6 – Security Misconfiguration | #6 – Vulnerable and Outdated Components |
#7 – Cross-site Scripting (XSS) | #7 – Identification and Authentication Failures |
#8 – Insecure Deserialization | #8 – Software and Data Integrity Failures |
#9 – Using Components with Known Vulnerabilities | #9 – Security Logging and Monitoring Failures |
#10 – Insufficient Logging and Monitoring | #10 – Server-side Request Forgery (SSRF) |
该表表明大多数针对 Web 应用程序的安全漏洞都没有改变。当开发人员试图修复这些缺陷时,他们的方法发生了变化。与普遍的看法相反,避免这些安全漏洞很容易入手;我们只需要知道适用于特定安全问题的一些基本规则。
让我们深入研究这些安全问题。
损坏的访问控制
根据 2021 年版的 OWASP,我们最应该关注的问题是访问控制被破坏。损坏的访问控制就像它听起来的那样:当我们对控制应用程序的访问方式存在缺陷时,就会发生这种情况。损坏的访问控制示例如下图所示。
<form method="post" action="">
<input type="text" name="Username" placeholder="Your Username?">
<input type="text" name="Password" placeholder="Your Password?">
<input type="submit" name="Submit" value="Log In">
</form>
<?php
if(isset($_POST['Submit'])) {
$Username = $_POST['Username'];
$Password = $_POST['Password'];
if(!empty($Username)) {
if(!empty($Password)) {
header("loggedin_page.php");
exit;
}
}
}
?>
看到问题了吗?该代码只是检查用户名和密码字段是否不为空。如何在数据库中运行几个查询以确保用户名和密码存在?