FAQ-000433 - Connected App Security / Credential Management

Current Status:VALID_RESPONSEErrorUnable to AnswerSuggests Case

Current FAQ

Question
How should developers securely manage and store Connected App credentials (consumer key, consumer secret, client ID) in managed packages?
Answer
To securely manage and store Connected App credentials in managed packages, follow these comprehensive best practices: 1. **Use Protected Storage**: Store credentials using Protected Custom Settings or Protected Custom Metadata to ensure they are not exposed to unauthorized users. Avoid public custom settings, public custom metadata, or custom objects without encryption. 2. **Encryption**: Encrypt credentials using AES-128 or higher encryption. Use Apex Crypto calls to encrypt secrets and store the encryption key in a protected custom setting or hidden custom metadata API field. For server-side applications, store the encryption key separately in a property file that the database process cannot access. 3. **Provide Secure UI**: Build a custom UI using Visualforce, Aura, or LWC to allow subscribers to input credentials securely. Pass the subscriber's input to an Apex class within the managed package for secure storage. 4. **Named Credentials**: Use Named Credentials for locally generated or per-org secrets, but be aware that administrators can view these credentials. 5. **Avoid Hardcoding**: Never hardcode sensitive information in your codebase or store credentials directly on the client side. 6. **Set Proper Permissions**: Ensure fields containing encrypted secrets have appropriate permissions to restrict access. 7. **Use Transient Keyword**: When writing code to update protected custom settings, use the `transient` keyword to prevent sensitive data from being stored in the viewstate. 8. **Prevent Exposure in Logs**: Ensure sensitive data is not logged or exposed in debug logs. 9. **Client Application Storage**: For client-side applications, use vendor-provided keychains, keystores, or DP API for storing credentials. For browser apps, rely on password managers instead of storing secrets directly. 10. **Clear Documentation**: Clearly explain the changes and authorization levels required from the admin in the app setup page and seek user consent for the level of access being requested.
Enhancing FAQ...

Enhancing FAQ with AI recommendations...

AI Recommended Enhancement

Related Security Rules (click to view)
AvoidHardcodedCredentialsInFieldDeclsAvoidHardcodedCredentialsInVarDeclsAvoidHardcodedCredentialsInVarAssignAvoidHardcodedCredentialsInHttpHeaderApexSuggestUsingNamedCredApexBadCrypto
Question
How should developers securely manage and store Connected App credentials (consumer key, consumer secret, client ID) in managed packages?
Recommended Answer Update
To securely manage and store Connected App credentials in managed packages, follow these comprehensive best practices: 1. **Use Protected Storage**: Store credentials using Protected Custom Settings or Protected Custom Metadata to ensure they aren't exposed to unauthorized users. Avoid public custom settings, public custom metadata, or custom objects without encryption. 2. **Encryption**: Encrypt credentials using AES-256 or higher encryption. Use Apex Crypto calls to encrypt secrets and store the encryption key in a protected custom setting or hidden custom metadata API field. For server-side applications, store the encryption key separately in a property file that the database process can't access. 3. **Provide Secure UI**: Build a custom UI using Visualforce, Aura, or LWC to allow subscribers to input credentials securely. Pass the subscriber's input to an Apex class within the managed package for secure storage. 4. **Named Credentials**: Use Named Credentials for locally generated or per-org secrets, but be aware that administrators can view these credentials. 5. **Avoid Hardcoding**: Never hardcode sensitive information in your codebase or store credentials directly on the client side. 6. **Set Proper Permissions**: Ensure fields containing encrypted secrets have appropriate permissions to restrict access. 7. **Use Transient Keyword**: When writing code to update protected custom settings, use the `transient` keyword to prevent sensitive data from being stored in the viewstate. 8. **Prevent Exposure in Logs**: Ensure sensitive data isn't logged or exposed in debug logs. 9. **Client Application Storage**: For client-side applications, use vendor-provided keychains, keystores, or DP API for storing credentials. For browser apps, rely on password managers instead of storing secrets directly. 10. **Clear Documentation**: Clearly explain the changes and authorization levels required from the admin in the app setup page and seek user consent for the level of access being requested.
Reasoning
The FAQ content was largely accurate but needed minor improvements for clarity and alignment with current security standards. Key changes made: 1) Updated encryption recommendation from 'AES-128 or higher' to 'AES-256 or higher' to reflect stronger security standards, 2) Changed 'cannot access' to 'can't access' and 'are not exposed' to 'aren't exposed' and similar contractions for more conversational tone, 3) Changed 'is not logged' to 'isn't logged' for consistency. The related security rules were selected because: AvoidHardcodedCredentialsInFieldDecls relates to point 5 about never hardcoding sensitive information in codebase; AvoidHardcodedCredentialsInVarDecls and AvoidHardcodedCredentialsInVarAssign relate to point 5 about avoiding hardcoded credentials in variable declarations and assignments; AvoidHardcodedCredentialsInHttpHeader relates to secure credential handling mentioned throughout the FAQ; ApexSuggestUsingNamedCred directly relates to point 4 about using Named Credentials; ApexBadCrypto relates to point 2 about using proper encryption methods with Apex Crypto calls.
Reasoning References