Back to skill

Security audit

Fastapi

Security checks for vulnerabilities and agentic risk

Overview

The skill is a coherent FastAPI tutorial, but it needs review because some examples encourage persistent environment changes and insecure production authentication defaults.

Install only if you are comfortable reviewing commands before execution. Use a virtual environment, do not allow the agent to change global pip configuration unless you explicitly want that, bind development servers to localhost unless exposure is intentional, and replace all sample secrets and demo users before any real deployment.

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
guides/03-advanced-usage.md:284
Finding

Hardcoded JWT Signing Key and Default User Credential in Authentication Template

Content
View full analysis

Vulnerability Details

File Location: guides/03-advanced-usage.md, lines 284–311
Vulnerability Type: Hardcoded authentication secrets and credentials
Risk Level: High

Vulnerable Code

python
SECRET_KEY = "09d25e094faa6ca2556c818166b7a9563b93f7099f6f0f4caa6cf63b88e8d3e7"
ALGORITHM = "HS256"
ACCESS_TOKEN_EXPIRE_MINUTES = 30

password_hash = PasswordHash.recommended()
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")

# Data models
class Token(BaseModel):
    access_token: str
    token_type: str

class TokenData(BaseModel):
    username: str | None = None

class User(BaseModel):
    username: str
    email: str | None = None
    disabled: bool | None = None

class UserInDB(User):
    hashed_password: str

# Simulated user database
fake_users_db = {
    "johndoe": {
        "username": "johndoe",
        "email": "johndoe@example.com",
        "hashed_password": password_hash.hash("secret"),
        "disabled": False,
    }
}

A second insecure placeholder is shown in the environment configuration example at guides/03-advanced-usage.md, line 622:

bash
SECRET_KEY=super-secret-key

Technical Analysis

The documented authentication implementation uses a fixed, publicly known symmetric key for HS256 JWT signing and verification. Because HS256 uses the same secret for both operations, possession of this key allows an attacker to generate tokens that pass signature validation.

The template also creates a known default account whose password is derived from the literal value secret. Although the password is stored as a hash at runtime, the underlying password is disclosed in the documentation and can be used directly against an application that deploys the example unchanged.

The Skill presents this as a complete authentication implementation and states that the AI can automatically implement JWT authentication. Consequently, generated applications may inherit these values if developers do not replace them. The environm ...[truncated 1734 chars]

Remediation
View remediation

Remediation Suggestions

  1. Remove all fixed signing keys and default passwords from generated authentication code.

  2. Generate a unique, cryptographically secure secret for each deployment, for example with Python's secrets.token_urlsafe(64).

  3. Load the signing key from a protected environment variable or dedicated secret manager rather than source code or committed .env files.

  4. Make the signing key mandatory and fail application startup when it is absent, too short, or equal to a known placeholder.

  5. Add validation similar to:

    python
    import os
    
    SECRET_KEY = os.environ["SECRET_KEY"]
    
    insecure_values = {
        "super-secret-key",
        "change-me",
        "09d25e094faa6ca2556c818166b7a9563b93f7099f6f0f4caa6cf63b88e8d3e7",
    }
    
    if len(SECRET_KEY) < 32 or SECRET_KEY in insecure_values:
        raise RuntimeError("A strong, deployment-specific SECRET_KEY is required")
    
  6. Remove the default johndoe account from production templates. If sample credentials are required for a tutorial, clearly isolate them in test-only code and prevent their use when production mode is enabled.

  7. Rotate the signing key and invalidate all existing tokens if the documented key has ever been deployed.

  8. Keep secret files outside version control, restrict their filesystem permissions, and use deployment-platform secret injection.

  9. Consider asymmetric JWT signing where appropriate so verification services receive only a public key, while the private signing key remains isolated.

  10. Add automated security tests that reject known placeholder secrets and verify that forged or previously signed tokens fail after key rotation.

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
  • Supply ChainUnpinned Dependencies, External Script Fetching, Obfuscated Code
Findings (16)

Ae1

High
Category
analysis-evasion
Confidence
100% confidence
Finding

Referenced artifact was not completely inspected

Content

Scanner excerpt · SKILL.md (reported line 79)May include surrounding context.

md
- [高级用法](./guides/03-advanced-usage.md)

Credential Access

High
Category
Privilege Escalation
Confidence
60% confidence
Finding

Code accesses credential files (SSH keys, AWS credentials, etc.). This could indicate credential theft attempts.

Content

Scanner excerpt · guides/03-advanced-usage.md (reported line 612)May include surrounding context.

access_token_expire_minutes: int = 30

text
class Config:
    env_file = ".env"

settings = Settings()

text

Credential Access

High
Category
Privilege Escalation
Confidence
89% confidence
Finding

The documentation includes a concrete .env example containing a database connection string with embedded username and password and a plaintext SECRET_KEY. Even if presented as sample data, publishing secret-shaped values in instructional content normalizes insecure handling and increases the risk that users copy them into real deployments or accidentally commit real credentials in the same pattern.

Content

Scanner excerpt · guides/03-advanced-usage.md (reported line 618)May include surrounding context.

text

```bash
# .env
APP_NAME=Production API
DEBUG=false
DATABASE_URL=postgresql://user:pass@localhost/mydb

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
88% confidence
Finding

This markdown file presents the skill name/description and all user-facing instructions in Chinese, but does not indicate that the language is optional or limited to a Chinese-speaking context. That can violate language/locale policy because it forces a specific language without user opt-in.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
89% confidence
Finding

The guide explicitly says the AI can directly run package installation commands, which causes real environment changes by installing software and dependencies. Even though this is an installation guide and the commands are ordinary, having an agent execute them without a clear confirmation boundary or warning can lead to unintended modification of the user's system or virtual environment.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
97% confidence
Finding

The command pip config set global.index-url ... makes a persistent system-wide configuration change, redirecting future package installs to a different package index. Without an explicit warning, an agent following this instruction could silently alter the user's package supply chain behavior beyond the current task, creating lasting integrity and trust risks.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The guide explicitly tells an AI to automatically generate and run code, but does not warn that doing so will create files, execute Python, and start a local web server. In an agent context, this can cause unreviewed code execution and local side effects on the user's machine without informed consent.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
98% confidence
Finding

The command using --host 0.0.0.0 exposes the development server on all network interfaces, which can make a demo app reachable from other machines on the local network or beyond depending on environment. Presenting this without a warning is risky, especially in an AI-execution setting where the command may be run automatically.

Content

No source excerpt is available for this finding.

External Transmission

Medium
Category
Data Exfiltration
Confidence
60% confidence
Finding

Data is being sent to an external URL. This could be legitimate telemetry or data exfiltration. Manual review is recommended.

Content

Scanner excerpt · guides/02-quickstart.md (reported line 159)May include surrounding context.

发送 POST 请求:

bash
curl -X POST "http://127.0.0.1:8000/items/" \
  -H "Content-Type: application/json" \
  -d '{"name": "Foo", "price": 45.2}'

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
94% confidence
Finding

The testing section again instructs AI to generate and execute tests, which entails creating files, importing application code, and running local commands via pytest. In an automated agent workflow, this can execute unreviewed code paths and produce unintended local effects without notifying the user.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
90% confidence
Finding

该文档标题及全文内容均使用中文,但未说明这是面向特定中文用户群体的区域性文档,也未提供用户可选择语言/本地化选项。根据规则,未经用户选择而强制特定语言属于自然语言层面的语言/区域政策问题。

Content

No source excerpt is available for this finding.

Rp1

Medium
Category
MCP Rug Pull
Confidence
75% confidence
Finding

Docker image references without a specific tag (:latest is implicit) or digest (@sha256:...) can be silently replaced by a malicious image.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

该 markdown 文件从标题到全部故障排查说明均仅使用中文呈现,没有提供用户可选择的语言选项,也没有说明该技能仅面向中文用户或特定地区。按照语言/locale 政策,强制单一语言且无用户 opt-in 属于自然语言层面的策略问题。

Content

No source excerpt is available for this finding.

External Transmission

Medium
Category
Data Exfiltration
Confidence
60% confidence
Finding

Data is being sent to an external URL. This could be legitimate telemetry or data exfiltration. Manual review is recommended.

Content

Scanner excerpt · troubleshooting.md (reported line 139)May include surrounding context.

排查步骤:

bash
# 检查请求体格式
curl -X POST http://localhost:8000/items/ \
  -H "Content-Type: application/json" \
  -d '{"name": "test", "price": 10.5}'

Missing User Warnings

Low
Category
Not specified by scanner
Confidence
85% confidence
Finding

文档展示了 DELETE /{hero_id} 接口会删除数据库记录并提交事务,但周边说明未提醒这是不可逆或具数据影响的操作。对于 markdown 文件,若描述省略会影响用户数据或系统完整性的行为警告,应予以提示。

Content

No source excerpt is available for this finding.

Missing User Warnings

Low
Category
Not specified by scanner
Confidence
78% confidence
Finding

后台任务示例会将通知信息写入 log.txt,并向用户邮箱发送消息,这涉及用户数据写入和外发通信。文档未提示日志可能包含个人信息,也未提醒邮件发送会触发对外传输行为。

Content

No source excerpt is available for this finding.

Static analysis

Detected: suspicious.exposed_secret_literal

File appears to expose a hardcoded API secret or token.

Critical
Code
suspicious.exposed_secret_literal
Location
guides/03-advanced-usage.md:284