Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run bandit checks and add appropriate exclusions #67

Closed
holmboe opened this issue Dec 13, 2023 · 3 comments
Closed

Run bandit checks and add appropriate exclusions #67

holmboe opened this issue Dec 13, 2023 · 3 comments

Comments

@holmboe
Copy link
Contributor

holmboe commented Dec 13, 2023

Run bandit checks and add appropriate exclusions to the source code.

@Grokzen Grokzen removed their assignment Dec 13, 2023
@Grokzen Grokzen closed this as completed in 1f43340 Jan 4, 2024
@Grokzen
Copy link
Collaborator

Grokzen commented Jan 4, 2024

(bandit) ➜  subgit git:(master) ✗   bandit subgit/ -r
[main]  INFO    profile include tests: None
[main]  INFO    profile exclude tests: None
[main]  INFO    cli include tests: None
[main]  INFO    cli exclude tests: None
[main]  INFO    running on Python 3.10.12
Run started:2024-01-04 21:49:26.530119

Test results:
        No issues identified.

Code scanned:
        Total lines of code: 1162
        Total lines skipped (#nosec): 8

Run metrics:
        Total issues (by severity):
                Undefined: 0
                Low: 0
                Medium: 0
                High: 0
        Total issues (by confidence):
                Undefined: 0
                Low: 0
                Medium: 0
                High: 0
Files skipped (0):

@holmboe
Copy link
Contributor Author

holmboe commented Jan 8, 2024

@Grokzen could you go a little bit further on this to add more context? Add a comment in the ticket on what the Bandit result was before the exclusions were added.

Perhaps even use the more explicit #nosec Xnnn in the code? See https://bandit.readthedocs.io/en/latest/config.html#exclusions for examples.

@Grokzen
Copy link
Collaborator

Grokzen commented Jan 11, 2024

This is the bandit log before the exclusions was added in

Run started:2024-01-11 10:04:16.004581

Test results:
>> Issue: [B404:blacklist] Consider possible security implications associated with the subprocess module.
   Severity: Low   Confidence: High
   CWE: CWE-78 (https://cwe.mitre.org/data/definitions/78.html)
   More Info: https://bandit.readthedocs.io/en/1.7.6/blacklists/blacklist_imports.html#b404-import-subprocess
   Location: subgit/core.py:11:0
10	from pathlib import Path
11	from subprocess import PIPE, Popen
12	

--------------------------------------------------
>> Issue: [B602:subprocess_popen_with_shell_equals_true] subprocess call with shell=True identified, security issue.
   Severity: High   Confidence: High
   CWE: CWE-78 (https://cwe.mitre.org/data/definitions/78.html)
   More Info: https://bandit.readthedocs.io/en/1.7.6/plugins/b602_subprocess_popen_with_shell_equals_true.html
   Location: subgit/core.py:34:14
33	        stderr=None,
34	        shell=True,
35	    )
36	    output, stderr = process.communicate()
37	
38	    return output, stderr
39	
40	

--------------------------------------------------
>> Issue: [B404:blacklist] Consider possible security implications associated with the subprocess module.
   Severity: Low   Confidence: High
   CWE: CWE-78 (https://cwe.mitre.org/data/definitions/78.html)
   More Info: https://bandit.readthedocs.io/en/1.7.6/blacklists/blacklist_imports.html#b404-import-subprocess
   Location: subgit/inspect/git_inspect.py:6:0
5	import logging
6	import subprocess
7	

--------------------------------------------------
>> Issue: [B603:subprocess_without_shell_equals_true] subprocess call - check for execution of untrusted input.
   Severity: Low   Confidence: High
   CWE: CWE-78 (https://cwe.mitre.org/data/definitions/78.html)
   More Info: https://bandit.readthedocs.io/en/1.7.6/plugins/b603_subprocess_without_shell_equals_true.html
   Location: subgit/inspect/git_inspect.py:37:12
36	                ],
37	                shell=False,
38	                capture_output=True,
39	            )
40	        except FileNotFoundError:
41	            return False
42	
43	        return True
44	

--------------------------------------------------
>> Issue: [B607:start_process_with_partial_path] Starting a process with a partial executable path
   Severity: Low   Confidence: High
   CWE: CWE-78 (https://cwe.mitre.org/data/definitions/78.html)
   More Info: https://bandit.readthedocs.io/en/1.7.6/plugins/b607_start_process_with_partial_path.html
   Location: subgit/inspect/git_inspect.py:54:14
53	
54	        out = subprocess.run([
55	                "gh", "repo", "list",
56	                f"{owner}",
57	                "--json", "id,name,defaultBranchRef,sshUrl,isArchived",
58	                "-L", "100"
59	            ],
60	            shell=False,
61	            capture_output=True,
62	        )
63	        data = json.loads(out.stdout)

--------------------------------------------------
>> Issue: [B603:subprocess_without_shell_equals_true] subprocess call - check for execution of untrusted input.
   Severity: Low   Confidence: High
   CWE: CWE-78 (https://cwe.mitre.org/data/definitions/78.html)
   More Info: https://bandit.readthedocs.io/en/1.7.6/plugins/b603_subprocess_without_shell_equals_true.html
   Location: subgit/inspect/git_inspect.py:60:14
59	            ],
60	            shell=False,
61	            capture_output=True,
62	        )
63	        data = json.loads(out.stdout)
64	        repos = {}
65	        mapped_data = {
66	            repo["name"].lower():
67	            repo for repo in data
68	            if repo["isArchived"] == self.is_archived
69	        }

--------------------------------------------------
>> Issue: [B607:start_process_with_partial_path] Starting a process with a partial executable path
   Severity: Low   Confidence: High
   CWE: CWE-78 (https://cwe.mitre.org/data/definitions/78.html)
   More Info: https://bandit.readthedocs.io/en/1.7.6/plugins/b607_start_process_with_partial_path.html
   Location: subgit/inspect/git_inspect.py:111:14
110	
111	        out = subprocess.run(
112	            [
113	                "gitlab",
114	                "-o", "json",
115	                "project", "list",
116	                "--membership", "yes",
117	                "--all",
118	            ],
119	            shell=False,
120	            capture_output=True,
121	        )
122	        repos = {}

--------------------------------------------------
>> Issue: [B603:subprocess_without_shell_equals_true] subprocess call - check for execution of untrusted input.
   Severity: Low   Confidence: High
   CWE: CWE-78 (https://cwe.mitre.org/data/definitions/78.html)
   More Info: https://bandit.readthedocs.io/en/1.7.6/plugins/b603_subprocess_without_shell_equals_true.html
   Location: subgit/inspect/git_inspect.py:119:14
118	            ],
119	            shell=False,
120	            capture_output=True,
121	        )
122	        repos = {}
123	        data = json.loads(out.stdout)
124	        mapped_data = {
125	            repo["name"].lower():
126	            repo for repo in data
127	            if repo["namespace"]["name"] == owner and repo["archived"] == self.is_archived
128	        }
129	        sorted_names = sorted([
130	            repo["name"].lower()

--------------------------------------------------

Code scanned:
	Total lines of code: 1162
	Total lines skipped (#nosec): 0
	Total potential issues skipped due to specifically being disabled (e.g., #nosec BXXX): 0

Run metrics:
	Total issues (by severity):
		Undefined: 0
		Low: 7
		Medium: 0
		High: 1
	Total issues (by confidence):
		Undefined: 0
		Low: 0
		Medium: 0
		High: 8
Files skipped (0):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants