refactor(net): IP limiter の鍵の作り方を戦略ごとの wrapper に包み body reader の差を固定 (R6b・掟 15) - #623
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
…(R6b・掟 15) 第 6 回レビュー Phase 6 の R6b (C15)。lib/net/clientRateLimit.ts に既存の 2 戦略 (hashIpBucket + checkIpRateLimit / anonymizeIp + checkReadRateLimit) をそのまま包む 関数を置き、非 money の 10 route (+ 有料 shops 検索の admission limiter) の呼び出しを 差し替える。鍵・窓・上限・429 応答・評価順は不変 (route ごとに実 relayGuards/ipHash で固定)。 body reader は 4 つとも readJsonBodyCapped と挙動が違う (BOM・不正 UTF-8・cap 境界・ cancel) ため置換せず、差を characterization test で固定した (統一は B-R6f)。 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HeizmagJBgL5peL5mQpxkc
cipherwebllc
force-pushed
the
fix/r6-r6b-limiter-wrappers
branch
from
September 24, 2026 16:35
16760bf to
67da1b3
Compare
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.
概要
第 6 回レビュー Phase 6 (完全リファクタ) の R6b です (指摘 C15)。挙動を変えない整理だけです。
limiter の wrapper
lib/net/clientRateLimit.ts(server-only) に、既存の 2 つの鍵の作り方をそのまま包む関数を置きました。checkClientIpBucketRateLimit: 従来のcheckIpRateLimit(scope, hashIpBucket(clientIp(req)), …)と同じ呼び出しcheckClientIpPrefixRateLimit: 従来のcheckReadRateLimit(keyFor(anonymizeIp(clientIp(req) ?? '')), …)と同じ呼び出し差し替えた route は 11 か所です: SIWE の nonce/verify、license の products/verify、shops の無料と有料検索、directory、tip-messages、handle GET、push の subscribe/test。鍵・窓・上限・429 の応答・認証や検証との順序は変えていません。鍵の統一 (counter がリセットされる) は B-R6 で、limiter を囲む try/catch も残しています (B-R6e)。
guardPaidShopsApi) は、x402 の 402 の前に走る admission limiter で money の入口です。変更は limiter の式の差し替えだけで、支払いの処理には触れていませんが、merge 前に user の明示レビューをお願いします。body reader
4 つの手書きの JSON body reader と
readJsonBodyCappedを比べ、どれも挙動が違うため置き換えていません。差は characterization test で固定しました (BOM 付きで上限 +3 byte を通す・不正な UTF-8 を U+FFFD で受ける・上限ちょうどの不正 byte で 413・上限超過後も全体を読む・content-type の要求)。統一は B-R6f で route ごとに判断します。公開文言・応答は変わりません。
固定と検証 (base = main に rebase 済み)
見つかった既存の問題 (本 PR では変えない・B-R6f・掟 12/15)
relay/jpyc と csv-pass/relay は、本文が JSON の
nullだとtypeof raw.chainIdが try の外にあるため 500 と Sentry event になります (400invalid_payloadが妥当)。状態の変化や資金の危険はなく、relay は IP の admission limiter、CSV パスは SIWE session で守られています。register/claim と relay/status と同じ null 検査を足す追加のみの修正を、別 PR で提案します。🤖 Generated with Claude Code
https://claude.ai/code/session_01HeizmagJBgL5peL5mQpxkc