fix(caip): validate full string in caip2Parts and caip10Parts - #143
fix(caip): validate full string in caip2Parts and caip10Parts#143bayrakdarerdem wants to merge 1 commit into
Conversation
caip2Parts and caip10Parts parsed input with caip.split(":") and only
checked that the destructured segments were non-empty. split() does not
cap the number of segments, so malformed input with extra trailing
:segments (e.g. "eip155:1:extra") silently parsed as if truncated,
instead of being rejected.
caip10Parts is reached from @agentcommercekit/did's did:pkh
createVerificationMethod via the public
createDidPkhDocumentFromCaip10AccountId, which does not itself
re-validate its input against the CAIP-10 pattern -- so a malformed
account ID passed to that entry point could previously produce a DID
document built from silently truncated account data instead of
throwing.
Both functions now test the input against their full regex
(caip2ChainIdRegex / caip10AccountIdRegex) before parsing.
Adds regression tests (caip10Parts previously had no test coverage at
all) and a changeset.
Assisted by Claude (Anthropic).
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
WalkthroughCAIP-2 and CAIP-10 parsers now validate complete input strings before splitting. Tests cover valid identifiers and malformed inputs with extra segments or missing account addresses. A changeset documents the behavior and its effect on DID verification-method creation. ChangesCAIP parser validation
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
Summary
caip2Partsandcaip10Partsparsed input withcaip.split(":")and onlychecked that the destructured segments were non-empty.
split()doesn'tcap the number of segments, so malformed input with extra trailing
:segments(e.g."eip155:1:extra") silently parsed as if truncated,instead of being rejected.
caip10Partsis reached from@agentcommercekit/did'sdid:pkhcreateVerificationMethod, via the publiccreateDidPkhDocumentFromCaip10AccountId. That entry point doesn't itselfre-validate its input against the CAIP-10 pattern, so a malformed account
ID passed there could previously produce a DID document built from
silently truncated account data instead of throwing.
Fix
Both functions now test the input against their full regex
(
caip2ChainIdRegex/caip10AccountIdRegex) before parsing, somalformed input is rejected up front instead of silently truncated.
Tests
caip10Partspreviously hadno test coverage at all).
caipanddidpackage test suites — all passing.Changeset
Included (
@agentcommercekit/caippatch).Assisted by Claude (Anthropic) — the bug and fix were found and
implemented working interactively through the codebase and tests.
Summary by CodeRabbit
Bug Fixes
Tests