|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing checks for using requests without timeout. |
|
8 """ |
|
9 |
|
10 # |
|
11 # This is a modified version of the one found in the bandit package. |
|
12 # |
|
13 # SPDX-License-Identifier: Apache-2.0 |
|
14 # |
|
15 |
|
16 |
|
17 def getChecks(): |
|
18 """ |
|
19 Public method to get a dictionary with checks handled by this module. |
|
20 |
|
21 @return dictionary containing checker lists containing checker function and |
|
22 list of codes |
|
23 @rtype dict |
|
24 """ |
|
25 return { |
|
26 "Call": [ |
|
27 (checkRequestWithouTimeout, ("S114",)), |
|
28 ], |
|
29 } |
|
30 |
|
31 |
|
32 def checkRequestWithouTimeout(reportError, context, config): |
|
33 """ |
|
34 Function to check for use of requests without timeout. |
|
35 |
|
36 @param reportError function to be used to report errors |
|
37 @type func |
|
38 @param context security context object |
|
39 @type SecurityContext |
|
40 @param config dictionary with configuration data |
|
41 @type dict |
|
42 """ |
|
43 httpVerbs = ("get", "options", "head", "post", "put", "patch", "delete") |
|
44 if ( |
|
45 "requests" in context.callFunctionNameQual |
|
46 and context.callFunctionName in httpVerbs |
|
47 ): |
|
48 # check for missing timeout |
|
49 if context.checkCallArgValue("timeout") is None: |
|
50 reportError( |
|
51 context.node.lineno - 1, |
|
52 context.node.col_offset, |
|
53 "S114.1", |
|
54 "M", |
|
55 "L", |
|
56 ) |
|
57 |
|
58 # check for timeout=None |
|
59 if context.checkCallArgValue("timeout", "None"): |
|
60 reportError( |
|
61 context.node.lineno - 1, |
|
62 context.node.col_offset, |
|
63 "S114.2", |
|
64 "M", |
|
65 "L", |
|
66 ) |