T09 · Insecure Skill Coding Practices
- Location
scripts/query.py:68- Finding
API Key Exposed Through Command-Line Arguments
- Content
View full analysis
Vulnerability Details
File Location:
scripts/query.py:68-75
Secondary Locations:SKILL.md:27-28,SKILL.md:124-125
Vulnerability Type: Command-line secret exposure
Risk Level: MediumVulnerable Code
python def main(): parser = argparse.ArgumentParser(description="企业信息查询") parser.add_argument("--keyword", required=True, help="企业名称关键词(必填)") parser.add_argument("--category", help="企业分类(可选)") parser.add_argument("--API_KEY", required=True, help="API密钥(必填)") args = parser.parse_args()The documented invocation explicitly places the credential in the command line:
text python scripts/query.py --keyword "南京水利公司" --category "01" --API_KEY "ABC123"Technical Analysis
The script requires the service API key to be supplied through the
--API_KEYcommand-line argument. Command-line arguments are not an appropriate secret-delivery mechanism because they may be:- Recorded in interactive shell history.
- Captured by process monitoring, audit, observability, or endpoint-management systems.
- Visible through process inspection facilities to users with sufficient local permissions.
- Retained in automation logs, job metadata, terminal transcripts, or support diagnostics.
The key is subsequently included in the JSON body of an HTTPS request to the fixed endpoint
https://rcd-test.dfwycredit.com/s1/skill/enterprise. Transmission to that service is declared and necessary for authentication, and HTTPS protects the request in transit under normal certificate-validation assumptions. The confirmed weakness is therefore the local handling of the credential through process arguments, not the declared network transmission itself.Attack Path
- A consumer follows the documented example and invokes the script with a real API key in
--API_KEY. - The full command is retained in shell history, automation output, process telemetry, or another local com ...[truncated 1087 chars]
- Remediation
View remediation
Remediation Suggestions
-
Remove the
--API_KEYcommand-line argument and obtain the credential from a protected secret source, such as:- A secret manager supplied by the execution platform.
- A restricted-permission configuration or credential file.
- A dedicated environment variable where platform constraints require it.
- Standard input through a non-echoing prompt for interactive use.
-
For environment-based configuration, fail safely when the variable is absent:
python API_KEY = os.environ.get("RCD_API_KEY") if not API_KEY: parser.error("RCD_API_KEY is not configured") -
Update
SKILL.mdto remove every command example containing an API key. Document secure configuration separately, for example:text RCD_API_KEY is supplied through the platform's secret configuration. python scripts/query.py --keyword "Example Company" --category "01" -
Ensure the key is never included in logs, exceptions, telemetry, debug output, or returned JSON. Apply explicit redaction if request parameters are logged by surrounding infrastructure.
-
Restrict each API key to the minimum required operations, enforce rate limits, monitor anomalous use, and provide straightforward revocation and rotation procedures.
-
Treat keys previously used through the documented command-line interface as potentially exposed and rotate them where shell history, process telemetry, or automation logs may have retained the command.
-
