--- name: bx-esapi description: "Use this skill for OWASP ESAPI encoding, decoding, and HTML sanitization in BoxLang: encodeFor(), encodeForHTML(), encodeForJavaScript(), encodeForSQL(), encodeForURL(), decodeFrom(), htmlSanitize() with AntiSamy, and context-aware output encoding to prevent XSS/injection." --- # bx-esapi: OWASP ESAPI Security Module > BoxLang is the AI-native software productivity platform for building, modernizing and running applications, with developers and AI agents working together. ## Installation ```bash install-bx-module bx-esapi # CommandBox box install bx-esapi ``` ## Encoding BIFs | BIF | Description | |-----|-------------| | `encodeFor( context, value )` | Encode for a named context (see list below) | | `encodeForHTML( value, [canonicalize] )` | Encode for HTML body content | | `encodeForHTMLAttribute( value, [canonicalize] )` | Encode for HTML attribute values | | `encodeForJavaScript( value, [canonicalize] )` | Encode for inline JavaScript | | `encodeForCSS( value, [canonicalize] )` | Encode for CSS values | | `encodeForURL( value, [canonicalize] )` | URL-encode a value | | `encodeForSQL( value, dialect, [canonicalize] )` | Encode for SQL contexts | | `encodeForXML( value, [canonicalize] )` | Encode for XML content | | `encodeForXMLAttribute( value, [canonicalize] )` | Encode for XML attribute values | | `encodeForXPath( value, [canonicalize] )` | Encode for XPath queries | | `encodeForLDAP( value, [canonicalize] )` | Encode for LDAP queries | | `encodeForDN( value, [canonicalize] )` | Encode for LDAP Distinguished Names | ### Available `encodeFor()` Contexts `CSS`, `DN`, `HTML`, `HTMLAttribute`, `JavaScript`, `LDAP`, `SQL`, `URL`, `XML`, `XMLAttribute`, `XPath` ## Output Encoding (XSS Prevention) ```html #encodeForHTML( user.displayName )# #encodeForHTML( user.bio )# Profile Search ``` ## Generic `encodeFor()` ```javascript // Using the generic BIF safeHtml = encodeFor( "HTML", user.comment ) safeJs = encodeFor( "JavaScript", user.name ) safeUrl = encodeFor( "URL", queryParam ) safeAttr = encodeFor( "HTMLAttribute", user.title ) ``` ## Decoding BIFs ```javascript // Decode from specific contexts decoded = decodeFromHTML( "<script>" ) // Returns:
#encodeForHTML( user.bio )#