T09 · Insecure Skill Coding Practices
- Location
scripts/google_lens.py:219- Finding
API Token Exposure Through Command-Line Arguments and Unnecessary Environment Mutation
- Content
View full analysis
Vulnerability Details
File Location:
scripts/google_lens.py:219,scripts/google_lens.py:442-448
Vulnerability Type: Insecure credential handling
Risk Level: MediumVulnerable Code
python parser.add_argument("--token", help="Dataify API token. Bearer prefix is optional.")python def get_authorization(token_arg: str | None) -> str | None: token = clean_value(token_arg) or clean_value(os.environ.get("DATAIFY_API_TOKEN")) if not token: return None if not token.lower().startswith("bearer "): token = f"Bearer {token}" os.environ["DATAIFY_API_TOKEN"] = token return tokenTechnical Analysis
The script permits a Dataify API token to be supplied through the
--tokencommand-line argument. Command-line secrets can be exposed through shell history, process inspection utilities, terminal or automation logs, telemetry, and error reports.The
get_authorizationfunction also writes the normalized bearer credential back intoos.environ. This assignment is unnecessary because the credential is already available in a local variable and can be passed directly to the HTTP request. The mutation increases the credential's exposure to process diagnostics and any child process that may be added or launched if the script is imported or extended. It also unexpectedly changes the variable from a raw token to aBearer ...value.Sending the credential in the
Authorizationheader to the fixed HTTPS endpoint is necessary for the declared API functionality and is not itself the vulnerability. The issue is the avoidable local exposure created before transmission.Attack Path
- A user or automation system invokes the script with a command such as
python3 scripts/google_lens.py --token SECRET .... - The complete command may be recorded in shell history, execution logs, Agent telemetry, or process metadata.
- A local user or monitoring component ...[truncated 971 chars]
- A user or automation system invokes the script with a command such as
- Remediation
View remediation
Remediation Suggestions
- Remove the
--tokencommand-line option and read the credential only fromDATAIFY_API_TOKENor an approved secret-management facility. - Do not assign the normalized token back to
os.environ. Normalize it in a local variable and return that value directly. - If interactive token entry is required, use
getpass.getpass()so the value is not echoed or placed in shell history. - Ensure application logs, exceptions, telemetry, previews, and HTTP debugging output redact both raw tokens and values prefixed with
Bearer. - Document that credentials must never be passed as command-line arguments or pasted into chat.
- Prefer short-lived, revocable, and least-privileged API tokens where supported.
- A hardened implementation should follow this pattern:
python def get_authorization() -> str | None: token = clean_value(os.environ.get("DATAIFY_API_TOKEN")) if not token: return None if not token.lower().startswith("bearer "): token = f"Bearer {token}" return token- Remove the
