FG
๐Ÿ”Œ APIs & SDKsTwilio

Wrong validation on accountSid when using API Sid/Api Key to initialize the client

Freshabout 21 hours ago
Mar 14, 20260 views
Confidence Score57%
57%

Problem

Issue Summary When initialize the client using API Sid/Key, validation still applied to the username field which will check if the field starts with 'AC'. But API Sid should start with 'SK'. Steps to Reproduce Initialize the twilio SDK client using API Sid/Key Code Snippet [code block] Exception/Log [code block] Technical details: twilio-node version: 3.48.0 node version: 13.12.0

Error Output

Error: accountSid must start with AC

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix โ€“ Awaiting Verification

Update Validation Logic for API Sid Initialization

Medium Risk

The current validation logic for the accountSid in the Twilio SDK incorrectly checks if the provided Sid starts with 'AC'. This validation does not account for API Sids, which start with 'SK'. As a result, using an API Sid leads to a validation error.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Modify Validation Logic in SDK

    Update the Twilio SDK validation logic to allow accountSid values that start with 'SK' for API Sids. This change should be made in the client initialization method.

    javascript
    if (!accountSid.startsWith('AC') && !accountSid.startsWith('SK')) { throw new Error('accountSid must start with AC or SK'); }
  2. 2

    Update Documentation

    Revise the SDK documentation to clarify that both 'AC' and 'SK' prefixes are acceptable for accountSid, depending on whether the user is initializing with a standard Sid or an API Sid.

  3. 3

    Test Changes

    Create unit tests to ensure that both 'AC' and 'SK' prefixed accountSids are accepted without throwing validation errors. Ensure that invalid Sids (not starting with 'AC' or 'SK') still trigger the appropriate error.

    javascript
    describe('AccountSid Validation', () => { it('should accept SK prefixed Sid', () => { expect(() => initializeClient('SK123456')).not.toThrow(); }); it('should throw error for invalid Sid', () => { expect(() => initializeClient('INVALID')).toThrow('accountSid must start with AC or SK'); }); });
  4. 4

    Release Update

    Once changes are made and tested, release the updated version of the Twilio SDK to ensure users have access to the fix.

Validation

To confirm the fix worked, initialize the Twilio SDK client using both an 'AC' prefixed Sid and an 'SK' prefixed Sid. Ensure that both initializations succeed without errors. Additionally, test with an invalid Sid to confirm the error message is triggered correctly.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

twiliosmsapitype:-twilio-enhancement