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

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9653
e67609152c5e
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
19 19
20 20
21 def getChecks(): 21 def getChecks():
22 """ 22 """
23 Public method to get a dictionary with checks handled by this module. 23 Public method to get a dictionary with checks handled by this module.
24 24
25 @return dictionary containing checker lists containing checker function and 25 @return dictionary containing checker lists containing checker function and
26 list of codes 26 list of codes
27 @rtype dict 27 @rtype dict
28 """ 28 """
29 return { 29 return {
34 34
35 35
36 def checkLinuxCommandsWildcardInjection(reportError, context, config): 36 def checkLinuxCommandsWildcardInjection(reportError, context, config):
37 """ 37 """
38 Function to check for use of wildcard injection. 38 Function to check for use of wildcard injection.
39 39
40 @param reportError function to be used to report errors 40 @param reportError function to be used to report errors
41 @type func 41 @type func
42 @param context security context object 42 @param context security context object
43 @type SecurityContext 43 @type SecurityContext
44 @param config dictionary with configuration data 44 @param config dictionary with configuration data
45 @type dict 45 @type dict
46 """ 46 """
47 subProcessFunctionNames = ( 47 subProcessFunctionNames = (
48 config["shell_injection_subprocess"] 48 config["shell_injection_subprocess"]
49 if config and "shell_injection_subprocess" in config else 49 if config and "shell_injection_subprocess" in config
50 SecurityDefaults["shell_injection_subprocess"] 50 else SecurityDefaults["shell_injection_subprocess"]
51 ) 51 )
52 52
53 shellFunctionNames = ( 53 shellFunctionNames = (
54 config["shell_injection_shell"] 54 config["shell_injection_shell"]
55 if config and "shell_injection_shell" in config else 55 if config and "shell_injection_shell" in config
56 SecurityDefaults["shell_injection_shell"] 56 else SecurityDefaults["shell_injection_shell"]
57 ) 57 )
58 58
59 vulnerableFunctions = ['chown', 'chmod', 'tar', 'rsync'] 59 vulnerableFunctions = ["chown", "chmod", "tar", "rsync"]
60 if ( 60 if (
61 (context.callFunctionNameQual in shellFunctionNames or 61 context.callFunctionNameQual in shellFunctionNames
62 (context.callFunctionNameQual in subProcessFunctionNames and 62 or (
63 context.checkCallArgValue('shell', 'True'))) and 63 context.callFunctionNameQual in subProcessFunctionNames
64 context.callArgsCount >= 1 64 and context.checkCallArgValue("shell", "True")
65 ): 65 )
66 ) and context.callArgsCount >= 1:
66 callArgument = context.getCallArgAtPosition(0) 67 callArgument = context.getCallArgAtPosition(0)
67 argumentString = '' 68 argumentString = ""
68 if isinstance(callArgument, list): 69 if isinstance(callArgument, list):
69 for li in callArgument: 70 for li in callArgument:
70 argumentString += ' {0}'.format(li) 71 argumentString += " {0}".format(li)
71 elif isinstance(callArgument, str): 72 elif isinstance(callArgument, str):
72 argumentString = callArgument 73 argumentString = callArgument
73 74
74 if argumentString != '': 75 if argumentString != "":
75 for vulnerableFunction in vulnerableFunctions: 76 for vulnerableFunction in vulnerableFunctions:
76 if ( 77 if vulnerableFunction in argumentString and "*" in argumentString:
77 vulnerableFunction in argumentString and 78 lineNo = context.getLinenoForCallArg("shell")
78 '*' in argumentString
79 ):
80 lineNo = context.getLinenoForCallArg('shell')
81 if lineNo < 1: 79 if lineNo < 1:
82 lineNo = context.node.lineno 80 lineNo = context.node.lineno
83 offset = context.getOffsetForCallArg('shell') 81 offset = context.getOffsetForCallArg("shell")
84 if offset < 0: 82 if offset < 0:
85 offset = context.node.col_offset 83 offset = context.node.col_offset
86 reportError( 84 reportError(
87 lineNo - 1, 85 lineNo - 1,
88 offset, 86 offset,
89 "S609", 87 "S609",
90 "H", 88 "H",
91 "M", 89 "M",
92 context.callFunctionNameQual 90 context.callFunctionNameQual,
93 ) 91 )

eric ide

mercurial