calls.py 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. #
  2. # Copyright 2016 Hewlett-Packard Development Company, L.P.
  3. #
  4. # SPDX-License-Identifier: Apache-2.0
  5. r"""
  6. ====================================================
  7. Blacklist various Python calls known to be dangerous
  8. ====================================================
  9. This blacklist data checks for a number of Python calls known to have possible
  10. security implications. The following blacklist tests are run against any
  11. function calls encountered in the scanned code base, triggered by encoutering
  12. ast.Call nodes.
  13. B301: pickle
  14. ------------
  15. Pickle and modules that wrap it can be unsafe when used to
  16. deserialize untrusted data, possible security issue.
  17. +------+---------------------+------------------------------------+-----------+
  18. | ID | Name | Calls | Severity |
  19. +======+=====================+====================================+===========+
  20. | B301 | pickle | - pickle.loads | Medium |
  21. | | | - pickle.load | |
  22. | | | - pickle.Unpickler | |
  23. | | | - dill.loads | |
  24. | | | - dill.load | |
  25. | | | - dill.Unpickler | |
  26. | | | - shelve.open | |
  27. | | | - shelve.DbfilenameShelf | |
  28. | | | - jsonpickle.decode | |
  29. | | | - jsonpickle.unpickler.decode | |
  30. | | | - jsonpickle.unpickler.Unpickler | |
  31. | | | - pandas.read_pickle | |
  32. +------+---------------------+------------------------------------+-----------+
  33. B302: marshal
  34. -------------
  35. Deserialization with the marshal module is possibly dangerous.
  36. +------+---------------------+------------------------------------+-----------+
  37. | ID | Name | Calls | Severity |
  38. +======+=====================+====================================+===========+
  39. | B302 | marshal | - marshal.load | Medium |
  40. | | | - marshal.loads | |
  41. +------+---------------------+------------------------------------+-----------+
  42. B303: md5
  43. ---------
  44. Use of insecure MD2, MD4, MD5, or SHA1 hash function.
  45. +------+---------------------+------------------------------------+-----------+
  46. | ID | Name | Calls | Severity |
  47. +======+=====================+====================================+===========+
  48. | B303 | md5 | - hashlib.md5 | Medium |
  49. | | | - hashlib.sha1 | |
  50. | | | - Crypto.Hash.MD2.new | |
  51. | | | - Crypto.Hash.MD4.new | |
  52. | | | - Crypto.Hash.MD5.new | |
  53. | | | - Crypto.Hash.SHA.new | |
  54. | | | - Cryptodome.Hash.MD2.new | |
  55. | | | - Cryptodome.Hash.MD4.new | |
  56. | | | - Cryptodome.Hash.MD5.new | |
  57. | | | - Cryptodome.Hash.SHA.new | |
  58. | | | - cryptography.hazmat.primitives | |
  59. | | | .hashes.MD5 | |
  60. | | | - cryptography.hazmat.primitives | |
  61. | | | .hashes.SHA1 | |
  62. +------+---------------------+------------------------------------+-----------+
  63. B304 - B305: ciphers and modes
  64. ------------------------------
  65. Use of insecure cipher or cipher mode. Replace with a known secure cipher such
  66. as AES.
  67. +------+---------------------+------------------------------------+-----------+
  68. | ID | Name | Calls | Severity |
  69. +======+=====================+====================================+===========+
  70. | B304 | ciphers | - Crypto.Cipher.ARC2.new | High |
  71. | | | - Crypto.Cipher.ARC4.new | |
  72. | | | - Crypto.Cipher.Blowfish.new | |
  73. | | | - Crypto.Cipher.DES.new | |
  74. | | | - Crypto.Cipher.XOR.new | |
  75. | | | - Cryptodome.Cipher.ARC2.new | |
  76. | | | - Cryptodome.Cipher.ARC4.new | |
  77. | | | - Cryptodome.Cipher.Blowfish.new | |
  78. | | | - Cryptodome.Cipher.DES.new | |
  79. | | | - Cryptodome.Cipher.XOR.new | |
  80. | | | - cryptography.hazmat.primitives | |
  81. | | | .ciphers.algorithms.ARC4 | |
  82. | | | - cryptography.hazmat.primitives | |
  83. | | | .ciphers.algorithms.Blowfish | |
  84. | | | - cryptography.hazmat.primitives | |
  85. | | | .ciphers.algorithms.IDEA | |
  86. +------+---------------------+------------------------------------+-----------+
  87. | B305 | cipher_modes | - cryptography.hazmat.primitives | Medium |
  88. | | | .ciphers.modes.ECB | |
  89. +------+---------------------+------------------------------------+-----------+
  90. B306: mktemp_q
  91. --------------
  92. Use of insecure and deprecated function (mktemp).
  93. +------+---------------------+------------------------------------+-----------+
  94. | ID | Name | Calls | Severity |
  95. +======+=====================+====================================+===========+
  96. | B306 | mktemp_q | - tempfile.mktemp | Medium |
  97. +------+---------------------+------------------------------------+-----------+
  98. B307: eval
  99. ----------
  100. Use of possibly insecure function - consider using safer ast.literal_eval.
  101. +------+---------------------+------------------------------------+-----------+
  102. | ID | Name | Calls | Severity |
  103. +======+=====================+====================================+===========+
  104. | B307 | eval | - eval | Medium |
  105. +------+---------------------+------------------------------------+-----------+
  106. B308: mark_safe
  107. ---------------
  108. Use of mark_safe() may expose cross-site scripting vulnerabilities and should
  109. be reviewed.
  110. +------+---------------------+------------------------------------+-----------+
  111. | ID | Name | Calls | Severity |
  112. +======+=====================+====================================+===========+
  113. | B308 | mark_safe | - django.utils.safestring.mark_safe| Medium |
  114. +------+---------------------+------------------------------------+-----------+
  115. B309: httpsconnection
  116. ---------------------
  117. The check for this call has been removed.
  118. Use of HTTPSConnection on older versions of Python prior to 2.7.9 and 3.4.3 do
  119. not provide security, see https://wiki.openstack.org/wiki/OSSN/OSSN-0033
  120. +------+---------------------+------------------------------------+-----------+
  121. | ID | Name | Calls | Severity |
  122. +======+=====================+====================================+===========+
  123. | B309 | httpsconnection | - httplib.HTTPSConnection | Medium |
  124. | | | - http.client.HTTPSConnection | |
  125. | | | - six.moves.http_client | |
  126. | | | .HTTPSConnection | |
  127. +------+---------------------+------------------------------------+-----------+
  128. B310: urllib_urlopen
  129. --------------------
  130. Audit url open for permitted schemes. Allowing use of 'file:'' or custom
  131. schemes is often unexpected.
  132. +------+---------------------+------------------------------------+-----------+
  133. | ID | Name | Calls | Severity |
  134. +======+=====================+====================================+===========+
  135. | B310 | urllib_urlopen | - urllib.urlopen | Medium |
  136. | | | - urllib.request.urlopen | |
  137. | | | - urllib.urlretrieve | |
  138. | | | - urllib.request.urlretrieve | |
  139. | | | - urllib.URLopener | |
  140. | | | - urllib.request.URLopener | |
  141. | | | - urllib.FancyURLopener | |
  142. | | | - urllib.request.FancyURLopener | |
  143. | | | - urllib2.urlopen | |
  144. | | | - urllib2.Request | |
  145. | | | - six.moves.urllib.request.urlopen | |
  146. | | | - six.moves.urllib.request | |
  147. | | | .urlretrieve | |
  148. | | | - six.moves.urllib.request | |
  149. | | | .URLopener | |
  150. | | | - six.moves.urllib.request | |
  151. | | | .FancyURLopener | |
  152. +------+---------------------+------------------------------------+-----------+
  153. B311: random
  154. ------------
  155. Standard pseudo-random generators are not suitable for security/cryptographic
  156. purposes.
  157. +------+---------------------+------------------------------------+-----------+
  158. | ID | Name | Calls | Severity |
  159. +======+=====================+====================================+===========+
  160. | B311 | random | - random.random | Low |
  161. | | | - random.randrange | |
  162. | | | - random.randint | |
  163. | | | - random.choice | |
  164. | | | - random.choices | |
  165. | | | - random.uniform | |
  166. | | | - random.triangular | |
  167. +------+---------------------+------------------------------------+-----------+
  168. B312: telnetlib
  169. ---------------
  170. Telnet-related functions are being called. Telnet is considered insecure. Use
  171. SSH or some other encrypted protocol.
  172. +------+---------------------+------------------------------------+-----------+
  173. | ID | Name | Calls | Severity |
  174. +======+=====================+====================================+===========+
  175. | B312 | telnetlib | - telnetlib.\* | High |
  176. +------+---------------------+------------------------------------+-----------+
  177. B313 - B320: XML
  178. ----------------
  179. Most of this is based off of Christian Heimes' work on defusedxml:
  180. https://pypi.org/project/defusedxml/#defusedxml-sax
  181. Using various XLM methods to parse untrusted XML data is known to be vulnerable
  182. to XML attacks. Methods should be replaced with their defusedxml equivalents.
  183. +------+---------------------+------------------------------------+-----------+
  184. | ID | Name | Calls | Severity |
  185. +======+=====================+====================================+===========+
  186. | B313 | xml_bad_cElementTree| - xml.etree.cElementTree.parse | Medium |
  187. | | | - xml.etree.cElementTree.iterparse | |
  188. | | | - xml.etree.cElementTree.fromstring| |
  189. | | | - xml.etree.cElementTree.XMLParser | |
  190. +------+---------------------+------------------------------------+-----------+
  191. | B314 | xml_bad_ElementTree | - xml.etree.ElementTree.parse | Medium |
  192. | | | - xml.etree.ElementTree.iterparse | |
  193. | | | - xml.etree.ElementTree.fromstring | |
  194. | | | - xml.etree.ElementTree.XMLParser | |
  195. +------+---------------------+------------------------------------+-----------+
  196. | B315 | xml_bad_expatreader | - xml.sax.expatreader.create_parser| Medium |
  197. +------+---------------------+------------------------------------+-----------+
  198. | B316 | xml_bad_expatbuilder| - xml.dom.expatbuilder.parse | Medium |
  199. | | | - xml.dom.expatbuilder.parseString | |
  200. +------+---------------------+------------------------------------+-----------+
  201. | B317 | xml_bad_sax | - xml.sax.parse | Medium |
  202. | | | - xml.sax.parseString | |
  203. | | | - xml.sax.make_parser | |
  204. +------+---------------------+------------------------------------+-----------+
  205. | B318 | xml_bad_minidom | - xml.dom.minidom.parse | Medium |
  206. | | | - xml.dom.minidom.parseString | |
  207. +------+---------------------+------------------------------------+-----------+
  208. | B319 | xml_bad_pulldom | - xml.dom.pulldom.parse | Medium |
  209. | | | - xml.dom.pulldom.parseString | |
  210. +------+---------------------+------------------------------------+-----------+
  211. | B320 | xml_bad_etree | - lxml.etree.parse | Medium |
  212. | | | - lxml.etree.fromstring | |
  213. | | | - lxml.etree.RestrictedElement | |
  214. | | | - lxml.etree.GlobalParserTLS | |
  215. | | | - lxml.etree.getDefaultParser | |
  216. | | | - lxml.etree.check_docinfo | |
  217. +------+---------------------+------------------------------------+-----------+
  218. B321: ftplib
  219. ------------
  220. FTP-related functions are being called. FTP is considered insecure. Use
  221. SSH/SFTP/SCP or some other encrypted protocol.
  222. +------+---------------------+------------------------------------+-----------+
  223. | ID | Name | Calls | Severity |
  224. +======+=====================+====================================+===========+
  225. | B321 | ftplib | - ftplib.\* | High |
  226. +------+---------------------+------------------------------------+-----------+
  227. B322: input
  228. -----------
  229. The check for this call has been removed.
  230. The input method in Python 2 will read from standard input, evaluate and
  231. run the resulting string as python source code. This is similar, though in
  232. many ways worse, than using eval. On Python 2, use raw_input instead, input
  233. is safe in Python 3.
  234. +------+---------------------+------------------------------------+-----------+
  235. | ID | Name | Calls | Severity |
  236. +======+=====================+====================================+===========+
  237. | B322 | input | - input | High |
  238. +------+---------------------+------------------------------------+-----------+
  239. B323: unverified_context
  240. ------------------------
  241. By default, Python will create a secure, verified ssl context for use in such
  242. classes as HTTPSConnection. However, it still allows using an insecure
  243. context via the _create_unverified_context that reverts to the previous
  244. behavior that does not validate certificates or perform hostname checks.
  245. +------+---------------------+------------------------------------+-----------+
  246. | ID | Name | Calls | Severity |
  247. +======+=====================+====================================+===========+
  248. | B323 | unverified_context | - ssl._create_unverified_context | Medium |
  249. +------+---------------------+------------------------------------+-----------+
  250. B325: tempnam
  251. --------------
  252. The check for this call has been removed.
  253. Use of os.tempnam() and os.tmpnam() is vulnerable to symlink attacks. Consider
  254. using tmpfile() instead.
  255. For further information:
  256. https://docs.python.org/2.7/library/os.html#os.tempnam
  257. https://docs.python.org/3/whatsnew/3.0.html?highlight=tempnam
  258. https://bugs.python.org/issue17880
  259. +------+---------------------+------------------------------------+-----------+
  260. | ID | Name | Calls | Severity |
  261. +======+=====================+====================================+===========+
  262. | B325 | tempnam | - os.tempnam | Medium |
  263. | | | - os.tmpnam | |
  264. +------+---------------------+------------------------------------+-----------+
  265. """
  266. import sys
  267. from bandit.blacklists import utils
  268. from bandit.core import issue
  269. def gen_blacklist():
  270. """Generate a list of items to blacklist.
  271. Methods of this type, "bandit.blacklist" plugins, are used to build a list
  272. of items that bandit's built in blacklisting tests will use to trigger
  273. issues. They replace the older blacklist* test plugins and allow
  274. blacklisted items to have a unique bandit ID for filtering and profile
  275. usage.
  276. :return: a dictionary mapping node types to a list of blacklist data
  277. """
  278. sets = []
  279. sets.append(
  280. utils.build_conf_dict(
  281. "pickle",
  282. "B301",
  283. issue.Cwe.DESERIALIZATION_OF_UNTRUSTED_DATA,
  284. [
  285. "pickle.loads",
  286. "pickle.load",
  287. "pickle.Unpickler",
  288. "dill.loads",
  289. "dill.load",
  290. "dill.Unpickler",
  291. "shelve.open",
  292. "shelve.DbfilenameShelf",
  293. "jsonpickle.decode",
  294. "jsonpickle.unpickler.decode",
  295. "jsonpickle.unpickler.Unpickler",
  296. "pandas.read_pickle",
  297. ],
  298. "Pickle and modules that wrap it can be unsafe when used to "
  299. "deserialize untrusted data, possible security issue.",
  300. )
  301. )
  302. sets.append(
  303. utils.build_conf_dict(
  304. "marshal",
  305. "B302",
  306. issue.Cwe.DESERIALIZATION_OF_UNTRUSTED_DATA,
  307. ["marshal.load", "marshal.loads"],
  308. "Deserialization with the marshal module is possibly dangerous.",
  309. )
  310. )
  311. if sys.version_info >= (3, 9):
  312. sets.append(
  313. utils.build_conf_dict(
  314. "md5",
  315. "B303",
  316. issue.Cwe.BROKEN_CRYPTO,
  317. [
  318. "Crypto.Hash.MD2.new",
  319. "Crypto.Hash.MD4.new",
  320. "Crypto.Hash.MD5.new",
  321. "Crypto.Hash.SHA.new",
  322. "Cryptodome.Hash.MD2.new",
  323. "Cryptodome.Hash.MD4.new",
  324. "Cryptodome.Hash.MD5.new",
  325. "Cryptodome.Hash.SHA.new",
  326. "cryptography.hazmat.primitives.hashes.MD5",
  327. "cryptography.hazmat.primitives.hashes.SHA1",
  328. ],
  329. "Use of insecure MD2, MD4, MD5, or SHA1 hash function.",
  330. )
  331. )
  332. else:
  333. sets.append(
  334. utils.build_conf_dict(
  335. "md5",
  336. "B303",
  337. issue.Cwe.BROKEN_CRYPTO,
  338. [
  339. "hashlib.md4",
  340. "hashlib.md5",
  341. "hashlib.sha",
  342. "hashlib.sha1",
  343. "Crypto.Hash.MD2.new",
  344. "Crypto.Hash.MD4.new",
  345. "Crypto.Hash.MD5.new",
  346. "Crypto.Hash.SHA.new",
  347. "Cryptodome.Hash.MD2.new",
  348. "Cryptodome.Hash.MD4.new",
  349. "Cryptodome.Hash.MD5.new",
  350. "Cryptodome.Hash.SHA.new",
  351. "cryptography.hazmat.primitives.hashes.MD5",
  352. "cryptography.hazmat.primitives.hashes.SHA1",
  353. ],
  354. "Use of insecure MD2, MD4, MD5, or SHA1 hash function.",
  355. )
  356. )
  357. sets.append(
  358. utils.build_conf_dict(
  359. "ciphers",
  360. "B304",
  361. issue.Cwe.BROKEN_CRYPTO,
  362. [
  363. "Crypto.Cipher.ARC2.new",
  364. "Crypto.Cipher.ARC4.new",
  365. "Crypto.Cipher.Blowfish.new",
  366. "Crypto.Cipher.DES.new",
  367. "Crypto.Cipher.XOR.new",
  368. "Cryptodome.Cipher.ARC2.new",
  369. "Cryptodome.Cipher.ARC4.new",
  370. "Cryptodome.Cipher.Blowfish.new",
  371. "Cryptodome.Cipher.DES.new",
  372. "Cryptodome.Cipher.XOR.new",
  373. "cryptography.hazmat.primitives.ciphers.algorithms.ARC4",
  374. "cryptography.hazmat.primitives.ciphers.algorithms.Blowfish",
  375. "cryptography.hazmat.primitives.ciphers.algorithms.IDEA",
  376. ],
  377. "Use of insecure cipher {name}. Replace with a known secure"
  378. " cipher such as AES.",
  379. "HIGH",
  380. )
  381. )
  382. sets.append(
  383. utils.build_conf_dict(
  384. "cipher_modes",
  385. "B305",
  386. issue.Cwe.BROKEN_CRYPTO,
  387. ["cryptography.hazmat.primitives.ciphers.modes.ECB"],
  388. "Use of insecure cipher mode {name}.",
  389. )
  390. )
  391. sets.append(
  392. utils.build_conf_dict(
  393. "mktemp_q",
  394. "B306",
  395. issue.Cwe.INSECURE_TEMP_FILE,
  396. ["tempfile.mktemp"],
  397. "Use of insecure and deprecated function (mktemp).",
  398. )
  399. )
  400. sets.append(
  401. utils.build_conf_dict(
  402. "eval",
  403. "B307",
  404. issue.Cwe.OS_COMMAND_INJECTION,
  405. ["eval"],
  406. "Use of possibly insecure function - consider using safer "
  407. "ast.literal_eval.",
  408. )
  409. )
  410. sets.append(
  411. utils.build_conf_dict(
  412. "mark_safe",
  413. "B308",
  414. issue.Cwe.XSS,
  415. ["django.utils.safestring.mark_safe"],
  416. "Use of mark_safe() may expose cross-site scripting "
  417. "vulnerabilities and should be reviewed.",
  418. )
  419. )
  420. # skipped B309 as the check for a call to httpsconnection has been removed
  421. sets.append(
  422. utils.build_conf_dict(
  423. "urllib_urlopen",
  424. "B310",
  425. issue.Cwe.PATH_TRAVERSAL,
  426. [
  427. "urllib.urlopen",
  428. "urllib.request.urlopen",
  429. "urllib.urlretrieve",
  430. "urllib.request.urlretrieve",
  431. "urllib.URLopener",
  432. "urllib.request.URLopener",
  433. "urllib.FancyURLopener",
  434. "urllib.request.FancyURLopener",
  435. "urllib2.urlopen",
  436. "urllib2.Request",
  437. "six.moves.urllib.request.urlopen",
  438. "six.moves.urllib.request.urlretrieve",
  439. "six.moves.urllib.request.URLopener",
  440. "six.moves.urllib.request.FancyURLopener",
  441. ],
  442. "Audit url open for permitted schemes. Allowing use of file:/ or "
  443. "custom schemes is often unexpected.",
  444. )
  445. )
  446. sets.append(
  447. utils.build_conf_dict(
  448. "random",
  449. "B311",
  450. issue.Cwe.INSUFFICIENT_RANDOM_VALUES,
  451. [
  452. "random.random",
  453. "random.randrange",
  454. "random.randint",
  455. "random.choice",
  456. "random.choices",
  457. "random.uniform",
  458. "random.triangular",
  459. ],
  460. "Standard pseudo-random generators are not suitable for "
  461. "security/cryptographic purposes.",
  462. "LOW",
  463. )
  464. )
  465. sets.append(
  466. utils.build_conf_dict(
  467. "telnetlib",
  468. "B312",
  469. issue.Cwe.CLEARTEXT_TRANSMISSION,
  470. ["telnetlib.*"],
  471. "Telnet-related functions are being called. Telnet is considered "
  472. "insecure. Use SSH or some other encrypted protocol.",
  473. "HIGH",
  474. )
  475. )
  476. # Most of this is based off of Christian Heimes' work on defusedxml:
  477. # https://pypi.org/project/defusedxml/#defusedxml-sax
  478. xml_msg = (
  479. "Using {name} to parse untrusted XML data is known to be "
  480. "vulnerable to XML attacks. Replace {name} with its "
  481. "defusedxml equivalent function or make sure "
  482. "defusedxml.defuse_stdlib() is called"
  483. )
  484. sets.append(
  485. utils.build_conf_dict(
  486. "xml_bad_cElementTree",
  487. "B313",
  488. issue.Cwe.IMPROPER_INPUT_VALIDATION,
  489. [
  490. "xml.etree.cElementTree.parse",
  491. "xml.etree.cElementTree.iterparse",
  492. "xml.etree.cElementTree.fromstring",
  493. "xml.etree.cElementTree.XMLParser",
  494. ],
  495. xml_msg,
  496. )
  497. )
  498. sets.append(
  499. utils.build_conf_dict(
  500. "xml_bad_ElementTree",
  501. "B314",
  502. issue.Cwe.IMPROPER_INPUT_VALIDATION,
  503. [
  504. "xml.etree.ElementTree.parse",
  505. "xml.etree.ElementTree.iterparse",
  506. "xml.etree.ElementTree.fromstring",
  507. "xml.etree.ElementTree.XMLParser",
  508. ],
  509. xml_msg,
  510. )
  511. )
  512. sets.append(
  513. utils.build_conf_dict(
  514. "xml_bad_expatreader",
  515. "B315",
  516. issue.Cwe.IMPROPER_INPUT_VALIDATION,
  517. ["xml.sax.expatreader.create_parser"],
  518. xml_msg,
  519. )
  520. )
  521. sets.append(
  522. utils.build_conf_dict(
  523. "xml_bad_expatbuilder",
  524. "B316",
  525. issue.Cwe.IMPROPER_INPUT_VALIDATION,
  526. ["xml.dom.expatbuilder.parse", "xml.dom.expatbuilder.parseString"],
  527. xml_msg,
  528. )
  529. )
  530. sets.append(
  531. utils.build_conf_dict(
  532. "xml_bad_sax",
  533. "B317",
  534. issue.Cwe.IMPROPER_INPUT_VALIDATION,
  535. ["xml.sax.parse", "xml.sax.parseString", "xml.sax.make_parser"],
  536. xml_msg,
  537. )
  538. )
  539. sets.append(
  540. utils.build_conf_dict(
  541. "xml_bad_minidom",
  542. "B318",
  543. issue.Cwe.IMPROPER_INPUT_VALIDATION,
  544. ["xml.dom.minidom.parse", "xml.dom.minidom.parseString"],
  545. xml_msg,
  546. )
  547. )
  548. sets.append(
  549. utils.build_conf_dict(
  550. "xml_bad_pulldom",
  551. "B319",
  552. issue.Cwe.IMPROPER_INPUT_VALIDATION,
  553. ["xml.dom.pulldom.parse", "xml.dom.pulldom.parseString"],
  554. xml_msg,
  555. )
  556. )
  557. sets.append(
  558. utils.build_conf_dict(
  559. "xml_bad_etree",
  560. "B320",
  561. issue.Cwe.IMPROPER_INPUT_VALIDATION,
  562. [
  563. "lxml.etree.parse",
  564. "lxml.etree.fromstring",
  565. "lxml.etree.RestrictedElement",
  566. "lxml.etree.GlobalParserTLS",
  567. "lxml.etree.getDefaultParser",
  568. "lxml.etree.check_docinfo",
  569. ],
  570. (
  571. "Using {name} to parse untrusted XML data is known to be "
  572. "vulnerable to XML attacks. Replace {name} with its "
  573. "defusedxml equivalent function."
  574. ),
  575. )
  576. )
  577. # end of XML tests
  578. sets.append(
  579. utils.build_conf_dict(
  580. "ftplib",
  581. "B321",
  582. issue.Cwe.CLEARTEXT_TRANSMISSION,
  583. ["ftplib.*"],
  584. "FTP-related functions are being called. FTP is considered "
  585. "insecure. Use SSH/SFTP/SCP or some other encrypted protocol.",
  586. "HIGH",
  587. )
  588. )
  589. # skipped B322 as the check for a call to input() has been removed
  590. sets.append(
  591. utils.build_conf_dict(
  592. "unverified_context",
  593. "B323",
  594. issue.Cwe.IMPROPER_CERT_VALIDATION,
  595. ["ssl._create_unverified_context"],
  596. "By default, Python will create a secure, verified ssl context for"
  597. " use in such classes as HTTPSConnection. However, it still allows"
  598. " using an insecure context via the _create_unverified_context "
  599. "that reverts to the previous behavior that does not validate "
  600. "certificates or perform hostname checks.",
  601. )
  602. )
  603. # skipped B324 (used in bandit/plugins/hashlib_new_insecure_functions.py)
  604. # skipped B325 as the check for a call to os.tempnam and os.tmpnam have
  605. # been removed
  606. return {"Call": sets}