fix(vercel-basic-auth): Authorization ヘッダパースを改善#18
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Walkthrough
Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
テストを先に整備 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/vercel-basic-auth/src/index.ts (1)
62-62: (参考)UTF-8 クレデンシャルのサポートについて
atob()はデコード結果を Latin-1 として解釈します。RFC 7617 では UTF-8 エンコーディングが推奨されているため、非 ASCII 文字を含むユーザー名・パスワードをサポートする場合は、以下のようなデコード処理が必要になる可能性があります:const decoded = new TextDecoder().decode( Uint8Array.from(atob(matched[1]), c => c.charCodeAt(0)) );現時点では ASCII のみのサポートで問題ないかもしれませんが、将来的な考慮事項として記録しておきます。
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/vercel-basic-auth/src/index.ts` at line 62, Replace the simple atob(matched[1]) decode (used to set decoded) with a UTF‑8‑aware decode so credentials containing non‑ASCII characters are handled correctly: use the atob result converted to a Uint8Array (e.g., Uint8Array.from(atob(matched[1]), c => c.charCodeAt(0))) and then decode with new TextDecoder().decode(...) instead of the plain atob call; update the code path in the same block where matched[1] is used and ensure decoded is assigned the TextDecoder output.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/vercel-basic-auth/src/index.ts`:
- Line 62: Replace the simple atob(matched[1]) decode (used to set decoded) with
a UTF‑8‑aware decode so credentials containing non‑ASCII characters are handled
correctly: use the atob result converted to a Uint8Array (e.g.,
Uint8Array.from(atob(matched[1]), c => c.charCodeAt(0))) and then decode with
new TextDecoder().decode(...) instead of the plain atob call; update the code
path in the same block where matched[1] is used and ensure decoded is assigned
the TextDecoder output.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: fb09dedb-e16a-42d7-8b5e-96ee2e5e470e
📒 Files selected for processing (2)
.changeset/fix-vercel-basic-auth-authorization-header.mdpackages/vercel-basic-auth/src/index.ts
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
893f893 to
99399ee
Compare
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
321a958 to
2dfc0a4
Compare
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
f526a3f to
0254f7a
Compare
概要
@plainbrew/vercel-basic-authのbasicAuth関数における Authorization ヘッダパース処理の問題を修正します。Closes #10
変更内容
1. Basic スキームの検証
authorization.split(" ")[1]ではBearerやDigestなどの他スキームも素通りしていた問題を修正。正規表現/^Basic\s+(.+)$/iでスキームを検証するようにしました。2. パスワード中の
:の対応atob(authValue).split(":")では:が複数あると正しく分割できない問題を修正。RFC 7617 に従い、最初の:のインデックスでusernameとpasswordを分割するようにしました。テスト
修正内容に対応するテストを追加しました。
Bearer/Digestスキームを弾くことの確認:が含まれるとき正しく認証できることの確認:を含まない base64 値のとき 401 を返すことの確認