{"record":{"id":"8e6b7b5a3c69bd25","repo":"crowdsecurity/crowdsec","slug":"message-for-s-contains-bad-data-format-missing","errorCode":null,"errorMessage":"message for '%s' contains bad data format: missing blocklist name","messagePattern":"message for '(.+?)' contains bad data format: missing blocklist name","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/apiserver/papi_cmd.go","lineNumber":208,"sourceCode":"\t\tp.Logger.Infof(\"Ignoring management command from PAPI in sync mode\")\n\t\treturn nil\n\t}\n\n\tswitch message.Header.OperationCmd {\n\tcase \"blocklist_unsubscribe\":\n\t\tdata, err := json.Marshal(message.Data)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tunsubscribeMsg := blocklistUnsubscribe{}\n\n\t\tif err := json.Unmarshal(data, &unsubscribeMsg); err != nil {\n\t\t\treturn fmt.Errorf(\"message for '%s' contains bad data format: %w\", message.Header.OperationType, err)\n\t\t}\n\n\t\tif unsubscribeMsg.Name == \"\" {\n\t\t\treturn fmt.Errorf(\"message for '%s' contains bad data format: missing blocklist name\", message.Header.OperationType)\n\t\t}\n\n\t\tp.Logger.Infof(\"Received blocklist_unsubscribe command from PAPI, unsubscribing from blocklist %s\", unsubscribeMsg.Name)\n\n\t\tfilter := make(map[string][]string)\n\t\tfilter[\"origin\"] = []string{types.ListOrigin}\n\t\tfilter[\"scenario\"] = []string{unsubscribeMsg.Name}\n\n\t\t_, deletedDecisions, err := p.DBClient.ExpireDecisionsWithFilter(ctx, filter)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"unable to expire decisions for list %s : %w\", unsubscribeMsg.Name, err)\n\t\t}\n\n\t\tp.Logger.Infof(\"deleted %d decisions for list %s\", len(deletedDecisions), unsubscribeMsg.Name)\n\tcase \"reauth\":\n\t\tp.Logger.Infof(\"Received reauth command from PAPI, resetting token\")\n\t\tp.apiClient.GetClient().Transport.(*apiclient.JWTTransport).ResetToken()\n\tcase \"force_pull\":","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/apiserver/papi_cmd.go#L190-L226","documentation":"ManagementCmd processes management commands received over the PAPI websocket from CrowdSec Central API. For a 'blocklist_unsubscribe' command the payload must contain a non-empty 'name' field identifying the blocklist to unsubscribe from. This error is thrown when the JSON payload unmarshals successfully into blocklistUnsubscribe but its Name field is empty, meaning the central API sent a malformed/incomplete message.","triggerScenarios":"A blocklist_unsubscribe PAPI message arrives whose JSON data lacks the 'name' key or has it set to \"\" — e.g. the upstream central API emits an empty placeholder message or a schema change drops the name field.","commonSituations":"Central API (CAPI) pushing commands with partial payloads; proxy or middleware stripping fields from the websocket message; version mismatch between the console/central API and the local crowdsec agent where the payload shape changed.","solutions":["Check the crowdsec logs for the operation_type in the error to identify which blocklist unsubscribe command was malformed, then inspect the central console for the affected blocklist","Update crowdsec to the latest version so payload handling matches the current central API schema","If it persists, report the malformed payload to CrowdSec (the sender side constructs the message); as a workaround the command is simply rejected and processing continues","Verify no intermediary (proxy, custom integration) rewrites or truncates PAPI websocket messages"],"exampleFix":"// before: payload {\"operation_cmd\":\"blocklist_unsubscribe\",\"data\":{}}\n// after: include the required field\n// {\"operation_cmd\":\"blocklist_unsubscribe\",\"data\":{\"name\":\"my-blocklist\"}}","handlingStrategy":"validation","validationCode":"msg, ok := message.Data.(map[string]interface{})\nname, ok2 := msg[\"name\"].(string)\nif !ok || !ok2 || name == \"\" {\n    return fmt.Errorf(\"blocklist_unsubscribe payload missing 'name'\")\n}","typeGuard":"func validBlocklistUnsubscribe(d map[string]interface{}) bool {\n    n, ok := d[\"name\"].(string)\n    return ok && n != \"\"\n}","tryCatchPattern":"if err := ManagementCmd(ctx, msg, p, false); err != nil {\n    if strings.Contains(err.Error(), \"missing blocklist name\") {\n        log.Warnf(\"skipping malformed PAPI command: %v\", err)\n        return nil\n    }\n    return err\n}","preventionTips":["Keep crowdsec and the enrolled console in sync on versions","Do not modify or filter PAPI websocket payloads in proxies","Monitor logs for repeated 'bad data format' messages indicating a sender-side bug"],"tags":["crowdsec","papi","websocket","payload-validation"],"backgroundTag":"empty-required-field","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}