半公開キー(kudaq_)と ?key= クエリレーンを追加(型で footgun 防止) - #25
Merged
Conversation
ヘッダを付けられないクライアント向けに /drop の ?key= 認証を条件付きで受理する。 セキュリティは「文書で祈る」でなく「型で統治する」方式: - 別種の半公開キー kudaq_ を導入(auth.ts)。?key= はこの種のみ受理し、通常鍵 kuda_ を URL に貼っても 401(isQueryKey/looksLikeApiKey)。ヘッダとクエリ併用は ヘッダ優先。/ingest・/api/admin/* はクエリキー不可のまま。 - 端点でのURL残留を潰す: observability.logs.invocation_logs=false(呼び出しログに URLが載るのを止める。console.* ログは維持)、全応答 Referrer-Policy: no-referrer、 既存の Cache-Control: no-store。ログ用マスク redactKeyInUrl(key=kuda_***)。 - 発行UI: 「半公開キー(URL利用可)」チェックボックス、一覧に種別バッジ、注記。 /api/keys は query_allowed を受け付け kudaq_ を発行。 - CLAUDE.md の「?key= 禁止」を「?key= は kudaq_ 種のみ受理」に改訂(根拠つき)。 README に2レーンと脅威モデルの根拠を明記。 - テスト: auth.test に kudaq_ 生成・種判定・redact。e2e に ?key= 受理/通常鍵拒否/ 不明キー401/ヘッダ優先/no-referrer/ingest・admin のクエリ不可(68/68)。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013biLJzQnwKk8xnMjrJD7cS
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Contributor
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
kuda | 3f87d07 | Jul 20 2026, 05:47 PM |
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013biLJzQnwKk8xnMjrJD7cS
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.
背景
ヘッダを付けられないクライアント(素の GET しか打てないフェッチ、URL 一本の共有、簡易 IoT)
向けに、外部エージェントから
/dropの?key=認証追加の要望があった。CLAUDE.md は従来「
?key=禁止」だったが、脅威モデルを実環境で評価し直し、「文書で祈る」でなく「型で統治する」強化版で受け入れる(オーナー判断でルール改訂)。
設計: 半公開キー
kudaq_による二層化Authorization: Bearer。通常鍵kuda_・半公開鍵kudaq_どちらも可。?key=kudaq_...。半公開キー種のみ受理。通常鍵kuda_を?key=に貼っても 401(isQueryKey/looksLikeApiKey)。ヘッダとクエリ併用はヘッダ優先。kudaq_はkuda_で始まらない(5文字目がqvs_)ので両種は明確に分離。ハッシュ照合なので、種は発行時に平文へ焼き込まれ DB カラム追加は不要。
これにより「利用者が自分の本キーを URL に貼る」footgun をコードで防ぐ。
端点でのURL残留を潰す(原提案への強化)
observability.logs.invocation_logs = false— Cloudflare の呼び出しログにはリクエスト URL(=
?key=平文)が載る。これを無効化(console.*ログは維持)。※原提案は「観測ログにURLは残らない」と誤認していたが、本 repo は observability 有効。
Referrer-Policy: no-referrer(util.tsのjson()と/・/app.js)。Cache-Control: no-store。redactKeyInUrl(key=kuda_***、grep 可)。現状コードは URL を一切ログしていないことも確認済み。
スコープ(non-negotiable を維持)
/ingest・/api/admin/*はクエリキー不可(ヘッダ/セッション必須。今後も追加しない)。/drop・当該キーの日次クォータ分のみ。台帳に全消費が残り、ダッシュボードからワンクリック無効化。
UI / ドキュメント
種別バッジ(通常 / 半公開(URL可))、注記。
/api/keysはquery_allowedを受け付け。検証
pnpm run typecheck✅pnpm test(vitest ユニット 58件:kudaq_生成・種判定・redactKeyInUrl追加)✅pnpm run test:e2e(wrangler dev + 管理者、68/68 pass)✅?key=<kudaq>→200 / 通常鍵を?key=→401(平文非露出)/ 不明kudaq_→401 /ヘッダ優先で記帳 /
/dropにno-referrer//ingest?key=→401 //api/admin/*?key=→403。observability.logs.invocation_logs:falseは wrangler スキーマ検証を通過(dev 起動で確認)。🤖 Generated with Claude Code
https://claude.ai/code/session_013biLJzQnwKk8xnMjrJD7cS
Generated by Claude Code