fix: accept Claude session keys in sk-ant-sid02 format#962
fix: accept Claude session keys in sk-ant-sid02 format#962octo-patch wants to merge 2 commits intoChatGPTBox-dev:masterfrom
Conversation
…Box-dev#935) Anthropic now issues session keys with the prefix sk-ant-sid02- in addition to the previous sk-ant-sid01- format. The validation was too strict, rejecting valid new-format keys with an error. Relaxed the check to match any sk-ant-sid prefix to be forward-compatible with future key format versions.
Review Summary by QodoAccept Claude session keys in sk-ant-sid02 format
WalkthroughsDescription• Relaxed Claude session key validation prefix check • Now accepts both sk-ant-sid01 and sk-ant-sid02 formats • Maintains forward compatibility with future key versions • Updated error message to reflect accepted formats Diagramflowchart LR
A["Session Key Validation"] -->|Old: sk-ant-sid01 only| B["Rejected new format keys"]
A -->|New: sk-ant-sid prefix| C["Accepts sid01 and sid02"]
C -->|Future compatible| D["Ready for new formats"]
File Changes1. src/services/clients/claude/index.mjs
|
Code Review by Qodo
1.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe Claude client's constructor session key validation was changed from a strict Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request updates the Claude client to support a wider range of session keys by checking for the 'sk-ant-sid' prefix. A review comment suggests generalizing the error message to align with this more flexible validation logic, ensuring the message remains accurate if additional key formats are introduced.
| if (!sessionKey.startsWith('sk-ant-sid')) { | ||
| throw new Error('Session key invalid: Must be in the format sk-ant-sid01-***** or sk-ant-sid02-*****') |
There was a problem hiding this comment.
The logic has been updated to generically accept any session key starting with sk-ant-sid, which is a good improvement for future-proofing. However, the error message still explicitly lists only sid01 and sid02. If Anthropic releases a sid03 format in the future, this message will become misleading to users because the code would actually accept the key, but the error message would imply it is unsupported. It is better to use a more generic error message that matches the implementation's flexibility.
| if (!sessionKey.startsWith('sk-ant-sid')) { | |
| throw new Error('Session key invalid: Must be in the format sk-ant-sid01-***** or sk-ant-sid02-*****') | |
| if (!sessionKey.startsWith('sk-ant-sid')) { | |
| throw new Error('Session key invalid: Must be in the format sk-ant-sid...') | |
| } |
Tightens the session key validation to match the documented format more
closely. The previous `startsWith('sk-ant-sid')` accepted malformed
values like `sk-ant-sidney` or `sk-ant-sid02` (missing the trailing
`-`), which would later fail authentication with a confusing 'login
first' message.
Now uses /^sk-ant-sid\d+-/ which:
- accepts existing sid01/sid02 keys
- accepts future sidNN versions (forward compatible)
- rejects malformed keys at construction time
Error message updated to reflect the generalised format while still
showing the known examples.
Addresses review feedback from CodeRabbit, Qodo and gemini-code-assist.
|
Thanks for the reviews! I've pushed a follow-up commit (ee16c1e) that addresses the validation/error-message inconsistency raised by CodeRabbit, Qodo and gemini-code-assist. The check is now
Error message updated to |
Fixes #935
Problem
Anthropic has started issuing Claude Web session keys in the format
sk-ant-sid02-*****, but the extension's Claude client validates keys strictly against thesk-ant-sid01-prefix. This causes users with new-format keys to see an error:Solution
Relaxed the session key prefix check from
sk-ant-sid01tosk-ant-sidso that it accepts both thesid01andsid02formats (and any future versioned formats Anthropic may introduce).Testing
src/services/clients/claude/index.mjssk-ant-sid01-xxxxx— still accepted ✓sk-ant-sid02-xxxxx— now accepted ✓invalid-key) — still rejected ✓Summary by CodeRabbit