|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2020 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing checks for the use of yaml load functions. |
|
8 """ |
|
9 |
|
10 # |
|
11 # This is a modified version of the one found in the bandit package. |
|
12 # |
|
13 # Original Copyright (c) 2016 Rackspace, Inc. |
|
14 # |
|
15 # SPDX-License-Identifier: Apache-2.0 |
|
16 # |
|
17 |
|
18 |
|
19 def getChecks(): |
|
20 """ |
|
21 Public method to get a dictionary with checks handled by this module. |
|
22 |
|
23 @return dictionary containing checker lists containing checker function and |
|
24 list of codes |
|
25 @rtype dict |
|
26 """ |
|
27 return { |
|
28 "Call": [ |
|
29 (checkYamlLoad, ("S506",)), |
|
30 ], |
|
31 } |
|
32 |
|
33 |
|
34 def checkYamlLoad(reportError, context, config): |
|
35 """ |
|
36 Function to check for the use of of yaml load functions. |
|
37 |
|
38 @param reportError function to be used to report errors |
|
39 @type func |
|
40 @param context security context object |
|
41 @type SecurityContext |
|
42 @param config dictionary with configuration data |
|
43 @type dict |
|
44 """ |
|
45 imported = context.isModuleImportedExact('yaml') |
|
46 qualname = context.callFunctionNameQual |
|
47 if not imported and isinstance(qualname, str): |
|
48 return |
|
49 |
|
50 qualnameList = qualname.split('.') |
|
51 func = qualnameList[-1] |
|
52 if all([ |
|
53 'yaml' in qualnameList, |
|
54 func == 'load', |
|
55 not context.checkCallArgValue('Loader', 'SafeLoader'), |
|
56 not context.checkCallArgValue('Loader', 'CSafeLoader'), |
|
57 ]): |
|
58 reportError( |
|
59 context.node.lineno - 1, |
|
60 context.node.col_offset, |
|
61 "S506", |
|
62 "M", |
|
63 "H" |
|
64 ) |