๐Ÿ”ท Core trusted

bx-unsafe-evaluate

Use this skill when you need the evaluate() BIF in BoxLang for legacy CFML migration or dynamic expression evaluation. This module is explicitly opt-in due to security risks and should be avoided in new code.

$ npx skills add ortus-boxlang/skills/boxlang-modules/bx-unsafe-evaluate
$ coldbox ai skills install ortus-boxlang/skills/boxlang-modules/bx-unsafe-evaluate
๐Ÿ”— https://skills.boxlang.io/skills/raw/ortus-boxlang/skills/boxlang-modules~bx-unsafe-evaluate

bx-unsafe-evaluate: Dynamic Code Evaluation

Installation

install-bx-module bx-unsafe-evaluate
# CommandBox
box install bx-unsafe-evaluate

BIF

// evaluate( expression )
// Evaluates the expression dynamically from left to right
// Returns the result of the rightmost expression
result = evaluate( expression )

Usage

// Dynamic property access
name     = "boxlang"
lastName = "majano"
op       = "eq"

result = evaluate( "#name# #op# #name#" )  // true

// Accessing dynamic variable names
variables.userAge   = 30
variables.userEmail = "[email protected]"

fieldName = "userAge"
value     = evaluate( fieldName )   // Returns 30

Security Warning

{% hint style="danger" %} evaluate() is explicitly discouraged for new code. It executes arbitrary BoxLang expressions, which creates serious injection vulnerabilities if any user-controlled input reaches it. {% endhint %}

Safer Alternatives for Common Use Cases

// โŒ UNSAFE: dynamic variable access via evaluate()
result = evaluate( userControlledInput )

// โœ… SAFE: use struct key access instead
data = { name: "Luis", age: 30 }
key  = "name"
result = data[ key ]    // Direct struct access โ€” no evaluate() needed

// โœ… SAFE: use variables scope access
fieldName = "myVar"
result    = variables[ fieldName ]

// โœ… SAFE: use invoke() for dynamic method calls
result = invoke( obj, methodName, args )

When evaluate() Is Acceptable

The ONLY justifiable use case is legacy CFML migration โ€” where existing code relies on evaluate() and refactoring would take significant time. In all such cases, plan to remove it:

// Legacy code being migrated โ€” evaluate() kept temporarily
// TODO: Replace with variables[ fieldName ] when all callers are updated
result = evaluate( fieldName )

Common Pitfalls

  • โŒ Never pass user input (form fields, URL params, request data) to evaluate()
  • โŒ Don't use it in new features โ€” there is always a safer alternative
  • โœ… Use variables[ dynamicKey ] for dynamic variable access
  • โœ… Use invoke( object, methodName, args ) for dynamic method dispatch
  • โœ… Remove any evaluate() calls as part of code modernization