src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Security/Checks/blackListImports.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9325
8157eb19aba5
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
14 # 14 #
15 # SPDX-License-Identifier: Apache-2.0 15 # SPDX-License-Identifier: Apache-2.0
16 # 16 #
17 17
18 _blacklists = { 18 _blacklists = {
19 "S401": ([ 19 "S401": (["telnetlib"], "H"),
20 'telnetlib'], 20 "S402": (["ftplib"], "H"),
21 "H"), 21 "S403": (["pickle", "cPickle", "dill", "shelve"], "L"),
22 "S402": ([ 22 "S404": (["subprocess"], "L"),
23 'ftplib'], 23 "S405": (["xml.etree.cElementTree", "xml.etree.ElementTree"], "L"),
24 "H"), 24 "S406": (["xml.sax"], "L"),
25 "S403": ([ 25 "S407": (["xml.dom.expatbuilder"], "L"),
26 'pickle', 26 "S408": (["xml.dom.minidom"], "L"),
27 'cPickle', 27 "S409": (["xml.dom.pulldom"], "L"),
28 'dill', 28 "S410": (["lxml"], "L"),
29 'shelve'], 29 "S411": (["xmlrpclib"], "H"),
30 "L"), 30 "S412": (
31 "S404": ([ 31 [
32 'subprocess'], 32 "wsgiref.handlers.CGIHandler",
33 "L"), 33 "twisted.web.twcgi.CGIScript",
34 "S405": ([ 34 "twisted.web.twcgi.CGIDirectory",
35 'xml.etree.cElementTree', 35 ],
36 'xml.etree.ElementTree'], 36 "H",
37 "L"), 37 ),
38 "S406": ([ 38 "S413": (
39 'xml.sax'], 39 [
40 "L"), 40 "Crypto.Cipher",
41 "S407": ([ 41 "Crypto.Hash",
42 'xml.dom.expatbuilder'], 42 "Crypto.IO",
43 "L"), 43 "Crypto.Protocol",
44 "S408": ([ 44 "Crypto.PublicKey",
45 'xml.dom.minidom'], 45 "Crypto.Random",
46 "L"), 46 "Crypto.Signature",
47 "S409": ([ 47 "Crypto.Util",
48 'xml.dom.pulldom'], 48 ],
49 "L"), 49 "H",
50 "S410": ([ 50 ),
51 'lxml'],
52 "L"),
53 "S411": ([
54 'xmlrpclib'],
55 "H"),
56 "S412": ([
57 'wsgiref.handlers.CGIHandler',
58 'twisted.web.twcgi.CGIScript',
59 'twisted.web.twcgi.CGIDirectory'],
60 "H"),
61 "S413": ([
62 'Crypto.Cipher',
63 'Crypto.Hash',
64 'Crypto.IO',
65 'Crypto.Protocol',
66 'Crypto.PublicKey',
67 'Crypto.Random',
68 'Crypto.Signature',
69 'Crypto.Util'],
70 "H"),
71 } 51 }
72 52
73 53
74 def getChecks(): 54 def getChecks():
75 """ 55 """
76 Public method to get a dictionary with checks handled by this module. 56 Public method to get a dictionary with checks handled by this module.
77 57
78 @return dictionary containing checker lists containing checker function and 58 @return dictionary containing checker lists containing checker function and
79 list of codes 59 list of codes
80 @rtype dict 60 @rtype dict
81 """ 61 """
82 return { 62 return {
93 73
94 74
95 def checkBlacklist(reportError, context, config): 75 def checkBlacklist(reportError, context, config):
96 """ 76 """
97 Function to check for blacklisted method calls. 77 Function to check for blacklisted method calls.
98 78
99 @param reportError function to be used to report errors 79 @param reportError function to be used to report errors
100 @type func 80 @type func
101 @param context security context object 81 @param context security context object
102 @type SecurityContext 82 @type SecurityContext
103 @param config dictionary with configuration data 83 @param config dictionary with configuration data
104 @type dict 84 @type dict
105 """ 85 """
106 nodeType = context.node.__class__.__name__ 86 nodeType = context.node.__class__.__name__
107 87
108 if nodeType.startswith('Import'): 88 if nodeType.startswith("Import"):
109 prefix = "" 89 prefix = ""
110 if ( 90 if nodeType == "ImportFrom" and context.node.module is not None:
111 nodeType == "ImportFrom" and
112 context.node.module is not None
113 ):
114 prefix = context.node.module + "." 91 prefix = context.node.module + "."
115 92
116 for code in _blacklists: 93 for code in _blacklists:
117 qualnames, severity = _blacklists[code] 94 qualnames, severity = _blacklists[code]
118 for name in context.node.names: 95 for name in context.node.names:
122 context.node.lineno - 1, 99 context.node.lineno - 1,
123 context.node.col_offset, 100 context.node.col_offset,
124 code, 101 code,
125 severity, 102 severity,
126 "H", 103 "H",
127 name.name 104 name.name,
128 ) 105 )

eric ide

mercurial