Back to skill

Security audit

FastAPI+SQLAlchemy 后端部署排障

Security checks for vulnerabilities and agentic risk

Overview

The skill is a troubleshooting guide, but it includes production-looking FastAPI auth guidance that returns no user identity and could weaken protected endpoints if copied directly.

Review this skill before installing or using it. Do not copy the get_current_user_id snippet into a real application unless you replace it with proper token/session validation that rejects unauthenticated requests. Treat the psutil install command as a troubleshooting hint and prefer pinned, reviewed dependencies in your project lockfile.

Vulnerability Patterns
  • Unauthorized Access and Privilege EscalationObtains permissions beyond the task's legitimate needs
  • Insecure DependenciesIntroduces malicious components through unsafe dependency sources
  • 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
Findings (2)

T05 · Unauthorized Access and Privilege Escalation

Error
Location
SKILL.md:74
Finding
Authentication Dependency Stub May Permit Unauthorized Access## Vulnerability Details **File Location**: `SKILL.md`, lines 74-76 **Vulnerability Type**: Authentication and authorization bypass **Risk Level**: High **Vulnerable Code**: ```python async def get_current_user_id(): """Get current user ID""" return None ``` ### Technical Analysis The Skill recommends implementing an authentication dependency that neither validates credentials nor rejects unauthenticated requests. It always returns `None`. In a FastAPI application, dependencies named `get_current_user_id` are commonly used as security boundaries for protected endpoints. Returning `None` rather than raising an authentication exception can cause downstream handlers to process an unauthenticated request. Exploitability depends on how callers handle the returned value, but endpoints that interpret `None` as a default user, omit an explicit null check, or rely solely on successful dependency execution may become accessible without valid credentials. ### Attack Path 1. An operator follows the troubleshooting instructions and adds the documented dependency. 2. A protected endpoint declares `get_current_user_id` as its authentication dependency. 3. An attacker submits a request without a token, or with an invalid token. 4. The dependency performs no credential verification and returns `None` instead of an HTTP 401 or 403 response. 5. If the endpoint does not independently reject `None`, it continues processing the unauthenticated request. 6. The attacker may access functionality or data that was intended to require authentication. ### Impact Assessment The maximum impact depends on the authorization logic of affected endpoints. Potential consequences include anonymous access to protected operations, disclosure of user or business data, unauthorized state changes, and incorrect user scoping. If privileged endpoints trust this dependency without additional checks, the issue could cross application-level privilege boun ...[truncated 7 chars]
Remediation
## Remediation Suggestions - Remove the placeholder implementation from deployment guidance. - Validate the request credential with the application's established token-verification function. - Return a strongly typed authenticated user identifier only after verifying token signature, expiration, issuer, audience, and required claims. - Raise `HTTPException(status_code=401)` for missing or invalid credentials and `HTTPException(status_code=403)` for insufficient permissions. - Ensure every protected endpoint applies explicit authorization checks after authentication. - Add tests confirming that missing, malformed, expired, and forged tokens are rejected and that users cannot access another user's resources. - Clearly label any illustrative placeholder as non-production code if it must remain in the documentation.

T08 · Insecure Dependencies

Warning
Location
SKILL.md:174
Finding
Unpinned Third-Party Dependency Installation## Vulnerability Details **File Location**: `SKILL.md`, lines 174-177 **Vulnerability Type**: Uncontrolled third-party dependency resolution **Risk Level**: Medium **Vulnerable Code**: ```text **Solution**: Install them separately: ```bash pip install psutil ``` ``` ### Technical Analysis The Skill instructs operators to install `psutil` without an exact version, lockfile, package hash, or approved package-index constraint. Consequently, the installed artifact can vary over time and across environments. Although the documented package name is legitimate and the reviewed Skill does not demonstrate an active dependency-confusion payload, this installation pattern weakens supply-chain integrity. A future compromised release, unsafe package-index configuration, or incompatible update could introduce malicious behavior or destabilize the deployment. Python package installation can execute build backend or setup logic, making package provenance relevant even before normal application runtime. ### Attack Path 1. An operator runs the documented installation command in the backend environment. 2. `pip` resolves package metadata using the environment's configured indexes and selects a currently available compatible release. 3. The selected artifact is downloaded without validation against a project-controlled lockfile or expected cryptographic hash. 4. If the selected release or configured index is compromised, malicious installation logic may execute with the privileges of the operator running `pip`. 5. The installed component may then execute again when imported by the application. ### Impact Assessment A compromised dependency could execute code with the privileges of the deployment account, read application files and environment variables, access credentials available to the backend, modify the environment, or affect application behavior. The practical likelihood is conditional on package or index compromise, but the abse ...[truncated 98 chars]
Remediation
## Remediation Suggestions - Declare `psutil` in the project's reviewed dependency manifest rather than installing it ad hoc. - Pin an approved exact version and generate a lockfile for reproducible resolution. - Require cryptographic hashes for downloaded artifacts, such as through a hash-locked requirements file and `pip install --require-hashes`. - Restrict installation to an approved package index over TLS and review environment-level `pip` index configuration. - Scan the resolved package and transitive dependencies for known vulnerabilities. - Test version upgrades in an isolated build pipeline before production deployment. - Build dependencies under a non-privileged account and deploy immutable, reviewed artifacts rather than installing packages directly on production systems.
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
  • Supply ChainUnpinned Dependencies, External Script Fetching, Obfuscated Code
  • Excessive AgencyUnrestricted Tool Access, Autonomous Decision Making, Scope Creep

Static analysis

No suspicious patterns detected.