Skip to content

fix(watch-http): 加固配对流程抵御 LAN 暴力破解#1

Open
8676311081 wants to merge 1 commit into
mainfrom
worktree-fix-watch-http-security
Open

fix(watch-http): 加固配对流程抵御 LAN 暴力破解#1
8676311081 wants to merge 1 commit into
mainfrom
worktree-fix-watch-http-security

Conversation

@8676311081

Copy link
Copy Markdown
Owner

Summary

  • 配对码 4 位 → 6 位(空间 10k → 1M)
  • 按 peer IP 记录失败次数(5 分钟滚动窗口)
  • 失败 ≥3 次自动轮换配对码;≥10 次将该 IP 封禁 5 分钟(429)
  • 配对码改用常数时间比较,消除时序侧信道
  • HTTP 解析器改为累积缓冲 + Content-Length 解析 + 64 KiB 上限;原实现假设单次 receive 即拿到完整请求,TCP 分片或大 body 会静默失败
  • 响应构造改为字节拼接,避免 Content-Length 与插值正文错位

后续(不在本 PR)

  • TLS + loopback/interface 绑定。当前仍在所有接口明文监听,LAN 嗅探可见 bearer token 和 SSE 负载。

Test plan

  • swift build 通过
  • 本地联调:iPhone 配对、输错 3 次应看到码轮换,10 次后 429
  • 用 curl 拆包(手工分两次发 header + body)确认能被完整解析

🤖 Generated with Claude Code

- 4-digit → 6-digit pairing code (10k → 1M values)
- Per-peer-IP failure ledger with rolling 5-min window
- Rotate code after 3 failures from a peer
- Block peer for 5 min after 10 failures (429)
- Constant-time code comparison
- Accumulating HTTP parser with Content-Length handling +
  64 KiB cap (previously assumed one packet = one request,
  silently failing on TCP fragmentation or oversized bodies)
- Response builder now constructs bytes explicitly, not
  via string interpolation of Content-Length

Follow-up not in this PR: TLS + loopback/interface binding
option. The endpoint still listens on all interfaces in
plaintext — bearer tokens and SSE payloads remain sniffable
on untrusted LANs until TLS lands.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant