File tree Expand file tree Collapse file tree
javascript/ql/src/Security/CWE-829 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44<qhelp >
55 <overview >
66 <p >
7- Placeholder
7+ Downloading executeables or other sensitive files over an unencrypted connection
8+ can leave a server open to man-in-the-middle attacks (MITM).
9+ Such a man-in-the-middle attack can allow an attacker to insert arbitary content
10+ into the downloaded file, and in the worst case allow the attacker to execute
11+ arbitary code on the vulnerable system.
812 </p >
9-
1013 </overview >
1114 <recommendation >
12-
1315 <p >
14- Placeholder
16+ Use an transfer protocol that includes encryption when downloading executeables or other sensitive files.
1517 </p >
16-
1718 </recommendation >
1819 <example >
19-
2020 <p >
21- Placeholder
21+ In this example a server downloads a shell script from a remote URL using the <code >node-fetch</code >
22+ library, and then executes this shell script.
2223 </p >
23-
24+ <sample src =" examples/insecure-download.js" />
25+ <p >
26+ The HTTP protocol is vulnerable to MITM, and thus an attacker could potentially replace the downloaded
27+ shell script with arbitary code, which allows the attacker complete control over the attacked system.
28+ </p >
29+ <p >
30+ The issue has been fixed in the below example by replacing the HTTP protocol with the HTTPS protocol.
31+ </p >
32+ <sample src =" examples/insecure-download.js" />
2433 </example >
2534
2635 <references >
36+ <li >OWASP: <a href =" https://owasp.org/www-community/attacks/Man-in-the-middle_attack" >Man-in-the-middle attack</a >.</li >
2737 </references >
28-
2938</qhelp >
Original file line number Diff line number Diff line change 1+ const fetch = require ( "node-fetch" ) ;
2+ const cp = require ( "child_process" ) ;
3+
4+ fetch ( 'http://mydownload.example.org/myscript.sh' )
5+ . then ( res => res . text ( ) )
6+ . then ( script => cp . execSync ( script ) ) ;
Original file line number Diff line number Diff line change 1+ const fetch = require ( "node-fetch" ) ;
2+ const cp = require ( "child_process" ) ;
3+
4+ fetch ( 'https://mydownload.example.org/myscript.sh' )
5+ . then ( res => res . text ( ) )
6+ . then ( script => cp . execSync ( script ) ) ;
You can’t perform that action at this time.
0 commit comments