FAQ-001148 - Lightning Web Components and JavaScript Security / Uncategorized

Current Status:VALID_RESPONSEErrorUnable to AnswerSuggests Case

Current FAQ

Question
What security measures are required for @AuraEnabled methods that accept configuration parameters?
Answer
To secure @AuraEnabled methods that accept configuration parameters, follow these measures: 1. **Input Validation and Sanitization**: Validate and sanitize inputs to prevent injection attacks like SOQL injection or XSS. Avoid directly using user-controlled inputs in queries or rendering. 2. **Enforce Sharing Rules**: Use the `with sharing` keyword in Apex classes to respect sharing rules. Avoid `without sharing` unless necessary and justified with proper access control checks. 3. **Limit Exposure**: Restrict method access to only what's necessary. Avoid exposing sensitive methods or data unnecessarily. 4. **Avoid Dangerous Methods**: Don't use methods that can introduce vulnerabilities, such as `System.setPassword` or directly handling user credentials. 5. **Secure Data Handling**: Encrypt sensitive data and avoid returning sensitive information, like access tokens, in plain text. 6. **Audit and Logging**: Log method calls and parameter usage to monitor and audit access and changes. 7. **Documentation and Review**: Document security measures and configurations in the AppExchange security review submission. Regularly review the code for secure coding compliance. 8. **Use Secure Coding Guidelines**: Follow Salesforce Secure Coding Guidelines to address vulnerabilities and ensure robust security practices. For more details, you can refer to Salesforce's Secure Coding Guidelines.
Enhancing FAQ...

Enhancing FAQ with AI recommendations...

AI Recommended Enhancement

Related Security Rules (click to view)
ApexSOQLInjectionApexSharingViolationsApexDangerousMethodsApexCRUDViolationApexCSRFApexXSSFromURLParamApexXSSFromEscapeFalse
Question
What security measures are required for @AuraEnabled methods that accept configuration parameters?
Recommended Answer Update
To secure @AuraEnabled methods that accept configuration parameters, follow these measures: 1. **Input Validation and Sanitization**: Validate and sanitize inputs to prevent injection attacks like SOQL injection or XSS. Avoid directly using user-controlled inputs in queries or rendering. 2. **Enforce Sharing Rules**: Use the `with sharing` keyword in Apex classes to respect sharing rules. Avoid `without sharing` unless necessary and justified with proper access control checks. 3. **Limit Exposure**: Restrict method access to only what's necessary. Avoid exposing sensitive methods or data unnecessarily. 4. **Avoid Dangerous Methods**: Don't use methods that can introduce vulnerabilities, such as `System.setPassword` or directly handling user credentials. 5. **Secure Data Handling**: Encrypt sensitive data using platform-provided cryptography and avoid returning sensitive information, like access tokens, in plain text. 6. **Audit and Logging**: Log method calls and parameter usage to monitor and audit access and changes. 7. **Documentation and Review**: Document security measures and configurations in the AppExchange security review submission. Regularly review the code for secure coding compliance. 8. **Use Secure Coding Guidelines**: Follow Salesforce Secure Coding Guidelines to address vulnerabilities and ensure robust security practices. For more details, you can refer to Salesforce's Secure Coding Guidelines.
Reasoning
The FAQ content is largely accurate and comprehensive, covering essential security measures for @AuraEnabled methods. I made one minor refinement to improve clarity and specificity: - Changed "Encrypt sensitive data" to "Encrypt sensitive data using platform-provided cryptography" to provide more specific guidance about using proper encryption methods rather than potentially vulnerable custom implementations. The security rules selected are all directly relevant to the FAQ's content: - ApexSOQLInjection: Directly relates to the FAQ's point #1 about validating inputs to prevent SOQL injection attacks when user-controlled inputs are used in queries - ApexSharingViolations: Directly corresponds to the FAQ's point #2 about enforcing sharing rules with the `with sharing` keyword and avoiding `without sharing` unless justified - ApexDangerousMethods: Matches the FAQ's point #4 about avoiding dangerous methods like `System.setPassword` that can introduce vulnerabilities - ApexCRUDViolation: Relates to the FAQ's broader security guidance about proper data access controls and the mention of secure coding practices - ApexCSRF: Relevant to the FAQ's discussion of securing @AuraEnabled methods, which are commonly targeted by CSRF attacks - ApexXSSFromURLParam and ApexXSSFromEscapeFalse: Both relate to the FAQ's point #1 about preventing XSS attacks through proper input validation and sanitization
Reasoning References
Recommended Related Articles