feat(auth): support longer PINs and harden login throttling - #125
Merged
shaobeichen merged 1 commit intoSep 16, 2026
Merged
Conversation
Allow 8-64 character alphanumeric custom PINs while preserving the generated 8-digit default, and close the concurrent login rate-limit window. Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
背景
我通过公网 IP 和 NAT 端口映射,将 DSH Pocket 的监听端口直接提供给外网访问。公网入口地址长期稳定,Pocket PIN 是该入口的身份验证凭据。
DSH 具备执行本机命令和读写文件的能力,因此成功通过 Pocket 认证后,攻击者可能获得接近远程代码执行的权限。对于直接暴露在互联网中的入口,认证凭据需要具备足够的抗猜测能力。
目前默认 PIN 是 8 位随机数字;自定义 PIN 则必须是恰好 8 位字母数字,可以混合使用:
10^8个可能值仅适用于默认的纯数字随机 PIN。62^8,约2.18 × 10^14种组合。log2(62^8) ≈ 47.63 bits。Pocket 的自定义 PIN 是通过网络提交、由服务端重复验证的固定凭据。它不是本地设备解锁 PIN,也不是验证一次后立即失效的一次性验证码,因此在安全模型上更接近单因素网络密码。
本 PR 保持默认 8 位随机数字 PIN 的行为不变,只将自定义公网及 LAN PIN 扩展为 8–64 位字母数字。这样不会影响现有用户,同时允许公网暴露场景使用密码管理器生成的长随机凭据。
并发限速问题
原有认证流程为:
/pocket-login的 POST body。攻击者可以在限速尚未触发时同时建立大量 POST 请求,暂不结束请求体,然后同步提交这些请求。由于这些请求已经通过第一次限速检查,即使前几个失败已经触发锁定,其余请求仍会继续执行 PIN 比较。
回归测试将失败阈值设置为 3,同时建立并提交 20 个错误 PIN 请求:
429 Too Many Requests。原有限速能够限制后续新请求,但无法有效限制已经通过首次检查的同步并发请求。攻击者可以按并发批次执行大量猜测,实际尝试速率不再符合配置的失败阈值。
本 PR 在请求体读取完成后、执行 PIN 比较前再次检查限速状态,从而关闭该并发窗口。
修改内容
/pocket-login登录页支持最长 64 位输入。兼容性
本 PR 允许最长 64 位,但没有宣称完整实现 NIST 密码规范。保留 8 位最小长度和字母数字字符集,是为了控制修改范围并兼容现有 Pocket PIN 行为。
Test plan
npm test,172 项测试全部通过。/pocket-login输入框允许 8–64 位 PIN。429。安全参考
NIST SP 800-63B 将通过网络提交并由服务端验证的 PIN 纳入 password authenticator 的讨论范围,其附录明确说明文档中的 “password” 也包括 passphrase 和 PIN。对于单因素网络密码,NIST 要求至少 15 个字符,建议允许至少 64 个字符,并要求服务端有效限制失败认证尝试。
OWASP Authentication Cheat Sheet 同样建议:未使用 MFA 时将少于 15 位的密码视为弱密码、最大长度至少支持 64 位,并为登录端点实施可靠的 throttling。
CWE-307 将“未充分限制短时间内大量失败认证尝试”定义为认证安全缺陷。其并行连接示例特别指出,如果认证限制未覆盖并行连接,攻击者可以绕过预期的尝试速率限制。
References
🤖 Generated with Claude Code