eric7/Plugins/CheckerPlugins/CodeStyleChecker/Security/Checks/generalHardcodedTmp.py

branch
eric7
changeset 8312
800c432b34c8
parent 8259
2bbec88047dd
child 8881
54e42bc2437a
equal deleted inserted replaced
8311:4e8b98454baa 8312:800c432b34c8
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2020 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a check for insecure usage of tmp file/directory.
8 """
9
10 #
11 # This is a modified version of the one found in the bandit package.
12 #
13 # Original Copyright 2014 Hewlett-Packard Development Company, L.P.
14 #
15 # SPDX-License-Identifier: Apache-2.0
16 #...r\Security\Checks\generalHardcodedTmp.py
17
18 from Security.SecurityDefaults import SecurityDefaults
19
20
21 def getChecks():
22 """
23 Public method to get a dictionary with checks handled by this module.
24
25 @return dictionary containing checker lists containing checker function and
26 list of codes
27 @rtype dict
28 """
29 return {
30 "Str": [
31 (checkHardcodedTmpDirectory, ("S108",)),
32 ],
33 }
34
35
36 def checkHardcodedTmpDirectory(reportError, context, config):
37 """
38 Function to check for insecure usage of tmp file/directory.
39
40 @param reportError function to be used to report errors
41 @type func
42 @param context security context object
43 @type SecurityContext
44 @param config dictionary with configuration data
45 @type dict
46 """
47 tmpDirs = (
48 config["hardcoded_tmp_directories"]
49 if config and "hardcoded_tmp_directories" in config else
50 SecurityDefaults["hardcoded_tmp_directories"]
51 )
52
53 if any(context.stringVal.startswith(s) for s in tmpDirs):
54 reportError(
55 context.node.lineno - 1,
56 context.node.col_offset,
57 "S108",
58 "M",
59 "M",
60 )

eric ide

mercurial