{"record":{"id":"ed32e81ccb245ba4","repo":"crowdsecurity/crowdsec","slug":"unable-to-compile-apply-s-w","errorCode":null,"errorMessage":"unable to compile apply %s : %w","messagePattern":"unable to compile apply (.+?) : %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/appsec/appsec.go","lineNumber":172,"sourceCode":"\t}\n\n\topts := exprhelpers.GetExprOptions(env)\n\tif patcher != nil {\n\t\topts = append(opts, expr.Patch(patcher))\n\t}\n\tif h.Filter != \"\" {\n\t\tprogram, err := expr.Compile(h.Filter, opts...) // FIXME: opts\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"unable to compile filter %s : %w\", h.Filter, err)\n\t\t}\n\n\t\th.FilterExpr = program\n\t}\n\n\tfor _, apply := range h.Apply {\n\t\tprogram, err := expr.Compile(apply, opts...)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"unable to compile apply %s : %w\", apply, err)\n\t\t}\n\n\t\th.ApplyExpr = append(h.ApplyExpr, program)\n\t}\n\n\treturn nil\n}\n\ntype AppsecTempResponse struct {\n\tInBandInterrupt         bool\n\tOutOfBandInterrupt      bool\n\tAction                  string                // allow, deny, captcha, challenge, log\n\tUserHTTPResponseCode    int                   // The response code to send to the user\n\tUserHTTPBodyContent     string                // The body content to send to the user, only for challenge response\n\tUserHTTPCookies         []cookie.AppsecCookie // Raw Set-Cookie headers to send to the user.\n\tUserHeaders             map[string][]string   // Headers to send to the user\n\tBouncerHTTPResponseCode int                   // The response code to send to the remediation component\n\tSendEvent               bool                  // do we send an internal event on rule match","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/appsec/appsec.go#L154-L190","documentation":"Hook.Build compiles each entry of the hook's `apply` list as expr programs that mutate the request/transaction state. If any apply expression fails expr.Compile, the hook build aborts with 'unable to compile apply'. Same nature as the filter compile error but for the apply (side-effect) expressions.","triggerScenarios":"Hook.Build iterating h.Apply where one expression fails expr.Compile: invalid syntax, assignment to an unknown variable slot, or calling an undefined function in the AppSec environment.","commonSituations":"Writing `tx.set('name', ...)` with wrong argument order or an unknown helper; typo in target variable; expressions copied from WAF rules that use a different syntax dialect.","solutions":["Read the wrapped expr error to locate the failing apply expression and cause","Verify the variable you assign to exists in the AppSec expr environment (e.g. tx.*, req.*, vars.*)","Fix the apply expression in the appsec-config YAML","Compile-test each apply expression individually to find the offender in a multi-entry list"],"exampleFix":"// before\napply:\n  - \"tx.set('bad')\"\n// after\napply:\n  - \"tx.set('is_bad', true)\"","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Compile-test apply expressions in CI","Verify assignment targets exist"],"tags":["expr","appsec","compilation"],"backgroundTag":"invalid-config-value","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}