fix(calling): serialize concurrent fetchEncryptionKeyUrl calls to prevent duplicate KMS keys and contact groups - #5178
Draft
mkesavan13 wants to merge 1 commit into
Draft
fix(calling): serialize concurrent fetchEncryptionKeyUrl calls to prevent duplicate KMS keys and contact groups#5178mkesavan13 wants to merge 1 commit into
mkesavan13 wants to merge 1 commit into
Conversation
…8465 AC-2) Jira: https://jira-eng-sjc12.cisco.com/jira/browse/CAI-8465 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
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.
COMPLETES CAI-8465
This pull request addresses
A TOCTOU (time-of-check/time-of-use) concurrency bug in
ContactsClient.fetchEncryptionKeyUrlwhere concurrent callers racing on an empty group list each create a separate KMS key and a duplicate "Other contacts" default group. This produces duplicate KMS resources and duplicate default contact groups in the contacts service.Root Cause:
fetchEncryptionKeyUrlhad no concurrency guard on the KMS-key-creation + default-group-creation path. Multiple concurrent callers (e.g., concurrentcreateContactorfetchDefaultGroupcalls on a fresh client) each checkedthis.groupsas empty, each calledcreateUnboundKeys/createResource, and each calledcreateContactGroup(DEFAULT_GROUP_NAME)independently before any had stored the result.by making the following changes
packages/calling/src/Contacts/ContactsClient.ts— Added a privateencryptionKeyUrlPromise: Promise<string> | undefinedsingle-flight guard infetchEncryptionKeyUrl. The first caller to reach the no-groups branch stores an IIFE promise; concurrent callers await the same promise instead of starting independent KMS/group-creation sequences. On transient failure the guard is cleared so subsequent callers can retry.packages/calling/src/Contacts/ContactsClient.test.ts— Two new unit tests: (1) concurrent calls resolve to the same URL with only one KMS key and one default group created; (2) a failed resolution clears the in-flight promise so the next call retries.packages/calling/src/Contacts/ai-docs/contacts-spec.md— Spec updated to document theencryptionKeyUrlPromisefield, single-flight resolution behavior, and retry-after-failure semantics.Change Type
The following scenarios were tested
ContactsClient.test.tstests pass, including 2 new concurrency tests for AC-2Testing
ContactsClient.test.tstests pass including 2 new concurrency tests for AC-2Acceptance Criteria
fetchEncryptionKeyUrlcalls resolve to a single URL; at most one KMS key and one default contact group created per resolution cycle.concurrent fetchEncryptionKeyUrl creates one key and one default grouppassed in Gate 2 (26/26 tests)packages/callingExternal Validation Required
packages/calling/src/Voicemail/BroadworksBackendConnector.ts:194-220external-dependency— no trusted-host allowlist source exists inpackages/calling; the only BWRKS XSI host is the backend-controlled WDMBW_XSI_URLthat is itself the attack vector (Utils.ts:1300-1327).External validation never uses completion language. Human review performs the external validation. Acceptance criteria and recorded evidence are disclosed for human review; external validation remains explicitly unrun by JiraToPr.
Contract Discovery Warnings
The GAI Coding Policy And Copyright Annotation Best Practices
I certified that
Jira: https://jira-eng-sjc12.cisco.com/jira/browse/CAI-8465
🤖 Generated with Claude Code