通过不安全连接下载敏感文件¶
ID: js/insecure-download
Kind: path-problem
Security severity: 8.1
Severity: error
Precision: high
Tags:
- security
- external/cwe/cwe-829
Query suites:
- javascript-code-scanning.qls
- javascript-security-extended.qls
- javascript-security-and-quality.qls
通过未加密的连接下载可执行文件或其他敏感文件可能会使服务器容易受到中间人攻击 (MITM) 的攻击。这种攻击允许攻击者将任意内容插入下载的文件中,在最坏的情况下,允许攻击者在易受攻击的系统上执行任意代码。
建议¶
在下载可执行文件或其他敏感文件时使用安全的传输协议。
示例¶
在这个示例中,服务器使用node-fetch
库从远程 URL 下载 shell 脚本,然后执行此 shell 脚本。
const fetch = require("node-fetch");
const cp = require("child_process");
fetch('http://mydownload.example.org/myscript.sh')
.then(res => res.text())
.then(script => cp.execSync(script));
HTTP 协议容易受到 MITM 攻击,因此攻击者可能用任意代码替换下载的 shell 脚本,从而使攻击者完全控制系统。
下面的示例通过将 HTTP 协议替换为 HTTPS 协议修复了该问题。
const fetch = require("node-fetch");
const cp = require("child_process");
fetch('https://mydownload.example.org/myscript.sh')
.then(res => res.text())
.then(script => cp.execSync(script));