R2 图片托管只靠一个主密码:改为按用户校验和 5 分钟上传通行证
Jeremy(@jeremy_develop)把他的扩展的图片托管迁到了 R2,随后意识到,单一主密码一旦泄露就可能产生大额账单;他改成按用户 ID 校验,以及短时的直接上传通行证。回复中补充了按用户的预签名 URL、账单告警,以及限定存储桶范围的 token。
- 适用产品
- R2
- 来源
- 作者经验𝕏 帖子
- 作者
- Jeremy(@jeremy_develop)
要点
- 他说,上传系统只由一个“主密码”保护;一旦泄露,他可能会一觉醒来看到一张巨额 Cloudflare 账单。
- 他的改动:去掉主密码,改为校验每个用户的唯一 ID;不再通过服务器代理上传,而是签发一张“5 分钟临时通行证”,让浏览器直接上传;并从免费测试域名迁到他自己的域名,他说这样也能避开免费额度的速率限制。
- Mohak Bajaj(@MohakBajaj5)建议按用户使用短时的预签名上传 URL,并加上 Cloudflare 账单告警,“这样一次泄露只让你损失一个晚上,而不是一个月”;Jeremy 回复说,账单告警是他的下一步。
- FlareCost 回复说,R2 出站流量为 $0,因此泄露密钥的费用风险在于写入和存储:上传属于 Class A 操作(每月免费 100 万次,其后每 100 万次 $4.50),存储在 10 GB 之后为每 GB-month $0.015;限定存储桶范围的 token 能限制损失。2026-11-04 读取的 R2 定价页面列出了相同的费率。
原始来源
发布
原帖
到 𝕏 阅读Jeremy(@jeremy_develop)把他的扩展的图片托管迁到了 R2,随后意识到,单一主密码一旦泄露就可能产生大额账单;他改成按用户 ID 校验,以及短时的直接上传通行证。回复中补充了按用户的预签名 URL、账单告警,以及限定存储桶范围的 token。
Jeremy
@jeremy_develop · 𝕏 原帖
Yesterday, I celebrated moving my extension's image hosting from a 3rd-party (ImgBB) to my own Cloudflare R2. But right before bed, it hit me: the system was protected by a single "master password." If leaked, I could wake up to a massive Cloudflare bill. So today, I fixed it. Here is what I changed: 1. Dropped the master password. The system now strictly verifies each user's unique ID—no more unauthorized file dumps. 2. The server is no longer the middleman. It now simply issues a "5-minute temporary pass", letting the user's browser upload files directly to the cloud. Faster exports, and zero server strain. 3. Upgraded the domain. Swapped the free test domain for our own brand: https://t.co/p5BrutxKCG. It looks way more professional in Notion and easily avoids free-tier rate limits. Users won't notice today's update, but hackers definitely will. Locked the doors so I can finally sleep in peace. #BuildInPublic #Cloudflare #ChromeExtension #IndieHacker #SaaS
来自 @FlareCost 的回复:R2 出站流量为 $0,因此风险在于 Class A 写入(每月免费 100 万,其后 $4.50/百万)和存储(10 GB 之后 $0.015/GB-month);限定存储桶范围的 token 能限制损失。
到 𝕏 阅读FlareCost
@FlareCost · 𝕏 原帖
@jeremy_develop Good fix. R2 egress is $0, so a leaked key's real cost risk is writes and storage: uploads are Class A ops (1M free a month, then $4.50/M) and storage is $0.015/GB-month after 10 GB. Bucket-scoped tokens limit the damage. Estimate: https://t.co/2VrVNsNLKD
来自 @MohakBajaj5 的回复:按用户使用短时的预签名上传 URL,并加上 Cloudflare 账单告警,这样一次泄露的代价是一个晚上,而不是一个月。
到 𝕏 阅读Mohak Bajaj
@MohakBajaj5 · 𝕏 原帖
@jeremy_develop good catch before it hit the bill. i'd add short-lived presigned upload urls per user plus a cloudflare billing alert, so a leak costs you an evening, not a month
Jeremy 回复说,设置 Cloudflare 账单告警是他的下一步,用来限制爆炸半径。
到 𝕏 阅读Jeremy
@jeremy_develop · 𝕏 原帖
@MohakBajaj5 Exactly! Setting up Cloudflare billing alerts is my next step to minimize the blast radius if I ever mess up again. Really appreciate the reminder!
其他推荐阅读
免费额度的存储被旧数据填满:用每晚的 cron 让 KV、R2 和 D1 条目过期
风易(@Michael_liyang)说,最先填满免费额度的是存储,而不是请求配额:KV 缓存、R2 备份和 D1 日志只会增长。他在写入缓存时设置过期时间,并运行一个每晚执行的 cron,先软删除、确认,然后再删除过期的键和文件。
Duncan (@ephraimduncan):信用卡被收取 $1,264,当时仍有 $7,032 Cloudflare 创业抵扣剩余。
Duncan (@ephraimduncan) 在 Cloudflare 向信用卡收取 $1,264、当时仍有 $7,032 创业抵扣可用之后,询问该联系谁。Cloudflare 社交媒体经理 Val Vesa 回复称这可能是故障,请私信提供账户邮箱和账单工单号以便内部升级并修复;Cloudflare 开发者布道师 Harshil 请通过私信发送详情以便转交团队。作者回复称详情正在发送。
预算提醒是喇叭,不是刹车
@GUYUE_LGY 引用 Cloudflare Budget alerts 文档:费用跨过阈值只发邮件,不会暂停或封顶用量。交给 AI 自动运行前,作者只查一件事:到线以后系统究竟做什么。