T09 · Insecure Skill Coding Practices
- Location
scripts/search_datasets.py:320- Finding
CNGB API Token Exposed Through Command-Line Arguments
- Content
View full analysis
Vulnerability Details
File Location:
scripts/search_datasets.py, lines 320 and 341
Vulnerability Type: Sensitive credential exposure through process arguments and shell history
Risk Level: MediumVulnerable Code
python parser.add_argument("--cngb-token", help="CNGB API token (optional)")python if not args.skip_cngb: all_results.extend(search_cngb(args, token=args.cngb_token))The credential is subsequently placed in the authorization header:
python headers = {} if token: headers["Authorization"] = f"Bearer {token}" try: req = urllib.request.Request(f"{base}/search/dataset?{params}", headers=headers) with urllib.request.urlopen(req, timeout=15) as resp: data = json.loads(resp.read())Technical Analysis
Accepting an API token as a command-line argument exposes it outside the application's intended credential boundary. Depending on the operating system and environment, command-line arguments may be visible through process-listing and monitoring facilities. The complete invocation may also be retained in interactive shell history, terminal logs, job-runner metadata, or diagnostic records.
The script does not print the token, hardcode it, or send it to an unrelated host. It limits use of the credential to an HTTPS
Authorization: Bearerheader sent to the declared CNGB endpoint. Nevertheless, command-line transport is an insecure secret-input mechanism.Attack Path
- A user invokes the tool with
--cngb-token SECRET. - The shell may persist the complete command in its history, or a local process-monitoring facility may capture the argument while the program runs.
- An attacker with access to that history, process metadata, terminal recording, or job logs obtains the token.
- The attacker submits the recovered bearer token to CNGB.
- The attacker gains whatever CNGB API access is authorized for that token, including possible access to controlled datasets.
This path requires ...[truncated 559 chars]
- A user invokes the tool with
- Remediation
View remediation
Remediation Suggestions
- Remove or deprecate
--cngb-tokenas a direct secret-bearing argument. - Prompt securely using
getpass.getpass()when authenticated CNGB access is requested. - Alternatively, integrate with an operating-system credential store or accept a path to a token file whose permissions are restricted to the current user.
- If automation requires an environment variable, document its exposure limitations and ensure CI systems mask it from logs; a credential store or protected file is preferable.
- Avoid including tokens in examples, diagnostics, exception messages, telemetry, or command logs.
- Clear in-memory references when practical after constructing the authenticated request.
- Rotate any token that has previously been supplied on a command line where shell history or process telemetry may have retained it.
- Remove or deprecate
