T09 · Insecure Skill Coding Practices
- Location
huawei-cloud-cce-list.py:28- Finding
Ambiguous Environment Variable Matching Can Select Unintended Cloud Credentials
- Content
View full analysis
Vulnerability Details
File Location:
huawei-cloud-cce-list.py:28-41
Vulnerability Type: Overbroad credential discovery and ambiguous credential selection
Risk Level: MediumVulnerable Code:
python def _load_credentials() -> Tuple[str, str]: ak, sk = "", "" for k, v in os.environ.items(): u = k.upper() if not (u.startswith("HUAWEI") or u.startswith("HW") or u.startswith("HWC")): continue if "ACCESS_KEY" in u or u.endswith("_AK") or u == "AK": ak = v or ak if "SECRET_KEY" in u or u.endswith("_SK") or u == "SK": sk = v or sk if not ak or not sk: print("Error: AK/SK environment variables were not found.", file=sys.stderr) sys.exit(_EXIT_AUTH_ERR) return ak, skTechnical Analysis
The documented credential variables are
HUAWEICLOUD_SDK_AKandHUAWEICLOUD_SDK_SK, but the implementation enumerates the entire process environment and heuristically accepts any variable whose name begins withHUAWEI,HW, orHWCand contains a matching suffix or substring.If multiple matching variables exist, later entries encountered during environment iteration overwrite earlier values. The access key and secret key are also selected independently, so credentials from different variable pairs can be combined. This violates deterministic credential selection and can result in authentication against an unintended Huawei Cloud account.
The code does not expose credential values in its output, and this issue does not independently grant an attacker new privileges. Exploitation requires influence over the environment of the process.
Attack Path
- An attacker, wrapper script, CI configuration, or neighboring deployment component gains the ability to define environment variables for the Skill process.
- It defines matching variables such as
HWC_OTHER_AKandHWC_OTHER_SK. - The loade ...[truncated 839 chars]
- Remediation
View remediation
Remediation Suggestions
Read only the explicitly documented variables and reject incomplete credential pairs:
python def _load_credentials() -> Tuple[str, str]: ak = os.getenv("HUAWEICLOUD_SDK_AK") sk = os.getenv("HUAWEICLOUD_SDK_SK") if not ak or not sk: print( "Error: set HUAWEICLOUD_SDK_AK and HUAWEICLOUD_SDK_SK.", file=sys.stderr, ) raise SystemExit(_EXIT_AUTH_ERR) return ak, skAdditional hardening should include:
- Do not enumerate the complete environment to discover credentials.
- Do not support undocumented aliases unless each alias is explicitly named and conflicts are rejected.
- Use temporary, least-privileged credentials where supported.
- Add tests with multiple similarly named environment variables to verify deterministic selection.
- Ensure CI and process-launch configurations prevent untrusted users from modifying the Skill's environment.
