Wrong validation on accountSid when using API Sid/Api Key to initialize the client
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
Update Validation Logic for API Sid Initialization
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
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.
javascriptif (!accountSid.startsWith('AC') && !accountSid.startsWith('SK')) { throw new Error('accountSid must start with AC or SK'); } - 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
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.
javascriptdescribe('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
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
Alex Chen
2450 rep