FAQ-001110 - Lightning Web Components Manual DOM Security / Security Review Standards

Current Status:VALID_RESPONSEErrorUnable to AnswerSuggests Case

Current FAQ

Question
How do I ensure that manual DOM manipulation in LWC components meets security review standards?
Answer
To ensure manual DOM manipulation in LWC components meets security review standards: 1. **Minimize Use of `lwc:dom="manual"`**: Avoid using it unless absolutely necessary, as it can introduce vulnerabilities. 2. **Use Template Directives**: Prefer template directives to conditionally render elements based on the component's state. 3. **Sanitize User-Controlled Data**: If manual DOM manipulation is unavoidable, sanitize or encode all user-controlled data before rendering to prevent XSS attacks. 4. **Avoid External Dynamic Loading**: Do not dynamically load JavaScript or CSS from external sources. Use static resources within your package for any external scripts or styles. For more details, refer to Salesforce's secure coding practices and documentation.
Enhancing FAQ...

Enhancing FAQ with AI recommendations...

AI Recommended Enhancement

Related Security Rules (click to view)
@lwc/lwc/no-inner-htmlAvoidCreateElementScriptLinkTagAvoidUnescapedHtmlInAura
Question
How do I ensure that manual DOM manipulation in LWC components meets security review standards?
Recommended Answer Update
To ensure manual DOM manipulation in LWC components meets security review standards: 1. **Minimize Use of `lwc:dom="manual"`**: Avoid using it unless absolutely necessary, as it can introduce vulnerabilities. 2. **Use Template Directives**: Prefer template directives to conditionally render elements based on the component's state. 3. **Sanitize User-Controlled Data**: If manual DOM manipulation is unavoidable, sanitize or encode all user-controlled data before rendering to prevent XSS attacks. 4. **Avoid External Dynamic Loading**: Don't dynamically load JavaScript or CSS from external sources. Use static resources within your package for any external scripts or styles. For more details, refer to Salesforce's secure coding practices and documentation.
Reasoning
The FAQ content is accurate and well-structured, but contains a minor wording improvement opportunity. In point 4, changing 'Do not' to 'Don't' makes the language more conversational and consistent with the brand guidelines that recommend using contractions for a friendlier tone. For the security rules selected: - **@lwc/lwc/no-inner-html**: This rule directly relates to the FAQ's discussion of manual DOM manipulation in LWC components. The FAQ's emphasis on sanitizing user-controlled data and avoiding lwc:dom="manual" when possible aligns with this rule's purpose of preventing XSS vulnerabilities through innerHTML usage. - **AvoidCreateElementScriptLinkTag**: This rule connects to the FAQ's point 4 about avoiding external dynamic loading of JavaScript or CSS. The rule detects dynamic creation of script and link tags, which is exactly what the FAQ advises against when it says 'don't dynamically load JavaScript or CSS from external sources.' - **AvoidUnescapedHtmlInAura**: While this is an Aura-specific rule, it relates conceptually to the FAQ's emphasis on sanitizing user-controlled data before rendering. The underlying security principle of preventing XSS through proper data handling applies to both Aura and LWC contexts discussed in the FAQ.
Reasoning References