shadow1ng/fscan · error

webscan_expression_compile_failed

webscan_expression_compile_failed

Error message

webscan_expression_compile_failed: %w

What it means

EvaluateCached compiles a CEL expression with env.Compile(); if the compiler reports issues (syntax errors, undeclared references, type errors) it wraps them under webscan_expression_compile_failed. The expression text is invalid for the declared CEL environment.

Source

Thrown at webscan/lib/Eval.go:168

// EvaluateCached 评估 CEL 表达式(带编译缓存,用于规则执行热路径)
func EvaluateCached(env *cel.Env, expression string, params map[string]interface{}, cache CelProgCache) (ref.Val, error) {
	if expression == "" {
		return types.Bool(true), nil
	}

	var program cel.Program

	if cache != nil {
		if cached, ok := cache[expression]; ok {
			program = cached
		}
	}

	if program == nil {
		ast, issues := env.Compile(expression)
		if issues.Err() != nil {
			return nil, fmt.Errorf("%s: %w", i18n.GetText("webscan_expression_compile_failed"), issues.Err())
		}

		var err error
		program, err = env.Program(ast, GetBaseProgramOptions()...)
		if err != nil {
			return nil, fmt.Errorf("%s: %w", i18n.GetText("webscan_program_create_failed"), err)
		}

		if cache != nil {
			cache[expression] = program
		}
	}

	result, _, err := program.Eval(params)
	if err != nil {
		return nil, fmt.Errorf("%s: %w", i18n.GetText("webscan_expression_eval_failed"), err)
	}

View on GitHub (pinned to 95cc12e753)

Solutions

  1. Read issues.Err() — CEL reports the exact line/offset and reason
  2. Check every identifier in the expression is declared (request/response variables for POCs)
  3. Fix CEL syntax: use contains(), size(), matches() instead of Go/JS idioms
  4. Test the expression in a CEL playground before adding it to the POC
  5. Ensure custom functions used are registered via GetBaseProgramOptions/env options

Example fix

// before (undeclared variable typo)
Evaluate("respone.status == 200", params)
// after
Evaluate("response.status == 200", params)
Defensive patterns

Strategy: validation

Validate before calling

func validCEL(env *cel.Env, expr string) error {
    ast, issues := env.Compile(expr)
    return issues.Err()
}

Try / catch

result, err := Evaluate(expr, params)
if err != nil {
    var ce *cel.Issues
    log.Printf("expression %q failed to compile: %v", expr, err)
    return fmt.Errorf("bad poc expression %q: %w", expr, err)
}

Prevention

When it happens

Trigger: Evaluate(expression, params) / EvaluateCached with an expression containing CEL syntax errors, unknown function names, undeclared variables, or type-incompatible operations for the base env plus POC declarations.

Common situations: POC expressions with Go-style operators CEL doesn't support (&& with mismatched types, == between different types), typos in variable names like respone instead of response, use of functions not registered in the env, quoting problems producing empty or garbled expressions.

Related errors


AI-assisted analysis of shadow1ng/fscan@95cc12e753 (2026-09-06). Data as JSON: /api/errors/145381cd9e970237. Report an issue: GitHub.