crowdsecurity/crowdsec · error

appsec rule name is empty for %s

Error message

appsec rule name is empty for %s

What it means

LoadAppsecRules loads appsec rule collections from the hub and requires every rule to carry a non-empty Name. This error aborts loading when a parsed rule file has an empty `name:` field, because rules are registered and matched by name. It names the offending local file path.

Source

Thrown at pkg/appsec/loader.go:34

	appsecRules = make(map[string]AppsecCollectionConfig)

	for _, hubAppsecRuleItem := range hub.GetInstalledByType(cwhub.APPSEC_RULES, false) {
		content, err := os.ReadFile(hubAppsecRuleItem.State.LocalPath)
		if err != nil {
			log.Warnf("unable to read file %s : %s", hubAppsecRuleItem.State.LocalPath, err)
			continue
		}

		var rule AppsecCollectionConfig

		err = yaml.UnmarshalStrict(content, &rule)
		if err != nil {
			log.Warnf("unable to parse file %s : %s", hubAppsecRuleItem.State.LocalPath, err)
			continue
		}

		if rule.Name == "" {
			return fmt.Errorf("appsec rule name is empty for %s", hubAppsecRuleItem.State.LocalPath)
		}

		rule.hash = hubAppsecRuleItem.State.LocalHash
		rule.version = hubAppsecRuleItem.Version

		log.Infof("Adding %s to appsec rules", rule.Name)

		appsecRules[rule.Name] = rule
	}

	if len(appsecRules) == 0 {
		log.Debugf("No appsec rules found")
	}
	return nil
}

View on GitHub (pinned to 909b515798)

Solutions

  1. Open the file named in the error and add a non-empty `name:` field to the rule
  2. If it is a hub collection, run `cscli hub update` / reinstall the collection to restore intact files
  3. Validate custom rules YAML before deploying (name set at top level of the rule document)
  4. Remove or fix locally added files under the hub appsec rules path

Example fix

# before (rules.yaml)
secrets:
  - ...   # no name key
# after
name: crowdsecurity/my-rules
secrets:
  - ...
Defensive patterns

Strategy: validation

Validate before calling

// before loading
data, _ := os.ReadFile(path)
if !strings.Contains(string(data), "name:") {
    return fmt.Errorf("%s missing name field", path)
}

Try / catch

err := LoadAppsecRules(config)
if err != nil {
    log.Fatalf("appsec rules failed to load: %v", err)
}

Prevention

When it happens

Trigger: Loading an appsec rules file from the hub/local hub directory whose YAML front-matter or `name` field is empty, while other files parse fine (parse errors are warned and skipped; empty names are fatal).

Common situations: Hand-edited or locally added appsec rule files missing the `name:` key, corrupted hub downloads, or a custom rules file copied from an older format.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06). Data as JSON: /api/errors/5283ef21462cc0b1. Report an issue: GitHub.