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

chore: Handle all level 1 TiCS security violations #5103

Merged
merged 3 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cloudinit/cmd/devel/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def _stream_command_output_to_file(cmd, filename, msg, verbosity):
ensure_dir(os.path.dirname(filename))
try:
with open(filename, "w") as f:
subprocess.call(cmd, stdout=f, stderr=f)
subprocess.call(cmd, stdout=f, stderr=f) # nosec B603
except OSError as e:
write_file(filename, str(e))
_debug("collecting %s failed.\n" % msg, 1, verbosity)
Expand Down
2 changes: 1 addition & 1 deletion cloudinit/config/cc_power_state_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def doexit(sysexit):
def execmd(exe_args, output=None, data_in=None):
ret = 1
try:
proc = subprocess.Popen(
proc = subprocess.Popen( # nosec B603
exe_args,
stdin=subprocess.PIPE,
stdout=output,
Expand Down
4 changes: 2 additions & 2 deletions cloudinit/sources/DataSourceAzure.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import os.path
import re
import socket
import xml.etree.ElementTree as ET
import xml.etree.ElementTree as ET # nosec B405
from enum import Enum
from pathlib import Path
from time import sleep, time
Expand Down Expand Up @@ -1799,7 +1799,7 @@ def write_files(datadir, files, dirmode=None):
def _redact_password(cnt, fname):
"""Azure provides the UserPassword in plain text. So we redact it"""
try:
root = ET.fromstring(cnt)
root = ET.fromstring(cnt) # nosec B314
for elem in root.iter():
if (
"UserPassword" in elem.tag
Expand Down
4 changes: 2 additions & 2 deletions cloudinit/sources/DataSourceOVF.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import logging
import os
import re
from xml.dom import minidom
from xml.dom import minidom # nosec B408

from cloudinit import safeyaml, sources, subp, util

Expand Down Expand Up @@ -353,7 +353,7 @@ def find_child(node, filter_func):


def get_properties(contents):
dom = minidom.parseString(contents)
dom = minidom.parseString(contents) # nosec B318
if dom.documentElement.localName != "Environment":
raise XmlError("No Environment Node")

Expand Down
2 changes: 1 addition & 1 deletion cloudinit/sources/azure/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from datetime import datetime
from io import StringIO
from typing import Any, Dict, List, Optional, Tuple
from xml.etree import ElementTree
from xml.etree import ElementTree # B405
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this supposed to have a nosec in the comment?


import requests

Expand Down
12 changes: 7 additions & 5 deletions cloudinit/sources/helpers/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from datetime import datetime
from time import sleep, time
from typing import Callable, List, Optional, TypeVar, Union
from xml.etree import ElementTree
from xml.sax.saxutils import escape
from xml.etree import ElementTree # nosec B405
from xml.sax.saxutils import escape # nosec B406

from cloudinit import distros, subp, temp_utils, url_helper, util, version
from cloudinit.reporting import events
Expand Down Expand Up @@ -360,7 +360,7 @@ def __init__(
self.azure_endpoint_client = azure_endpoint_client

try:
self.root = ElementTree.fromstring(unparsed_xml)
self.root = ElementTree.fromstring(unparsed_xml) # nosec B314
except ElementTree.ParseError as e:
report_diagnostic_event(
"Failed to parse GoalState XML: %s" % e,
Expand Down Expand Up @@ -493,7 +493,9 @@ def _decrypt_certs_from_xml(self, certificates_xml):
"""Decrypt the certificates XML document using the our private key;
return the list of certs and private keys contained in the doc.
"""
tag = ElementTree.fromstring(certificates_xml).find(".//Data")
tag = ElementTree.fromstring(certificates_xml).find( # nosec B314
".//Data"
)
certificates_content = tag.text
lines = [
b"MIME-Version: 1.0",
Expand Down Expand Up @@ -1001,7 +1003,7 @@ def parse_text(cls, ovf_env_xml: str) -> "OvfEnvXml":
unparsable or invalid.
"""
try:
root = ElementTree.fromstring(ovf_env_xml)
root = ElementTree.fromstring(ovf_env_xml) # nosec B314
except ElementTree.ParseError as e:
raise errors.ReportableErrorOvfParsingException(exception=e) from e

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def render_tmpl(template, mode=None, is_yaml=False):
cmd_variant = ["--variant", VARIANT]
if PREFIX:
cmd_prefix = ["--prefix", PREFIX]
subprocess.run(
subprocess.run( # nosec B603
[
sys.executable,
"./tools/render-template",
Expand Down
6 changes: 3 additions & 3 deletions setup_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def pkg_config_read(library: str, var: str) -> str:
}
cmd = ["pkg-config", f"--variable={var}", library]
try:
path = subprocess.check_output(cmd).decode("utf-8")
path = subprocess.check_output(cmd).decode("utf-8") # nosec B603
path = path.strip()
except Exception:
path = fallbacks[library][var]
Expand Down Expand Up @@ -53,12 +53,12 @@ def version_to_pep440(version: str) -> str:

def get_version() -> str:
cmd = [sys.executable, "tools/read-version"]
ver = subprocess.check_output(cmd)
ver = subprocess.check_output(cmd) # B603
version = ver.decode("utf-8").strip()
return version_to_pep440(version)


def read_requires() -> List[str]:
cmd = [sys.executable, "tools/read-dependencies"]
deps = subprocess.check_output(cmd)
deps = subprocess.check_output(cmd) # nosec B603
return deps.decode("utf-8").splitlines()
Loading