How should I securely store API keys and other credentials entered by a customer during initial setup?
Answer
To securely store API keys and credentials entered by a customer during initial setup, follow these best practices:
1. **Use Protected Custom Settings or Metadata**: These ensure sensitive data is securely stored and not exposed to unauthorized users.
2. **Encryption**: If encryption is needed, store the encryption key separately in a protected custom setting or hidden custom metadata API field.
3. **Apex Crypto Calls**: Use Apex Crypto calls for encryption rather than relying solely on encrypted fields.
4. **Configure Permissions**: Ensure permissions are correctly set for fields containing encrypted secrets to prevent unauthorized access.
This approach ensures both security and proper handling of sensitive customer data.
How should I securely store API keys and other credentials entered by a customer during initial setup?
Recommended Answer Update
To securely store API keys and credentials entered by a customer during initial setup, follow these best practices:
1. **Use Protected Custom Settings or Custom Metadata Types**: These ensure sensitive data is securely stored and not exposed to unauthorized users.
2. **Encryption**: If encryption is needed, store the encryption key separately in a protected custom setting or protected custom metadata type field.
3. **Apex Crypto Calls**: Use Salesforce's Apex Crypto class for encryption rather than relying solely on platform encrypted fields.
4. **Configure Permissions**: Ensure permissions are correctly set for fields containing encrypted secrets to prevent unauthorized access.
This approach ensures both security and proper handling of sensitive customer data.
Reasoning
The FAQ content is mostly accurate but contains some imprecise terminology and minor issues that should be addressed:
1. **Terminology precision**: Changed "hidden custom metadata API field" to "protected custom metadata type field" for technical accuracy. Custom Metadata Types have protected fields, not "hidden API fields."
2. **Clarity improvement**: Refined "Custom Settings or Metadata" to "Custom Settings or Custom Metadata Types" for clearer identification of the specific Salesforce features being referenced.
3. **Technical accuracy**: Changed "Apex Crypto calls" to "Salesforce's Apex Crypto class" to be more specific about the platform feature being recommended.
Regarding security rules associations:
- **ApexBadCrypto**: This FAQ discusses encryption using Apex Crypto calls, and this rule detects weak cryptographic practices in Apex code
- **ApexSuggestUsingNamedCred**: While the FAQ doesn't explicitly mention Named Credentials, it deals with storing API credentials, which is exactly what Named Credentials are designed for
- **AvoidHardcodedCredentialsInFieldDecls**: The FAQ teaches about storing credentials in custom settings/metadata, directly relating to avoiding hardcoded credentials in field declarations
- **AvoidHardcodedCredentialsInVarDecls**: Related to the FAQ's guidance on proper credential storage rather than hardcoding in variable declarations
- **AvoidHardcodedCredentialsInVarAssign**: Connected to the FAQ's emphasis on secure credential storage rather than hardcoded assignments
- **ProtectSensitiveData**: This rule is directly applicable as the entire FAQ is about protecting sensitive API keys and credentials