T09 · Insecure Skill Coding Practices
- Location
scripts/whoami.py:2- Finding
Spoofable Effective-User Identity Check
- Content
View full analysis
Vulnerability Details
File Location:
scripts/whoami.py, lines 2-3
Vulnerability Type: Reliance on an untrusted environment variable for identity verification
Risk Level: Mediumpython import os print(os.environ.get('USER', 'unknown'))Technical Analysis
The script reports the value of the process-controlled
USERenvironment variable rather than querying the effective operating-system identity. A caller can arbitrarily override this variable, so it is not authoritative evidence of the process's effective username or privileges.This contradicts the documented purpose of returning the “current effective username” for permission and access-control verification. The implementation also ignores command-line arguments, meaning the documented
--full,--uid,--groups,--json, and--check USERbehaviors are not implemented.Attack Path
- An attacker or untrusted caller runs the tool while setting a forged environment value:
bash USER=root scripts/whoami.py - The script reads
USERwithout validating it against the process's effective UID. - The script prints
root, even if the process is running as a non-root user. - A wrapper or automation script that trusts this output for an authorization decision may incorrectly execute a branch intended only for root.
Impact Assessment
An attacker can spoof the identity reported by this utility within any process context where they can control inherited environment variables. This does not itself grant operating-system privileges or change the effective UID. However, consumers that use the output for permission checks, access-control decisions, auditing, or conditional execution may be misled.
The resulting scope depends on the consuming application. If a privileged wrapper treats the reported username as authoritative, the flaw could cause unauthorized privileged operations. No such wrapper is present in the audited project, so direct privilege escalat ...[truncated 45 chars]
- An attacker or untrusted caller runs the tool while setting a forged environment value:
- Remediation
View remediation
Remediation Suggestions
Resolve identity from kernel-backed process credentials rather than environment variables:
python import os import pwd effective_uid = os.geteuid() effective_username = pwd.getpwuid(effective_uid).pw_name print(effective_username)Additionally:
- Implement command-line parsing for every documented option, or remove unsupported options from
SKILL.md. - Implement
--check USERby comparing the requested username against the username derived fromos.geteuid(), with exit status0for a match and1otherwise. - Obtain UID and GID values through
os.geteuid()andos.getegid(). - Resolve group information through trusted OS identity APIs rather than environment values.
- Add tests that run the script with forged values such as
USER=rootand verify that the reported identity still matches the effective UID. - Warn callers not to use display-oriented output as the sole authorization boundary; privileged operations should independently verify effective credentials.
- Implement command-line parsing for every documented option, or remove unsupported options from
