跳转到正文
报告库
用途分类 / 其他用途

Fastapi Templates Skill 安全审计

作者说它能做什么(原文)

Create production-ready FastAPI projects with async patterns, dependency injection, and comprehensive error handling. Use when building new FastAPI applications or setting up backend API projects.

第三方安全检查结论

先别安装或运行

已检查文件
2
发现的风险
3
会不会运行危险命令?检查是否下载程序后直接运行、让他人远程控制电脑,或藏起要运行的命令。未发现风险
会不会泄露文件和密钥?检查是否发送含密码或密钥的文件,以及代码里是否直接写了密钥。发现 2 项风险
中风险

任何已登录用户都可按 ID 查询其他用户记录

原文依据:2 处
发现了什么

读取用户的端点要求登录,却没有像更新和删除端点那样检查 current_user.id 与 user_id;已认证用户可选择任意整数 ID,端点会返回 User 响应模型包含的字段。

为什么需要注意

用户资料可被其他普通账户枚举和读取。具体泄露范围取决于未提供的 User 响应模型,但该访问控制缺口适用于模型公开的所有字段。

按 ID 读取用户的端点只要求调用者已登录,并未验证其是否读取本人或具有管理员权限;相比之下,同文件的更新端点明确检查 ID。若采用该示例,任何有效登录用户都可尝试枚举 ID,并收到 User 响应模型暴露的字段。具体泄露范围因未提供 User 模型而无法确定。用户应要求作者说明访问策略,并加入本人或角色权限校验及最小化响应字段。

references/details.md:295来自说明文档打开原文件
@router.get("/{user_id}", response_model=User)async def read_user(    user_id: int,    db: AsyncSession = Depends(get_db),    current_user: User = Depends(get_current_user)):    """Get user by ID."""    user = await user_service.repository.get(db, user_id)    if not user:        raise HTTPException(status_code=404, detail="User not found")    return user
查看另外 1 个位置
references/details.md:307来自说明文档打开原文件
@router.patch("/{user_id}", response_model=User)async def update_user(    user_id: int,    user_in: UserUpdate,    db: AsyncSession = Depends(get_db),    current_user: User = Depends(get_current_user)):    """Update user."""    if current_user.id != user_id:        raise HTTPException(status_code=403, detail="Not authorized")
中风险

数据库调试日志在模板中默认开启,可能记录敏感参数

原文依据:2 处
发现了什么

异步 SQLAlchemy 引擎被固定配置为 echo=True。SQLAlchemy 的回显模式会输出执行的 SQL 及其绑定参数,生产请求中的电子邮件、令牌相关记录或其他业务数据可能进入应用日志。

为什么需要注意

能读取日志的人员或日志平台可能获得原本只应保存在数据库中的个人或业务数据;日志保留和转发还会扩大数据副本范围。

完整应用示例创建数据库引擎时固定启用 `echo=True`,且没有按开发/生产环境切换。SQLAlchemy 回显通常会把执行的 SQL 和绑定参数写入日志;采用该模板后,查询或写入的用户及业务数据可能进入日志,扩大对日志读取者和日志平台的暴露。用户应要求作者默认关闭回显,或仅通过明确的开发环境设置启用,并检查日志保存与访问权限。

references/details.md:65来自说明文档打开原文件
settings = get_settings()engine = create_async_engine(    settings.DATABASE_URL,    echo=True,    future=True)
查看另外 1 个位置
SKILL.md:3来自说明文档打开原文件
name: fastapi-templatesdescription: Create production-ready FastAPI projects with async patterns, dependency injection, and comprehensive error handling. Use when building new FastAPI applications or setting up backend API projects.---
会不会删除文件或一直在后台运行?检查是否大范围删除文件、改写磁盘,或设置自动启动。未发现风险
会不会绕过安全保护?检查是否跳过网站安全验证、开放过多文件权限,或取消操作前的确认。发现 1 项风险
高风险

“生产就绪”示例配置为任意来源、方法和请求头开放 CORS

原文依据:2 处
发现了什么

应用允许所有来源、所有 HTTP 方法和所有请求头,并同时启用凭据模式。这与其“production-ready”用途不相称;复制到真实服务后,浏览器跨站访问面会被不必要地扩大。

为什么需要注意

在浏览器和具体 CORS/凭据组合允许的情况下,恶意网站可代表访问者向 API 发起跨源请求或读取响应。即使浏览器拒绝通配来源与凭据的某些组合,该配置仍可能造成客户端故障,并鼓励后续采用过宽的来源设置。

这是供用户采用的完整应用示例,并被标为“production-ready”。其中 CORS 明确允许任意来源、方法和请求头,同时启用凭据。浏览器对通配符凭据请求有限制,但该配置仍会不必要地扩大跨站访问面,并可能产生与预期不符的行为。用户应要求作者提供按部署域名配置的来源白名单,并在上线前限制方法和请求头。

references/details.md:28来自说明文档打开原文件
# CORS middlewareapp.add_middleware(    CORSMiddleware,    allow_origins=["*"],    allow_credentials=True,    allow_methods=["*"],    allow_headers=["*"],)
查看另外 1 个位置
SKILL.md:3来自说明文档打开原文件
name: fastapi-templatesdescription: Create production-ready FastAPI projects with async patterns, dependency injection, and comprehensive error handling. Use when building new FastAPI applications or setting up backend API projects.---
会不会误导 AI 或隐藏内容?检查工作说明是否要求 AI 忽略你的指令、干扰检查结果,或夹带看不见的文字。未发现风险
会不会偷偷改推广链接或收款方?检查是否强制替换推广链接或收款对象,同时要求隐瞒更改。未发现风险

Skill 逻辑拆解

4 个说明模块

该 Skill 是用于生成 FastAPI 项目的文档型模板,并指示代理在需要完整实现示例时读取随附的 details.md;所提供内容没有安装命令或自动执行入口。

查看原文
SKILL.md:2来自说明文档打开原文件
---name: fastapi-templatesdescription: Create production-ready FastAPI projects with async patterns, dependency injection, and comprehensive error handling. Use when building new FastAPI applications or setting up backend API projects.---
SKILL.md:71来自说明文档打开原文件
## Detailed worked examples and patternsDetailed sections (starting with `## Implementation Patterns`) live in `references/details.md`. Read that file when the navigation summary above is insufficient.

模板从 .env 读取数据库地址和 JWT 密钥,并使用该密钥签发及验证 HS256 访问令牌。

查看原文
references/details.md:45来自说明文档打开原文件
class Settings(BaseSettings):    """Application settings."""    DATABASE_URL: str    SECRET_KEY: str    ACCESS_TOKEN_EXPIRE_MINUTES: int = 30    API_V1_STR: str = "/api/v1"    class Config:        env_file = ".env"
references/details.md:351来自说明文档打开原文件
ALGORITHM = "HS256"def create_access_token(data: dict, expires_delta: Optional[timedelta] = None):    """Create JWT access token."""    to_encode = data.copy()    if expires_delta:        expire = datetime.utcnow() + expires_delta    else:        expire = datetime.utcnow() + timedelta(minutes=15)    to_encode.update({"exp": expire})    encoded_jwt = jwt.encode(to_encode, settings.SECRET_KEY, algorithm=ALGORITHM)    return encoded_jwt
references/details.md:396来自说明文档打开原文件
    try:        payload = jwt.decode(token, settings.SECRET_KEY, algorithms=[ALGORITHM])        user_id: int = payload.get("sub")        if user_id is None:            raise credentials_exception    except JWTError:        raise credentials_exception

数据库依赖在请求处理成功后自动提交事务,发生异常时回滚;仓库层包含创建、更新和删除持久记录的操作。

查看原文
references/details.md:81来自说明文档打开原文件
async def get_db() -> AsyncSession:    """Dependency for database session."""    async with AsyncSessionLocal() as session:        try:            yield session            await session.commit()        except Exception:            await session.rollback()            raise        finally:            await session.close()```
references/details.md:158来自说明文档打开原文件
    async def delete(self, db: AsyncSession, id: int) -> bool:        """Delete record."""        obj = await self.get(db, id)        if obj:            await db.delete(obj)            return True        return False
从这里开始 · 工作说明SKILL.md
fastapi-templates
连线表示工作说明包含的模块,不是实际运行顺序。点击模块可查看原文。

文件引用关系图

1 处引用
哪些文件发起引用引用了什么
连线表示真实的文件引用,不是运行顺序。点击节点可高亮相关连线,并查看具体文件和原文位置。虚线表示还有文件需要定位。
文件与检查记录2 个文件

检查范围与遗漏

逐文件查看涉及的内容

下方列出本次涉及的原文范围;纳入检查不代表已查清所有问题。

  • SKILL.md已纳入全文
  • references/details.md已纳入全文

这份报告只针对上方版本。我们看了拿到的代码和说明文件,没有实际运行 Skill,也没有检查它另外安装的软件包。因此,这不是“保证安全”的承诺;换了版本或使用环境,结果也可能不同。

  • SKILL.md工作说明
  • references/details.md配套文件

代码和说明中提到的操作

读取文件
SKILL.md:73来自说明文档打开原文件
Detailed sections (starting with `## Implementation Patterns`) live in `references/details.md`. Read that file when the navigation summary above is insufficient.
连接外部网站
SKILL.md:116来自说明文档打开原文件
    async with AsyncClient(app=app, base_url="http://test") as client:        yield client
读取密钥或账号配置
references/details.md:32来自说明文档打开原文件
    allow_origins=["*"],    allow_credentials=True,    allow_methods=["*"],
references/details.md:53来自说明文档打开原文件
    class Config:        env_file = ".env"
references/details.md:390来自说明文档打开原文件
    """Get current authenticated user."""    credentials_exception = HTTPException(        status_code=status.HTTP_401_UNAUTHORIZED,
读取了多少行
547
文件校验值(用于核对版本)
89d3dddb24448a91d122a0a5b29ace9fea6ca77852c3cbe74013369ab1876905