crowdsecurity/crowdsec · error

%s: latest hash missing from index. The index file is invali

Error message

%s: latest hash missing from index. The index file is invalid, please run 'cscli hub update' and try again

What it means

FetchContentTo needs the item's latest content hash to validate whatever it writes. If i.latestHash() returns empty, the index entry is missing its hash metadata, and the item cannot be safely fetched, so it errors with a directive to re-download the index.

Source

Thrown at pkg/cwhub/fetch.go:69

	if gotHash != wantHash {
		return fmt.Errorf("%w. The index file is invalid, please run 'cscli hub update' and try again",
			downloader.HashMismatchError{
				Expected: wantHash,
				Got: gotHash,
			})
	}

	return nil
}

// FetchContentTo writes the last version of the item's YAML file to the specified path.
// If the file is embedded in the index file, it will be written directly without downloads.
// Returns whether the file was downloaded (to inform if the security engine needs reloading)
// and the remote url for feedback purposes.
func (i *Item) FetchContentTo(ctx context.Context, contentProvider ContentProvider, destPath string) (bool, string, error) {
	wantHash := i.latestHash()
	if wantHash == "" {
		return false, "", fmt.Errorf("%s: latest hash missing from index. The index file is invalid, please run 'cscli hub update' and try again", i.FQName())
	}

	// Use the embedded content if available
	if i.Content != "" {
		if err := i.writeEmbeddedContentTo(destPath, wantHash); err != nil {
			return false, "", err
		}

		i.State.DownloadPath = destPath

		return true, fmt.Sprintf("(embedded in %s)", i.hub.local.HubIndexFile), nil
	}

	downloaded, _, err := contentProvider.FetchContent(ctx, i.RemotePath, destPath, wantHash, i.hub.logger)

	if err == nil && downloaded {
		i.State.DownloadPath = destPath
	}

View on GitHub (pinned to 909b515798)

Solutions

  1. Run `sudo cscli hub update` to download a fresh index
  2. If it persists, remove /var/lib/crowdsec/data/hub/.index.json and run `cscli hub update` again
  3. Ensure cscli/crowdsec version matches the hub index schema (upgrade if outdated)
Defensive patterns

Strategy: validation

Validate before calling

for _, it := range items {
    if it.LatestHash == "" {
        return fmt.Errorf("item %s has no hash in index; run 'cscli hub update'", it.Name)
    }
}

Try / catch

if _, _, err := item.FetchContentTo(ctx, provider, dest); err != nil {
    if strings.Contains(err.Error(), "latest hash missing from index") {
        return refreshHubIndexAndRetry(ctx)
    }
    return err
}

Prevention

When it happens

Trigger: Calling FetchContentTo (e.g. via itemDiff during hub sync/upgrade) for an item whose index entry lacks the latest hash — index missing the version/hash fields for that item.

Common situations: Corrupted or truncated .index.json, index downloaded by an older cscli version with a different schema, manual edits, or a hub-side item whose metadata was not fully published.

Understand the failure class

Background: "missing required config value" errors: why libraries refuse to start when a configuration key is empty, unset, or blank — this error's family across 48 libraries.

Related errors


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