32 list of codes |
32 list of codes |
33 @rtype dict |
33 @rtype dict |
34 """ |
34 """ |
35 return { |
35 return { |
36 "Str": [ |
36 "Str": [ |
37 (checkHardcodedPasswordAsString, ("S105",)), |
37 (checkHardcodedPasswordAsString, ("S-105",)), |
38 ], |
38 ], |
39 "Call": [ |
39 "Call": [ |
40 (checkHardcodedPasswordAsFunctionArg, ("S106",)), |
40 (checkHardcodedPasswordAsFunctionArg, ("S-106",)), |
41 ], |
41 ], |
42 "FunctionDef": [ |
42 "FunctionDef": [ |
43 (checkHardcodedPasswordAsDefault, ("S107",)), |
43 (checkHardcodedPasswordAsDefault, ("S-107",)), |
44 ], |
44 ], |
45 } |
45 } |
46 |
46 |
47 |
47 |
48 def checkHardcodedPasswordAsString(reportError, context, _config): |
48 def checkHardcodedPasswordAsString(reportError, context, _config): |
62 for targ in node._securityParent.targets: |
62 for targ in node._securityParent.targets: |
63 if isinstance(targ, ast.Name) and RE_CANDIDATES.search(targ.id): |
63 if isinstance(targ, ast.Name) and RE_CANDIDATES.search(targ.id): |
64 reportError( |
64 reportError( |
65 context.node.lineno - 1, |
65 context.node.lineno - 1, |
66 context.node.col_offset, |
66 context.node.col_offset, |
67 "S105", |
67 "S-105", |
68 "L", |
68 "L", |
69 "M", |
69 "M", |
70 node.value, |
70 node.value, |
71 ) |
71 ) |
72 |
72 |
78 assign = node._securityParent._securityParent._securityParent |
78 assign = node._securityParent._securityParent._securityParent |
79 if isinstance(assign, ast.Assign) and AstUtilities.isString(assign.value): |
79 if isinstance(assign, ast.Assign) and AstUtilities.isString(assign.value): |
80 reportError( |
80 reportError( |
81 context.node.lineno - 1, |
81 context.node.lineno - 1, |
82 context.node.col_offset, |
82 context.node.col_offset, |
83 "S105", |
83 "S-105", |
84 "L", |
84 "L", |
85 "M", |
85 "M", |
86 assign.value.value, |
86 assign.value.value, |
87 ) |
87 ) |
88 |
88 |
95 and AstUtilities.isString(comp.comparators[0]) |
95 and AstUtilities.isString(comp.comparators[0]) |
96 ): |
96 ): |
97 reportError( |
97 reportError( |
98 context.node.lineno - 1, |
98 context.node.lineno - 1, |
99 context.node.col_offset, |
99 context.node.col_offset, |
100 "S105", |
100 "S-105", |
101 "L", |
101 "L", |
102 "M", |
102 "M", |
103 comp.comparators[0].s, |
103 comp.comparators[0].s, |
104 ) |
104 ) |
105 |
105 |
119 for kw in context.node.keywords: |
119 for kw in context.node.keywords: |
120 if AstUtilities.isString(kw.value) and RE_CANDIDATES.search(kw.arg): |
120 if AstUtilities.isString(kw.value) and RE_CANDIDATES.search(kw.arg): |
121 reportError( |
121 reportError( |
122 context.node.lineno - 1, |
122 context.node.lineno - 1, |
123 context.node.col_offset, |
123 context.node.col_offset, |
124 "S106", |
124 "S-106", |
125 "L", |
125 "L", |
126 "M", |
126 "M", |
127 kw.value.value, |
127 kw.value.value, |
128 ) |
128 ) |
129 |
129 |