Back to skill

Security audit

Python包鸿蒙兼容性测试技能

Security checks for vulnerabilities and agentic risk

Overview

This compatibility checker has a legitimate purpose, but it can download and run third-party package code with broad local access and several unsafe implementation choices.

Install or run this only in a disposable, low-privilege container or VM with no secrets in the environment, no sensitive host directories mounted, and constrained network access. Do not run its suggested sudo pip commands for arbitrary packages, and treat generated compatibility reports as advisory rather than authoritative.

Vulnerability Patterns
  • Skill Instruction HijackingAlters the agent's session goals or safety constraints when the skill loads
  • Agent Memory PoisoningWrites attacker-controlled rules into memory that affect later sessions
  • Remote Payload Retrieval and ExecutionFetches external code whose behavior can change after review
  • Embedded Malicious CodeShips malicious scripts inside the skill and executes them locally
  • Unauthorized Access and Privilege EscalationObtains permissions beyond the task's legitimate needs
Findings (7)

<![CDATA[T03

Error
Location
scripts/check_compatibility.py:388
Finding

<![CDATA[Untrusted remote package code is installed and executed without isolation]]>

Content
View full analysis
Tuple[bool, str, str]: """Run a shell command and return success status, stdout, stderr.""" try: result = subprocess.run( cmd, capture_output=True, text=True, timeout=timeout, cwd=cwd, env={**os.environ, "PIP_NO_CACHE_DIR": "1"} ) ``` ```python # Create temporary virtual environment pip_cmd = [sys.executable, "-m", "pip", "install", "--target", venv_path, package_name] success, stdout, stderr = run_command(pip_cmd, timeout=300) ``` ```python # Run pytest with verbose output and result reporting # Use --import-mode=importlib to avoid importing from source directory success, stdout, stderr = run_command( [sys.executable, "-m", "pytest", str(test_file), "-v", "--tb=short", "--import-mode=importlib"], timeout=120, # 2 minutes per test file cwd="/tmp" # Run from /tmp to avoid importing from source ) ``` ### Technical Analysis The checker installs user-selected packages and executes tests obtained from downloaded package source. Both operations can execute arbitrary third-party code: - `pip install` may invoke PEP 517 build backends, build-system dependencies, native compilers, or legacy setup hooks. - Pytest imports test modules and package modules during collection and execution. - `--target` changes the installation destination but does not create a security boundary. - Running from `/tmp` and using `--import-mode=importlib` do not restrict filesystem, process, or network access. - `run_command` copies the complete host environment through `env={**o ...[truncated 1821 chars]
Remediation
View remediation

<![CDATA[T09

Error
Location
scripts/check_compatibility.py:240
Finding

<![CDATA[TLS certificate verification is disabled for GitHub and PyPI downloads]]>

Content
View full analysis
Remediation
View remediation

<![CDATA[T09

Error
Location
scripts/check_compatibility.py:340
Finding

<![CDATA[Downloaded source archives are extracted without safe path and link validation]]>

Content
View full analysis
Remediation
View remediation

<![CDATA[T09

Error
Location
scripts/check_compatibility.py:966
Finding

<![CDATA[Unvalidated package names are embedded into executable Python source]]>

Content
View full analysis
=')[0].split('<=')[0].split('[')[0] packages.append(pkg_name.strip()) ``` ### Technical Analysis The absence of `shell=True` does not prevent this vulnerability. The attacker-controlled value is embedded in Python source passed to `python -c`, so Python itself interprets injected syntax. In the metadata operation, a crafted value can terminate the quoted string and append Python statements. In the import operation, replacing hyphens with underscores does not constrain the value to a valid identifier and does not remove semicolons, parentheses, quotes, whitespace, or other Python syntax. No strict Python distribution-name validation occurs before these commands are constructed. ### Attack Path 1. An attacker supplies a crafted package argument or places it in a requirements file consumed by the Skill. 2. The checker eventually calls `check_already_installed`. 3. The package value is inserted into a formatted Python program. 4. `python -c` parses the attacker-controlled syntax. 5. The injected code executes as the user running the Skill. ### Impact Assessment Successful exploitation provides arbitrary Python code ...[truncated 287 chars]
Remediation
View remediation

<![CDATA[T08

Error
Location
scripts/check_compatibility.py:199
Finding

<![CDATA[Guessed GitHub repositories and moving branches are treated as package source]]>

Content
View full analysis
Remediation
View remediation

<![CDATA[T05

Error
Location
references/python-env-setup.md:72
Finding

<![CDATA[Setup documentation recommends installing untrusted packages with root privileges]]>

Content
View full analysis
# Or install to user directory python3 -m pip install --user # Or use --target python3 -m pip install --target ./local_packages ``` ``` ### Technical Analysis Python package installation may execute build backends, setup hooks, compilers, and dependency code. Running pip through `sudo` grants all such code root privileges. A permission error should not be resolved by broadening package installation privileges, particularly in a Skill whose purpose involves evaluating potentially incompatible or unknown packages. The recommendation conflicts with least-privilege principles and with the same document's safer virtual-environment guidance. ### Attack Path 1. A user encounters a permission error and follows the documented `sudo` workaround. 2. The user installs a malicious or compromised package. 3. The package's build backend or setup hook executes during installation as root. 4. The payload modifies system files, installs persistent components, accesses protected data, or changes security configuration. ### Impact Assessment Successful exploitation grants root-level code execution and system-wide impact. An attacker may read protected files, alter system binaries or configuration, compromise other users, and establish persistence. ]]>
Remediation
View remediation

<![CDATA[T09

Warning
Location
references/python-env-setup.md:153
Finding

<![CDATA[Setup documentation recommends bypassing pip host verification]]>

Content
View full analysis
``` ``` ### Technical Analysis The `--trusted-host` option weakens pip's normal transport-security enforcement for the designated host. It treats the host as trusted rather than solving the underlying certificate-validation failure. Package installation is a code-execution operation, so weakening source authentication creates a direct supply-chain risk. ### Attack Path 1. A user encounters a certificate error. 2. The user follows the documented `--trusted-host` workaround. 3. An attacker intercepts or redirects package traffic under conditions where normal verification would have blocked the connection. 4. The attacker substitutes a malicious distribution. 5. Pip installs the distribution and executes its build backend or setup code. ### Impact Assessment A successful attack provides arbitrary code execution with the privileges of the user running pip. If combined with the separate `sudo` recommendation, the impact can increase to root-level system compromise. ]]>
Remediation
View remediation
Vulnerability Patterns
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
  • Excessive AgencyUnrestricted Tool Access, Autonomous Decision Making, Scope Creep
  • Rogue AgentSelf-Modification, Session Persistence
Findings (19)

Missing User Warnings

High
Category
Not specified by scanner
Confidence
99% confidence
Finding

TLS certificate verification is explicitly disabled for GitHub and PyPI downloads, allowing a man-in-the-middle attacker to tamper with package metadata and source archives. Because the skill later installs and executes downloaded code, this turns transport-layer tampering into arbitrary code execution with very high risk.

Content

No source excerpt is available for this finding.

Env Variable Harvesting

High
Category
Data Exfiltration
Confidence
98% confidence
Finding

The code explicitly copies the full process environment into subprocesses that later execute untrusted package installers and tests. That enables environment harvesting of secrets such as API keys, CI tokens, credentials, and internal configuration, which can then be exfiltrated by malicious package code.

Content

Scanner excerpt · scripts/check_compatibility.py (reported line 394)May include surrounding context.

python
text=True,
            timeout=timeout,
            cwd=cwd,
            env={**os.environ, "PIP_NO_CACHE_DIR": "1"}
        )
        return result.returncode == 0, result.stdout, result.stderr
    except subprocess.TimeoutExpired:

Context-Inappropriate Capability

High
Category
Not specified by scanner
Confidence
99% confidence
Finding

Installing arbitrary user-specified packages with pip can execute setup.py, PEP 517 build hooks, dependency resolution logic, and other installer-controlled code from remote sources. In this skill, the package name is user-controlled and the install occurs as part of normal operation, so an attacker can supply a malicious package to gain code execution.

Content

No source excerpt is available for this finding.

Missing User Warnings

High
Category
Not specified by scanner
Confidence
98% confidence
Finding

The skill performs high-risk behavior—installing arbitrary remote packages and running their code—without clear safety disclosure or user confirmation. In a skill/agent context, that increases the chance the behavior will be invoked in a more trusted environment than intended, leading to unexpected code execution.

Content

No source excerpt is available for this finding.

Context-Inappropriate Capability

High
Category
Not specified by scanner
Confidence
99% confidence
Finding

The skill downloads third-party source code and executes its tests via pytest, with a fallback to running Python files directly. Test suites and Python files are arbitrary code supplied by external package authors, so this creates direct remote code execution on the host running the checker.

Content

No source excerpt is available for this finding.

Undeclared Tool Scope

Medium
Category
MCP Least Privilege
Confidence
96% confidence
Finding

The skill advertises and documents capabilities that imply network access, shell execution, and file read/write, yet it declares no explicit tool scope or permission boundary. In this context, the skill downloads third-party code and runs tests, so the absence of declared restrictions increases the risk of overbroad execution, unintended tool access, and unsafe use in environments that rely on manifest-level scoping.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
98% confidence
Finding

The skill downloads source code from GitHub/PyPI and runs package tests, which means it may execute untrusted third-party code with the agent's privileges. Omitting an explicit warning is dangerous because users may treat the skill as a passive compatibility checker when it actually performs high-risk code execution that can trigger arbitrary commands, data access, network exfiltration, or local system modification through malicious test suites or build steps.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
94% confidence
Finding

This markdown file presents all user-facing content in a single language and does not indicate that the user can choose another language or that the report is intentionally limited to a Chinese-speaking audience. Under the stated policy, forcing a specific language without user opt-in is a natural-language policy violation.

Content

No source excerpt is available for this finding.

Intent-Code Divergence

Medium
Category
Not specified by scanner
Confidence
97% confidence
Finding

The report asserts that numpy is fully compatible with HarmonyOS even though it documents a failed source download and 5 failed test cases. In a compatibility-checking skill, this creates a misleading assurance signal that can cause users or downstream automation to approve unsupported packages, hide real portability defects, and make deployment decisions on inaccurate results.

Content

No source excerpt is available for this finding.

Session Persistence

Medium
Category
Rogue Agent
Confidence
60% confidence
Finding

Skill establishes unauthorized persistence across sessions via cron jobs, startup scripts, or state files. Session persistence allows an attacker to maintain access beyond the current interaction.

Content

Scanner excerpt · references/python-env-setup.md (reported line 26)May include surrounding context.

Always use virtual environments to avoid conflicts:

bash
# Create virtual environment
python3 -m venv venv

# Activate (if supported)

Sudo/Root Execution

Medium
Category
Privilege Escalation
Confidence
97% confidence
Finding

This line explicitly instructs users to run pip with sudo, which elevates package installation to root. Because Python package installs may run arbitrary code during build/install, this creates a realistic path to privilege misuse or system compromise if the package or dependency chain is malicious.

Content

Scanner excerpt · references/python-env-setup.md (reported line 74)May include surrounding context.

HarmonyOS may restrict execution:

bash
# Try with sudo (user can provide password)
sudo python3 -m pip install <package>

# Or install to user directory

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
96% confidence
Finding

The document recommends using sudo python3 -m pip install <package> to resolve permission issues, but it does not warn that this performs a system-wide package installation with elevated privileges. Installing arbitrary packages as root can execute untrusted setup/build scripts with full system privileges and can also corrupt the system Python environment.

Content

No source excerpt is available for this finding.

Sudo/Root Execution

Medium
Category
Privilege Escalation
Confidence
70% confidence
Finding

Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.

Content

Scanner excerpt · references/python-env-setup.md (reported line 75)May include surrounding context.

bash
# Try with sudo (user can provide password)
sudo python3 -m pip install <package>

# Or install to user directory
python3 -m pip install --user <package>

subprocess module call

Medium
Category
Dangerous Code Execution
Confidence
89% confidence
Finding

The helper centralizes execution of external commands and is later used to run pip, pytest, and direct Python execution on untrusted package content. While subprocess.run is not using shell=True, it still executes attacker-controlled code paths because package names and downloaded test files ultimately determine what gets run.

Content

Scanner excerpt · scripts/check_compatibility.py (reported line 388)May include surrounding context.

python
def run_command(cmd: List[str], timeout: int = 300, cwd: str = None) -> Tuple[bool, str, str]:
    """Run a shell command and return success status, stdout, stderr."""
    try:
        result = subprocess.run(
            cmd,
            capture_output=True,
            text=True,

Context-Inappropriate Capability

Medium
Category
Not specified by scanner
Confidence
97% confidence
Finding

The subprocess helper passes the full host environment to commands that include pip and pytest operating on untrusted packages. Malicious build scripts or tests can read tokens, credentials, proxy settings, and other secrets from inherited environment variables and exfiltrate them.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
97% confidence
Finding

Multiple hard-coded report headings and content strings are emitted in Chinese, which imposes a specific language on users. There is no opt-in, locale selection, or documented justification showing that the tool is intentionally region-specific.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
85% confidence
Finding

This code creates output files on disk as a side effect of running the checker. While file writing is part of reporting behavior, the user-facing usage text and argument help shown earlier do not make this automatic file creation clear.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
87% confidence
Finding

The documentation states that timestamps use East China / Beijing time (UTC+8) as a fixed behavior. This imposes a locale-specific convention without offering user choice or explaining why that locale is required for the skill's function.

Content

No source excerpt is available for this finding.

Intent-Code Divergence

Low
Category
Not specified by scanner
Confidence
87% confidence
Finding

The docstring says the function checks installability in a 'clean virtual environment', but the implementation does not create or activate a virtual environment. It runs pip install --target against an arbitrary directory using the current interpreter, which is materially different from the documented isolation model.

Content

No source excerpt is available for this finding.

Static analysis

No suspicious patterns detected.