FAQ-000309 - CSS and UI Security / Inline CSS Security Issues

Current Status:VALID_RESPONSEErrorUnable to AnswerSuggests Case

Current FAQ

Question
Are there exceptions to the rule against inline styles for specific components like email templates?
Answer
Yes, there are exceptions to the rule against inline styles for components like email templates in Salesforce. For example, in Visualforce email templates, the attribute `renderUsingSystemContextWithoutSharing` can be used. This allows the template to render in System Context, enabling it to function even if the user does not have access to the related records. This is specifically designed for scenarios where access to records is restricted but sending emails is still required. **For Visualforce Email Templates:** To use CSS in Visualforce Email Templates without violating the "inline CSS" security rule: 1. Save the CSS in a **static resource**. 2. Reference the static resource in the email template. This ensures compliance with security policies by avoiding inline CSS. Additionally, you can use the `renderUsingSystemContextWithoutSharing` attribute in the Visualforce email template to render it in System Context, which helps address access-related issues. **Handling Inline CSS Requirements:** To handle inline CSS requirements in Visualforce email templates, you can use the attribute `renderUsingSystemContextWithoutSharing` set to `true` in the template markup. This allows the Visualforce email template to render in System Context, enabling the email to be sent successfully even if the guest user does not have access to the related records.
Enhancing FAQ...

Enhancing FAQ with AI recommendations...

AI Recommended Enhancement

Related Security Rules (click to view)
VfHtmlStyleTagXss
Question
Are there exceptions to the rule against inline styles for specific components like email templates?
Recommended Answer Update
Yes, there are exceptions to the rule against inline styles for components like email templates in Salesforce. For example, in Visualforce email templates, the attribute `renderUsingSystemContextWithoutSharing` can be used. This allows the template to render in System Context, enabling it to function even if the user doesn't have access to the related records. This is specifically designed for scenarios where access to records is restricted but sending emails is still required. **For Visualforce Email Templates:** To use CSS in Visualforce Email Templates without violating the "inline CSS" security rule: 1. Save the CSS in a **static resource**. 2. Reference the static resource in the email template. This ensures compliance with security policies by avoiding inline CSS. Additionally, you can use the `renderUsingSystemContextWithoutSharing` attribute in the Visualforce email template to render it in System Context, which helps address access-related issues. **Handling Inline CSS Requirements:** To handle inline CSS requirements in Visualforce email templates, you can use the attribute `renderUsingSystemContextWithoutSharing` set to `true` in the template markup. This allows the Visualforce email template to render in System Context, enabling the email to be sent successfully even if the guest user doesn't have access to the related records.
Reasoning
The FAQ content is generally accurate and well-structured. I made one minor improvement for conversational tone by changing "does not have access" to "doesn't have access" to follow the brand guidelines for using contractions. The content appropriately addresses inline CSS security concerns and provides valid workarounds using static resources. I selected the VfHtmlStyleTagXss rule because this FAQ directly addresses CSS usage in Visualforce templates, which is exactly what this security rule is designed to detect and prevent. The FAQ's discussion of avoiding inline CSS and using static resources instead aligns with the security concerns that VfHtmlStyleTagXss addresses - preventing XSS vulnerabilities through unsafe CSS in Visualforce pages.
Reasoning References