# trust(html) - [Description](#description) - [Signature](#signature) - [How it works](#how-it-works) - [Security considerations](#security-considerations) - [Scripts that do not run](#scripts-that-do-not-run) - [Avoid trusting HTML](#avoid-trusting-html) --- ### Description Turns an HTML string into unescaped HTML. **Do not use `m.trust` on unsanitized user input.** Always try to use an [alternative method](#avoid-trusting-html) first, before considering using `m.trust`. --- ### Signature `vnode = m.trust(html)` Argument | Type | Required | Description ----------- | -------------------- | -------- | --- `html` | `String` | Yes | A string containing HTML text **returns** | `Vnode` | | A trusted HTML [vnode](vnodes.md) that represents the input string [How to read signatures](signatures.md) --- ### How it works By default, Mithril escapes all values in order to prevent a class of security problems called [XSS injections](https://en.wikipedia.org/wiki/Cross-site_scripting). ```javascript var userContent = "" var view = m("div", userContent) m.render(document.body, view) // equivalent HTML //
<script>alert('evil')</script>
``` However, sometimes it is desirable to render rich text and formatting markup. To fill that need, `m.trust` creates trusted HTML [vnodes](vnodes.md) which are rendered as HTML. ```javascript var view = m("div", [ m.trust("

Here's some HTML

") ]) m.render(document.body, view) // equivalent HTML //

Here's some HTML

``` Trusted HTML vnodes are objects, not strings; therefore they cannot be concatenated with regular strings. --- ### Security considerations You **must sanitize the input** of `m.trust` to ensure there's no user-generated malicious code in the HTML string. If you don't sanitize an HTML string and mark it as a trusted string, any asynchronous javascript call points within the HTML string will be triggered and run with the authorization level of the user viewing the page. There are many ways in which an HTML string may contain executable code. The most common ways to inject security attacks are to add an `onload` or `onerror` attributes in `` or `