fix(state-node): unify request PoP with signed timestamp; drop jti single-use; verify JWT over wire bytes (#60, #61) - #62
Closed
somasekimoto wants to merge 1 commit into
Closed
somasekimoto wants to merge 1 commit into
somasekimoto wants to merge 1 commit into
Conversation
…op jti single-use; verify JWT over wire bytes Closes #61, closes #60. 問題(#61): 委譲 JWT の PoP 署名対象が固定文字列 {iss}:{aud}:{jti} で、 リクエストの新しさが署名に入っていなかった。その帳尻合わせの jti 単回消費が 「委譲トークンを 1 個渡して TTL 内で再利用する」SDK の設計と矛盾し、 履歴取得 → データ取得という通常の read すら成立しなかった(nonce 記録は ノードごとに独立で一貫性もない)。 修正(案 A): 署名対象をトークン種別によらず {operation}:{resource}:{timestamp} (書き込みは body hash + timestamp)に統一。リプレイ防御は署名内 timestamp の 鮮度チェック(5 分窓)に一本化し、jti 単回消費と nonce ストアを廃止。 timestamp はサーバ時刻フォールバックをやめ構造的に必須とした(欠如 = 認証 エラー)。盗まれた署名でできることは「同じリソースへの同じ操作を 5 分以内に 再実行」のみで、owner 用の非 JWT パスと同水準。 問題(#60): JWT 署名検証がパース後構造体の再シリアライズに依存し、発行者の JSON フィールド順序が異なると正当なトークンを拒否する brittle な実装だった。 修正: 受信したワイヤ上の header.payload セグメントに対して検証する verify_jwt_signature_wire を導入し、JWT 検証 2 箇所をこれに置換。 - PoP 検証は verify_caller_signature に一本化(全経路が authorize 前に通る)。 ucan_adapter は権限判定に専念し、署名は存在チェックのみ(検証は上流で済) - test-auth-generator / テストヘルパも統一形式へ。フィールド順序非依存・ 改ざん拒否・トークン再利用・timestamp 必須の回帰テストを追加 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
Author
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.
概要
Issue #61(委譲 JWT の jti 単回消費が SDK のトークン再利用設計と矛盾)と #60(JWT 署名検証が再シリアライズ依存で brittle)の修正。#54/#56 とは独立の main 向け PR。
#61: PoP を
{operation}:{resource}:{timestamp}に統一(案 A)問題の構造: 委譲 JWT の PoP 署名対象が固定文字列
{iss}:{aud}:{jti}で、同じトークンを使う限り署名が毎回同一 = リプレイと区別できない。timestamp ヘッダは署名に入っておらず差し替え可能。その帳尻合わせとして入っていた jti 単回消費が、修正: 認証スキームをトークン種別によらず 1 本化。
{operation}:{resource}:{timestamp}(書き込みは body hash + timestamp)。リクエストの新しさが署名の中に入るverify_caller_signatureに一本化(全経路が authorize より前に必ず通る)。ucan_adapterは権限判定に専念し、リクエスト署名は存在チェックのみ#60: JWT 署名をワイヤ上のバイト列で検証
パース後構造体を再シリアライズして署名対象を作り直していたため、発行者の JSON フィールド順序・空白が異なると正当なトークンを拒否する実装だった(test-auth-generator に canonical field order ハックが必要だったのはこれが原因)。受信した
header.payloadセグメントそのものを検証するverify_jwt_signature_wireを導入し、JWT 検証 2 箇所(認証アダプタ・認可アダプタ)を置換。テスト
--deny warningsクリーン🤖 Generated with Claude Code