diff --git a/README.md b/README.md index 1d9519a..726a853 100644 --- a/README.md +++ b/README.md @@ -365,6 +365,35 @@ To help the JSON RTE Serializer recognize and process additional tags that are c ### Convert JSON to HTML +#### HTML Attribute Name and Value Sanitization + + +This project ensures that HTML attributes are properly validated and sanitized according to the W3C HTML specification. It validates attribute names based on the HTML standards and sanitizes attribute values to ensure correct rendering and security, particularly against cross-site scripting (XSS) vulnerabilities. + +#### Attribute Name Guidelines + +All HTML attribute names must conform to the [W3C HTML specification](https://www.w3.org/TR/2012/WD-html-markup-20120329/syntax.html#attribute-name). These guidelines specify the following rules: + +- **Printable ASCII Characters:** Attribute names must consist only of printable ASCII characters. +- **Case-Insensitive:** Attribute names are case-insensitive, but lowercase is preferred for consistency. +- **No Special Characters:** Attribute names cannot contain spaces or special characters such as `=`, `>`, `<`, `"`, etc. +- **Allowed Attributes:** Attributes such as `xmlns`, `aria-*`, `data-*`, and others defined by HTML5 standards are allowed and must follow specific rules. + +##### Important Note: +If an attribute name does not conform to these rules, the attribute will be **dropped** from the element. + +#### Attribute Value Guidelines + +The values of HTML attributes are sanitized to ensure proper rendering and to mitigate security risks, such as Cross-Site Scripting (XSS). This sanitization process involves replacing HTML entities (like `<`, `>`, `&`, etc.) with their corresponding characters and removing any invalid or unsafe characters. + +Here are some common HTML entities and their replacements: + +- `<` → `<` +- `>` → `>` +- `&` → `&` + + +
ding": 234, + "status": "Active", + "emptyKey<": "12", + "country/": "USA" + }, + "children": [ + { + "text": "" + } + ] + }, ] diff --git a/test/toRedactor.test.ts b/test/toRedactor.test.ts index 6517f88..adbb8aa 100644 --- a/test/toRedactor.test.ts +++ b/test/toRedactor.test.ts @@ -279,6 +279,12 @@ describe("Testing json to html conversion", () => { const html = toRedactor(json); expect(html).toBe(expectedValue["RT-360"].html[4]); }) + + it("should drop invalid attribute names",()=>{ + const json = expectedValue["RT-360"].json[5] + const html = toRedactor(json); + expect(html).toBe(expectedValue["RT-360"].html[5]); + }) }) test('should convert numeric width to string', () => {