From f326d58068c7914ee1af6dbad4a7f67be9d67155 Mon Sep 17 00:00:00 2001 From: Joe Testa Date: Sun, 28 Jan 2024 18:17:49 -0500 Subject: [PATCH] Disable color when the NO_COLOR environment variable is set. (#234) --- README.md | 1 + src/ssh_audit/ssh_audit.py | 8 +++++++- ssh-audit.1 | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 97f21c0..971d91d 100644 --- a/README.md +++ b/README.md @@ -180,6 +180,7 @@ For convenience, a web front-end on top of the command-line tool is available at ### v3.2.0-dev (???) - Expanded filter of CBC ciphers to flag for the Terrapin vulnerability. It now includes more rarely found ciphers. + - Color output is disabled if the `NO_COLOR` environment variable is set (see https://no-color.org/). ### v3.1.0 (2023-12-20) - Added test for the Terrapin message prefix truncation vulnerability ([CVE-2023-48795](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2023-48795)). diff --git a/src/ssh_audit/ssh_audit.py b/src/ssh_audit/ssh_audit.py index 457ecdf..6c6daee 100755 --- a/src/ssh_audit/ssh_audit.py +++ b/src/ssh_audit/ssh_audit.py @@ -106,7 +106,8 @@ def usage(uout: OutputBuffer, err: Optional[str] = None) -> None: uout.info(' --lookup= looks up an algorithm(s) without\n connecting to a server') uout.info(' -M, --make-policy= creates a policy based on the target server\n (i.e.: the target server has the ideal\n configuration that other servers should\n adhere to)') uout.info(' -m, --manual print the man page (Windows only)') - uout.info(' -n, --no-colors disable colors') + uout.info(' -n, --no-colors disable colors (automatic when the NO_COLOR') + uout.info(' environment variable is set)') uout.info(' -p, --port= port to connect') uout.info(' -P, --policy= run a policy test using the specified policy') uout.info(' -t, --timeout= timeout (in seconds) for connection and reading\n (default: 5)') @@ -858,6 +859,11 @@ def process_commandline(out: OutputBuffer, args: List[str], usage_cb: Callable[. aconf = AuditConf() enable_colors = not any(i in args for i in ['--no-colors', '-n']) + + # Disable colors if the NO_COLOR environment variable is set. + if "NO_COLOR" in os.environ: + enable_colors = False + aconf.colors = enable_colors out.use_colors = enable_colors diff --git a/ssh-audit.1 b/ssh-audit.1 index df9a26d..8617d49 100644 --- a/ssh-audit.1 +++ b/ssh-audit.1 @@ -1,4 +1,4 @@ -.TH SSH-AUDIT 1 "March 13, 2022" +.TH SSH-AUDIT 1 "January 28, 2024" .SH NAME \fBssh-audit\fP \- SSH server & client configuration auditor .SH SYNOPSIS @@ -114,7 +114,7 @@ Creates a policy based on the target server. Useful when other servers should b .TP .B -n, \-\-no-colors .br -Disable color output. +Disable color output. Automatically set when the NO_COLOR environment variable is set. .TP .B -p, \-\-port=