fix: ignore empty link code companion reg#2608
Conversation
|
Thanks for opening this pull request and contributing to the project! The next step is for the maintainers to review your changes. If everything looks good, it will be approved and merged into the main branch. In the meantime, anyone in the community is encouraged to test this pull request and provide feedback. ✅ How to confirm it worksIf you’ve tested this PR, please comment below with: This helps us speed up the review and merge process. 📦 To test this PR locally:If you encounter any issues or have feedback, feel free to comment as well. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds an exported helper that extracts and normalizes pairing buffers from ChangesLink Code Companion Registration Robustness
🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels: Suggested reviewers:
🚥 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. 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.
🧹 Nitpick comments (1)
src/Socket/messages-recv.ts (1)
1154-1225: ⚡ Quick winWrap
link_code_companion_regcase in its own block
noSwitchDeclarationsis enabled in this repo; enclosing the case body avoids TDZ/cross-case scope pitfalls from lexical declarations.Proposed fix
- case 'link_code_companion_reg': + case 'link_code_companion_reg': { const linkCodeCompanionRegBuffers = extractLinkCodeCompanionRegBuffers(node) if (!linkCodeCompanionRegBuffers) { logger.debug( { id: node.attrs.id, type: node.attrs.type }, 'link_code_companion_reg notification without pairing data, skipping' ) break } const { ref, primaryIdentityPublicKey, primaryEphemeralPublicKeyWrapped } = linkCodeCompanionRegBuffers const codePairingPublicKey = await decipherLinkPublicKey(primaryEphemeralPublicKeyWrapped) @@ authState.creds.registered = true ev.emit('creds.update', authState.creds) break + } case 'privacy_token':🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/Socket/messages-recv.ts` around lines 1154 - 1225, The case 'link_code_companion_reg' declares lexical bindings that can leak into other switch cases due to noSwitchDeclarations; fix by wrapping the entire case body in its own block (e.g., add { ... } after case 'link_code_companion_reg':) so vars like linkCodeCompanionRegBuffers, codePairingPublicKey, companionSharedKey, linkCodeSalt, linkCodePairingExpanded, encryptPayload, encryptIv, encryptedPayload, identitySharedKey and modifications to authState.creds are scoped to that case; ensure the existing await query(...) and ev.emit('creds.update', ...) remain inside the new block and nothing else changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/Socket/messages-recv.ts`:
- Around line 1154-1225: The case 'link_code_companion_reg' declares lexical
bindings that can leak into other switch cases due to noSwitchDeclarations; fix
by wrapping the entire case body in its own block (e.g., add { ... } after case
'link_code_companion_reg':) so vars like linkCodeCompanionRegBuffers,
codePairingPublicKey, companionSharedKey, linkCodeSalt, linkCodePairingExpanded,
encryptPayload, encryptIv, encryptedPayload, identitySharedKey and modifications
to authState.creds are scoped to that case; ensure the existing await query(...)
and ev.emit('creds.update', ...) remain inside the new block and nothing else
changes.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 84b12a58-ea62-4572-ae0b-3f5a2feaa06d
📒 Files selected for processing (2)
src/Socket/messages-recv.tssrc/__tests__/Socket/messages-recv.test.ts
e574378 to
3bdfaf0
Compare
There was a problem hiding this comment.
No issues found across 2 files
You’re at about 99% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.
|
This PR is stale because it has been open for 14 days with no activity. Remove the stale label or comment or this will be closed in 14 days |
Summary
link_code_companion_reghandling when the notification is missing the pairing buffers Baileys currently needs.idandtype) instead of logging the full node.Protocol / behavior context
WhatsApp can deliver a
link_code_companion_regnotification without the fields used by Baileys's current companion-registration path. That malformed or partial stanza should not crash the receive path. This PR is intentionally defensive: it preserves the existing handling for complete payloads and prevents crashes when the required buffers are absent.WA Web captured JS sanity
Ran:
./tools/wa-web-sanity.sh 'link_code_companion_reg|companion_reg_refresh|DeviceLinkingHandleNotification'Relevant matches from the captured WA Web bundle:
WAWeb/Comms/HandleLoggedInStanza.jsWAWeb/Alt/DeviceLinkingHandleNotification.jsWA/Smax/InMdRefreshCodeNotifyCompanionRequest.jsRelevant excerpt:
The captured handler also branches by
stage, includingprimary_helloandrefresh_code. This PR does not claim to fully mirror that stage-specific flow; it only fixes the crash surface reported in #2600 by making Baileys tolerate incomplete pairing data safely.Tests
yarn lint(0 errors; existing warnings remain)yarn testFixes #2600
Drafted with Codex, reviewed and tested by me.
Summary by CodeRabbit
Bug Fixes
Tests