diff --git a/guides/v2.3/frontend-dev-guide/templates/template-security.md b/guides/v2.3/frontend-dev-guide/templates/template-security.md index 7a8d0eb5fc7..bbcf02f4c3e 100644 --- a/guides/v2.3/frontend-dev-guide/templates/template-security.md +++ b/guides/v2.3/frontend-dev-guide/templates/template-security.md @@ -9,15 +9,15 @@ functional_areas: To prevent [XSS] issues Magento recommends the following rules for escaping output in templates: -* If a method indicates that the content is escaped, do not escape: `getTitleHtml()`, `getHtmlTitle()` (the title is ready for the [HTML](https://glossary.magento.com/html) output) +* If a method indicates that the content is escaped, do not escape: `getTitleHtml()`, `getHtmlTitle()` (the title is ready for the [HTML](https://glossary.magento.com/html) output) -* Type casting and [php](https://glossary.magento.com/php) function `count()` don't need escaping (for example `echo (int)$var`, `echo (bool)$var`, `echo count($var)`) +* Type casting and [php](https://glossary.magento.com/php) function `count()` do not need escaping (for example `echo (int)$var`, `echo (bool)$var`, `echo count($var)`) -* Output in single quotes doesn't need escaping (for example `echo 'some text'`) +* Output in single quotes does not need escaping (for example `echo 'some text'`) -* Output in double quotes without variables doesn't need escaping (for example `echo "some text"`) +* Output in double quotes without variables does not need escaping (for example `echo "some text"`) -* For all other cases, escape the data using [specific escape functions](#escape-functions-for-templates). +* For all other cases, escape the data using [specific escape functions](#escape-functions-for-templates). The following code sample illustrates the XSS-safe output in templates: @@ -32,11 +32,27 @@ The following code sample illustrates the XSS-safe output in templates: getAnchorTextHtml() ?> ``` -#### Escape functions for templates +### Escape functions for templates For the following output cases, use the specified function to generate XSS-safe output. -**Case:** JSON output in script context\\ +**Case:** Escape string for the CSS context +**Function:** `escapeCss` + +```php + +"; ?> +
+``` + +The following example shows the escaped HTML output: + +```html + + +``` + +**Case:** JSON output in script context **Function:** No function needed for JSON output. ```html @@ -44,9 +60,9 @@ For the following output cases, use the specified function to generate XSS-safe - ``` -**Case:** JSON output in html/attribute context\\ + +**Case:** JSON output in html/attribute context **Function:** `escapeHtml` ```html @@ -54,7 +70,7 @@ For the following output cases, use the specified function to generate XSS-safe ``` -**Case:** String output that should not contain HTML\\ +**Case:** String output that should not contain HTML **Function:** `escapeHtml` You can pass in an optional array of allowed tags that will not be escaped. @@ -73,7 +89,7 @@ If your text contains special characters, they must be encoded as HTML entities,