shadow1ng/fscan · error

webscan_cel_env_not_initialized

webscan_cel_env_not_initialized

Error message

webscan_cel_env_not_initialized

What it means

ExtendEnvWithVars builds a CEL environment by extending the shared base env with POC-specific variable declarations. If GetBaseEnv() returns nil the base CEL environment was never initialized (cel.NewEnv at startup failed or init was skipped), so extension is impossible.

Source

Thrown at webscan/lib/Eval.go:118

}

// GetBaseEnv 获取基础CEL环境
func GetBaseEnv() *cel.Env {
	initBaseEnv()
	return baseEnv
}

// GetBaseProgramOptions 获取基础程序选项
func GetBaseProgramOptions() []cel.ProgramOption {
	initBaseEnv()
	return baseProgramOpt
}

// ExtendEnvWithVars 扩展基础环境,添加POC特定的变量声明
func ExtendEnvWithVars(varDecls []*exprpb.Decl) (*cel.Env, error) {
	base := GetBaseEnv()
	if base == nil {
		return nil, fmt.Errorf("%s", i18n.GetText("webscan_cel_env_not_initialized"))
	}
	if len(varDecls) == 0 {
		return base, nil
	}
	//nolint:staticcheck // SA1019: cel.Declarations已废弃但CEL库尚未提供替代方案
	return base.Extend(cel.Declarations(varDecls...))
}

// MakeVarDecl 根据变量名和表达式创建变量声明
func MakeVarDecl(key, value string) *exprpb.Decl {
	switch {
	case strings.HasPrefix(value, "randomInt"):
		//nolint:staticcheck // SA1019: decls.NewIdent已废弃但CEL库尚未提供替代方案
		return decls.NewIdent(key, decls.Int, nil)
	case strings.HasPrefix(value, "newReverse"):
		//nolint:staticcheck // SA1019: decls.NewIdent已废弃但CEL库尚未提供替代方案
		return decls.NewIdent(key, decls.NewObjectType("lib.Reverse"), nil)
	default:

View on GitHub (pinned to 95cc12e753)

Solutions

  1. Ensure the package's environment initialization runs before any evaluation (check init() in Eval.go or explicit InitEnv call)
  2. Check startup logs for earlier base-env creation failures and fix the root cause
  3. In tests, call the base env initializer before ExtendEnvWithVars
  4. Verify no build tags exclude the initialization file

Example fix

// before (using eval before init)
env, err := ExtendEnvWithVars(decls)
// after (ensure base env initialized first)
if GetBaseEnv() == nil {
    if err := InitBaseEnv(); err != nil { return err }
}
env, err := ExtendEnvWithVars(decls)
Defensive patterns

Strategy: type-guard

Validate before calling

if GetBaseEnv() == nil {
    return errors.New("CEL base env not initialized; call InitBaseEnv first")
}

Type guard

func baseEnvReady() bool { return GetBaseEnv() != nil }

Try / catch

env, err := ExtendEnvWithVars(decls)
if err != nil {
    if err.Error() == i18n.GetText("webscan_cel_env_not_initialized") {
        return fmt.Errorf("library init skipped: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling ExtendEnvWithVars(varDecls) (directly or via executePoc) before the base environment was created by the package's init/initialization path, or after base env construction failed and was swallowed earlier.

Common situations: Import-order issues where Eval setup is skipped, custom builds with modified init, base env init failing due to a bad custom function/declaration registered at startup, using the library in tests without invoking the initializer.

Related errors


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