> For the complete documentation index, see [llms.txt](https://boxlang.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boxlang.ortusbooks.com/boxlang-framework/modularity/esapi/reference/built-in-functions/esapi/issafehtml.md).

# IsSafeHTML

Verifies if the HTML is safe using antisamy policy rules.

The policy can be a string name of a built-in policy, a file path to a custom policy XML file, or a struct for programmatic policy configuration. For full struct documentation, see [`getSafeHTML()`](/boxlang-framework/modularity/esapi/reference/built-in-functions/esapi/getsafehtml.md).

**Built-in policies:** `anythinggoes`, `ebay` (default), `myspace`, `slashdot`, `tinymce`

## Method Signature

```
IsSafeHTML( string, [policy], [force] )
```

### Arguments

| Argument | Type             | Required | Description                                                                             | Default                           |
| -------- | ---------------- | -------- | --------------------------------------------------------------------------------------- | --------------------------------- |
| `string` | `string`         | `true`   | The HTML to validate                                                                    |                                   |
| `policy` | `string\|struct` | `false`  | The policy to use: a string name, file path, or a struct for programmatic configuration | `""` (uses default `ebay` policy) |
| `force`  | `boolean`        | `false`  | When `true` and using a struct policy, evicts it from cache and rebuilds it on demand   | `false`                           |

## Examples

### Basic safety check with default eBay policy

```js
result = isSafeHTML( "<b>Hello</b>" )
// result: true

result = isSafeHTML( "<b>Hello</b><script>alert('xss')</script>" )
// result: false (contains disallowed script tag)
```

### Using a named policy

```js
result = isSafeHTML( "<b>Hello</b><em>World</em>", "myspace" )
// result: true or false depending on whether content violates myspace policy
```

### Custom policy via struct

```js
result = isSafeHTML(
    "<b>Hello</b><em>World</em>",
    {
        basePolicy: "ebay",
        allowTags: [ "b", "em" ]
    }
)
// result: true (content only contains allowed tags)
```

### Force cache eviction for struct policies

```js
// First call caches the policy
result1 = isSafeHTML( "<b>test</b>", policyStruct )

// Second call uses cached policy (for performance)
result2 = isSafeHTML( "<b>test</b>", policyStruct )

// Force eviction and rebuild
result3 = isSafeHTML( "<b>test</b>", policyStruct, true )
```

## Related

* [Canonicalize](/boxlang-framework/modularity/esapi/reference/built-in-functions/esapi/canonicalize.md)
* [DecodeFor](/boxlang-framework/modularity/esapi/reference/built-in-functions/esapi/decodefor.md)
* [DecodeForBase64](/boxlang-framework/modularity/esapi/reference/built-in-functions/esapi/decodeforbase64.md)
* [DecodeForHTML](/boxlang-framework/modularity/esapi/reference/built-in-functions/esapi/decodeforhtml.md)
* [DecodeForJson](/boxlang-framework/modularity/esapi/reference/built-in-functions/esapi/decodeforjson.md)
* [DecodeFromURL](/boxlang-framework/modularity/esapi/reference/built-in-functions/esapi/decodefromurl.md)
* [EncodeFor](/boxlang-framework/modularity/esapi/reference/built-in-functions/esapi/encodefor.md)
* [encodeForCSS](/boxlang-framework/modularity/esapi/reference/built-in-functions/esapi/encodeforcss.md)
* [encodeForDN](/boxlang-framework/modularity/esapi/reference/built-in-functions/esapi/encodefordn.md)
* [encodeForHTML](/boxlang-framework/modularity/esapi/reference/built-in-functions/esapi/encodeforhtml.md)
* [encodeForHTMLAttribute](/boxlang-framework/modularity/esapi/reference/built-in-functions/esapi/encodeforhtmlattribute.md)
* [encodeForJavaScript](/boxlang-framework/modularity/esapi/reference/built-in-functions/esapi/encodeforjavascript.md)
* [encodeForLDAP](/boxlang-framework/modularity/esapi/reference/built-in-functions/esapi/encodeforldap.md)
* [EncodeForSQL](/boxlang-framework/modularity/esapi/reference/built-in-functions/esapi/encodeforsql.md)
* [encodeForURL](/boxlang-framework/modularity/esapi/reference/built-in-functions/esapi/encodeforurl.md)
* [encodeForXML](/boxlang-framework/modularity/esapi/reference/built-in-functions/esapi/encodeforxml.md)
* [encodeForXMLAttribute](/boxlang-framework/modularity/esapi/reference/built-in-functions/esapi/encodeforxmlattribute.md)
* [encodeForXPath](/boxlang-framework/modularity/esapi/reference/built-in-functions/esapi/encodeforxpath.md)
* [esapiDecode](/boxlang-framework/modularity/esapi/reference/built-in-functions/esapi/esapidecode.md)
* [esapiEncode](/boxlang-framework/modularity/esapi/reference/built-in-functions/esapi/esapiencode.md)
* [GetSafeHTML](/boxlang-framework/modularity/esapi/reference/built-in-functions/esapi/getsafehtml.md)
* [SanitizeHTML](/boxlang-framework/modularity/esapi/reference/built-in-functions/esapi/sanitizehtml.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://boxlang.ortusbooks.com/boxlang-framework/modularity/esapi/reference/built-in-functions/esapi/issafehtml.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
