T09 · Insecure Skill Coding Practices
- Location
scripts/generate_art_name.py:221- Finding
Access Token Exposure Through Command-Line Arguments and Plaintext Configuration Storage
- Content
View full analysis
Vulnerability Details
File Location:
scripts/generate_art_name.py:93-99,scripts/generate_art_name.py:221-227, andscripts/generate_art_name.py:262-266
Vulnerability Type: Insecure credential handling
Risk Level: MediumVulnerable Code
python def save_config(cfg: dict): """保存配置到文件""" CONFIG_FILE.parent.mkdir(parents=True, exist_ok=True) with open(CONFIG_FILE, "w", encoding="utf-8") as f: json.dump(cfg, f, ensure_ascii=False, indent=2) print(f"✅ 配置已保存到 {CONFIG_FILE}")python parser.add_argument("--token", "-t", type=str, default="", help="星河社区 Access Token(优先于配置文件)") parser.add_argument("--model", "-m", type=str, default="", choices=["ERNIE-Image", "ERNIE-Image-Turbo", "Stable-Diffusion-XL"], help="使用的模型,默认:ERNIE-Image-Turbo") parser.add_argument("--set-token", type=str, metavar="TOKEN", help="将 Access Token 保存到配置文件")python if args.set_token: config["access_token"] = args.set_token save_config(config) print(f"✅ Access Token 已保存!前8位:{args.set_token[:8]}****") returnThe insecure command-line usage is also explicitly recommended in
SKILL.md:30-36,README.md:20, andreferences/api_docs.md:120-122:bash python3 scripts/generate_art_name.py --set-token YOUR_TOKENTechnical Analysis
The Skill accepts access tokens through the
--tokenand--set-tokencommand-line arguments. Secrets supplied as command-line arguments can be exposed through shell history, process inspection utilities, terminal logs, automation logs, or monitoring systems that record executed commands.The
--set-tokenoperation then stores the long-lived token as plaintext JSON inconfig.json. The file is created using the process's default umask, without explicitly enforcing owner-only permissions. Depending on the host configuration, othe ...[truncated 2255 chars]- Remediation
View remediation
Remediation Suggestions
- Remove token-bearing command-line options, especially
--set-token, because command arguments are not an appropriate secret-entry channel. - Accept tokens through the
AISTUDIO_ACCESS_TOKENenvironment variable or prompt interactively with Python'sgetpass.getpass()so the token is not echoed or placed in shell history. - Prefer an operating-system credential store, such as Keychain, Secret Service, or Credential Manager, for persistent storage.
- If file-based persistence must remain available:
- Obtain explicit user consent before storing the token.
- Create the file atomically with owner-only mode
0600. - Verify and correct permissions when reading an existing configuration.
- Refuse to use a configuration file owned by another user or writable by untrusted users.
- Add
config.jsonto.gitignoreand document that it must never be committed, shared, or included in support bundles. - Stop printing the token prefix after storage.
- Update
README.md,SKILL.md, andreferences/api_docs.mdto recommend secure interactive or environment-based credential handling instead of command-line token arguments. - Advise users who previously used the documented command to remove affected shell-history entries, secure or delete plaintext configuration files, and rotate potentially exposed tokens.
- Remove token-bearing command-line options, especially
