Back to skill

Security audit

Baidu Ocr

Security checks for vulnerabilities and agentic risk

Overview

This OCR skill mostly does what it claims, but it ships and uses hardcoded Baidu credentials while also under-disclosing that image contents are sent to Baidu.

Review before installing. Do not use the bundled credentials, and treat the exposed Baidu key and secret as compromised. The publisher should rotate them, remove them from the package, load credentials only from secure user configuration, and add a clear notice that submitted images are uploaded to Baidu for OCR processing.

Vulnerability Patterns
  • Insecure Skill Coding PracticesFinds exploitable flaws such as hardcoded secrets or command injection
  • 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
Findings (1)

T09 · Insecure Skill Coding Practices

Error
Location
baidu_ocr.py:18
Finding
Hardcoded Baidu API Credentials Exposed in Distributed Source Code## Vulnerability Details **File Location**: `baidu_ocr.py:18-31` **Additional Exposure**: `ACTIVATE_GUIDE.md:5` exposes the same API key and states that it is valid. **Vulnerability Type**: Hardcoded cloud service credentials **Risk Level**: High ### Vulnerable Code ```python # 百度 OCR 配置 API_KEY = "4LceeJ8wBDSqa3SqDHmgXuk1" SECRET_KEY = "nIulIWxqaUtY5XyfexSvP4OL8ZBk0krR" # 获取 access_token def get_access_token(): """获取百度 API 的 access_token""" url = "https://aip.baidubce.com/oauth/2.0/token" params = { "grant_type": "client_credentials", "client_id": API_KEY, "client_secret": SECRET_KEY } ``` ### Technical Analysis The source code embeds a live-looking Baidu API key and secret key directly in the distributed Python file. The credentials are supplied to Baidu's OAuth client-credentials endpoint to obtain an access token. This contradicts the environment-based configuration declared by the Skill: - `SKILL.md` declares `BAIDU_API_KEY` and `BAIDU_SECRET_KEY` as required environment variables. - `metadata.json` also declares those environment variables. - The implementation never reads them and instead always uses the embedded credentials. Secrets stored in source code cannot be protected through normal runtime access controls. Anyone who can download, inspect, fork, cache, or otherwise access the Skill package can recover and reuse both values. Removing the credentials from a later release would not invalidate copies already distributed. The image upload itself is necessary for the declared cloud OCR functionality: the selected image is Base64-encoded and transmitted over HTTPS to the documented Baidu OCR service. Base64 is transport encoding rather than encryption, but no covert destination or unrelated data collection was identified. The confirmed vulnerability is the credential exposure, not the expected OCR upload. ### Attack Path ...[truncated 1524 chars]
Remediation
## Remediation Suggestions 1. **Immediately revoke and rotate the exposed credentials** - Treat both embedded values as compromised. - Revoke or regenerate the API key and secret through the Baidu AI console. - Review recent API usage, billing activity, enabled services, and authentication logs for unauthorized activity. 2. **Remove all credential values from the project** - Delete the constants from `baidu_ocr.py`. - Remove the API key from `ACTIVATE_GUIDE.md`. - Purge secrets from repository history and previously published artifacts where possible. 3. **Use the declared environment variables** ```python import os API_KEY = os.environ.get("BAIDU_API_KEY") SECRET_KEY = os.environ.get("BAIDU_SECRET_KEY") if not API_KEY or not SECRET_KEY: raise RuntimeError( "BAIDU_API_KEY and BAIDU_SECRET_KEY must be configured" ) ``` The program should fail closed when either variable is absent and must not fall back to bundled credentials. 4. **Protect credentials during operation** - Never print API keys, secret keys, or access tokens. - Restrict access to environment/configuration files containing credentials. - Where supported by the provider, avoid placing access tokens in URLs because query strings may be retained in logs; use an authorization header instead. 5. **Reduce cloud privileges** - Create a dedicated application credential for this Skill. - Enable only the OCR operations actually required. - Apply provider-side quotas, billing alerts, and usage monitoring. - Do not reuse the credential for unrelated Baidu AI services. 6. **Add secret-detection controls** - Run secret scanning in pre-commit hooks and CI. - Block publication when API credentials or token-like values are detected. - Document credential rotation and incident-response procedures.
Vulnerability Patterns
  • 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
  • Trigger AbuseOverly Broad Trigger, Shadow Command Trigger, Keyword Baiting Trigger
  • MCP Least PrivilegeUnderdeclared Capability, Wildcard Permission, Missing Permission Declaration
Findings (18)

Tp4

High
Category
MCP Tool Poisoning
Confidence
97% confidence
Finding
The documented behavior does not fully match the actual capability profile: the skill claims support for formula and table OCR that are apparently not exposed, and it omits declaring network/file-access behavior. Mismatches like this are dangerous because they undermine user consent and review accuracy, especially when local files are sent to external APIs.

Credential Access

High
Category
Privilege Escalation
Content
| 错误码 | 说明 | 解决方法 |
|--------|------|----------|
| 110 | Access Token 无效 | 重新获取 Token |
| 111 | Access Token 过期 | 重新获取 Token |
| 216100 | 认证失败 | 检查 API Key |
| 216101 | 授权失败 | 检查 Secret Key |
Confidence
70% confidence
Finding
Code accesses credential files (SSH keys, AWS credentials, etc.). This could indicate credential theft attempts.

Credential Access

High
Category
Privilege Escalation
Content
| 错误码 | 说明 | 解决方法 |
|--------|------|----------|
| 110 | Access Token 无效 | 重新获取 Token |
| 111 | Access Token 过期 | 重新获取 Token |
| 216100 | 认证失败 | 检查 API Key |
| 216101 | 授权失败 | 检查 Secret Key |
Confidence
70% confidence
Finding
Code accesses credential files (SSH keys, AWS credentials, etc.). This could indicate credential theft attempts.

Ae4

Medium
Category
analysis-evasion
Confidence
80% confidence
Finding
Suspicious Unicode normalization or mixed-script content

Context-Inappropriate Capability

Medium
Confidence
98% confidence
Finding
The guide publishes a live-looking Baidu API key and presents it as valid and usable. Exposing service credentials in documentation enables unauthorized use, quota theft, billing abuse, and can help an attacker pivot into the linked cloud application context; in a skill package, this is more dangerous because users may trust and reuse the embedded credential.

Missing User Warnings

Medium
Confidence
97% confidence
Finding
The guide not only displays a specific API key but encourages operators to identify and use the application by that key, without any warning about credential sensitivity. This increases the likelihood of accidental reuse, leakage, and unauthorized API consumption by anyone who reads the file.

Missing User Warnings

Medium
Confidence
90% confidence
Finding
The guide instructs users to run an OCR script on local images but does not disclose that OCR processing uses Baidu's remote API, which likely transmits image contents off-host. That omission creates a privacy and data-handling risk, especially if users test with sensitive documents under the assumption processing is local.

Ae4

Medium
Category
analysis-evasion
Confidence
80% confidence
Finding
Suspicious Unicode normalization or mixed-script content

Missing User Warnings

Medium
Confidence
95% confidence
Finding
The guide tells users to copy a new API Key and Secret Key but does not warn that these are sensitive credentials that must not be pasted into logs, screenshots, chats, source control, or shared config files. In a skill that integrates with a third-party OCR API, this omission increases the chance of credential leakage, which could enable unauthorized API use, billing abuse, or access under the user's account.

Lp3

Medium
Category
MCP Least Privilege
Confidence
92% confidence
Finding
The skill documents and relies on outbound network access to Baidu OCR APIs, but it does not declare any tool scope or permissions. This creates a transparency and policy-enforcement gap: users or the hosting platform may not realize that local image contents will be transmitted off-host to a third party.

Missing User Warnings

Medium
Confidence
96% confidence
Finding
The skill lacks a clear user-facing warning that provided images will be uploaded to Baidu's OCR service. This is a privacy and data-handling issue because users may submit sensitive screenshots, IDs, invoices, or documents without understanding that the content leaves the local environment.

Missing User Warnings

Medium
Confidence
99% confidence
Finding
Hard-coded API_KEY and SECRET_KEY are embedded directly in the source, exposing reusable credentials to anyone with file or repository access. This can lead to unauthorized API use, quota exhaustion, billing abuse, and possible compromise of the associated Baidu cloud account or service data.

Description-Behavior Mismatch

Medium
Confidence
96% confidence
Finding
The manifest describes a skill that supports mixed Chinese/English, formula, and table recognition. However, main() always calls ocr_general_basic() and never exposes or invokes ocr_table() or ocr_formula(), so the actual user-facing behavior is limited to general OCR rather than the broader capability claimed.

Missing User Warnings

Medium
Confidence
94% confidence
Finding
The script sends the full image contents to Baidu's remote OCR API, but the user-facing flow does not clearly warn that local image data will leave the system and be processed by a third party. In an OCR skill, this matters because images often contain sensitive documents, IDs, invoices, or personal information, so silent transmission creates a privacy and compliance risk.

Natural-Language Policy Violations

Low
Confidence
89% confidence
Finding
All user-facing messages, usage text, and descriptions in the script are presented in Chinese only, with no option for the user to select another language. This can violate a language/locale policy when the skill is not explicitly documented as Chinese-only or region-specific.

Intent-Code Divergence

Low
Confidence
82% confidence
Finding
The comment at L046 says '高精度版' and the endpoint used is accurate_basic, but the function docstring at L049 says '基础版'. This documentation is internally contradictory about what variant is being used, creating intent/documentation divergence.

Vague Triggers

Low
Confidence
76% confidence
Finding
This manifest file only describes the skill as '百度 OCR 文字识别 - 准确率 95%+' without any specific trigger phrases, scope limits, or exclusion conditions. In manifest files, missing specificity around when the skill should activate can lead to overly broad or unintended invocation behavior.

Natural-Language Policy Violations

Low
Confidence
80% confidence
Finding
The natural-language metadata is entirely in Chinese, which may impose a language expectation on users without indicating any opt-in, language choice, or region-specific justification. This can be a policy concern when a skill appears to require a specific language or locale by default.

Static analysis

Detected: suspicious.exposed_secret_literal

File appears to expose a hardcoded API secret or token.

Critical
Code
suspicious.exposed_secret_literal
Location
ACTIVATE_GUIDE.md:38

File appears to expose a hardcoded API secret or token.

Critical
Code
suspicious.exposed_secret_literal
Location
baidu_ocr.py:16