mirror of
https://github.com/codexu/note-gen.git
synced 2026-04-25 21:05:55 +03:00
[GH-ISSUE #796] [bug] 阿里云 OSS 连接失败 (S3 兼容性问题 / 强制 Path-Style 导致 403) #593
Labels
No labels
bug
duplicate
feature
platform: Android
platform: Linux
platform: Windows
platform: iOS
platform: macOS
priority: high
priority: low
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/note-gen#593
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @xianggau on GitHub (Dec 17, 2025).
Original GitHub issue: https://github.com/codexu/note-gen/issues/796
详细描述这个 Bug
问题描述
使用阿里云 OSS (Alibaba Cloud OSS) 作为 S3 图床/存储后端时,即使 AccessKey、SecretKey 和 Endpoint 配置正确,连接测试也会失败,返回
403 Forbidden。经过排查,原因是 NoteGen 在构造 S3 请求时强制使用了 Path-Style (
https://endpoint/bucket),而阿里云 OSS 对这种请求格式的签名校验十分严格(或者需要特定的 Host 头配置),导致默认生成的签名无法通过校验。复现步骤
LTAI...(有效密钥)...(有效密钥)my-bucket-nameoss-cn-beijinghttps://oss-cn-beijing.aliyuncs.com期望行为
连接成功 (HTTP 200)。
实际行为
连接失败,控制台或日志显示 HTTP 403 Forbidden。
技术分析
问题出在
src/lib/imageHosting/s3.ts中的testS3Connection和其他请求构造逻辑。NoteGen 目前的代码逻辑如下:
当 Endpoint 为
https://oss-cn-beijing.aliyuncs.com时,请求 URL 变为:https://oss-cn-beijing.aliyuncs.com/my-bucket-name此时
Host头是oss-cn-beijing.aliyuncs.com。阿里云 OSS 收到此类请求时,可能无法正确解析 Bucket 或者认为签名不匹配。相比之下,标准的 AWS SDK 或其他工具通常会自动使用 Virtual-Hosted Style:
https://my-bucket-name.oss-cn-beijing.aliyuncs.com临时解决方案 (用户侧)
目前用户无法通过常规配置绕过此问题,除非将 Endpoint 修改为 Bucket 域名并将 Bucket 字段留空(但这会导致路径拼接错误)。
建议修复方案
建议在
src/lib/imageHosting/s3.ts中增加对 Virtual-Hosted Style 的支持,或者自动检测阿里云 OSS Endpoint。修改建议 (伪代码):
附:复现脚本 (Node.js)
可以使用以下脚本验证该问题(证明 Credentials 是好的,只是 URL 构造方式导致了 403):
NoteGen 版本
v0.22.4
操作系统
Windows
报错日志
No response