tylerwince / flake8-bandit

Automated security testing using bandit and flake8.
MIT License
111 stars 23 forks source link

S601 for sanitized command #42

Open dmcnulla opened 1 year ago

dmcnulla commented 1 year ago

I'm getting flagged for S601 on the following code even though I've added sanitization of the command.

from paramiko import SSHClient
from shlex import join as shlex.join
...
class RemoteConnectionClass:
    ...

    def _create_ssh_client_conn(self, dbs_name: str, ssh_client=SSHClient) -> SSHClient:
        """Create, connect, and return ssh client."""
        ssh_client = ssh_client()
        ...
        return ssh_client

    def run_cmd(self, cmd: list[str], target_node: str, output_as_list=False,
                 std_out_timeout=DEFAULT_TIMEOUT) -> (str or [str], int):
        ssh_client = self._create_ssh_client_conn(target_node)

        # S601 is flagged for the following line
        std_in, std_out, std_err = ssh_client.exec_command(shlex_join(cmd))

        std_out.channel.settimeout(std_out_timeout)
        exit_code = std_out.channel.recv_exit_status()
        output = std_out.readlines() if output_as_list else std_out.read().decode()
        return output, exit_code

python 3.10.0 on macos Ventura 13.0.1 paramiko 2.9.5

Is there a recognized sanitization, or do I have to comment it with # noqa: S601 because it is already santized ?

Thanks,

Dave