{"record":{"id":"50c5e9d3df846267","repo":"crowdsecurity/crowdsec","slug":"message-for-s-contains-bad-data-format-missing-50c5e9","errorCode":null,"errorMessage":"message for '%s' contains bad data format: missing allowlist id","messagePattern":"message for '(.+?)' contains bad data format: missing allowlist id","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/apiserver/papi_cmd.go","lineNumber":308,"sourceCode":"\t\t}\n\tcase \"allowlist_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 := allowlistUnsubscribe{}\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 allowlist name\", message.Header.OperationType)\n\t\t}\n\n\t\tif unsubscribeMsg.Id == \"\" {\n\t\t\treturn fmt.Errorf(\"message for '%s' contains bad data format: missing allowlist id\", message.Header.OperationType)\n\t\t}\n\n\t\tp.Logger.Infof(\"Received allowlist_unsubscribe command from PAPI, unsubscribing from allowlist %s\", unsubscribeMsg.Name)\n\n\t\tif err := p.DBClient.DeleteAllowListByID(ctx, unsubscribeMsg.Name, unsubscribeMsg.Id, true); err != nil {\n\t\t\tif !ent.IsNotFound(err) {\n\t\t\t\treturn err\n\t\t\t}\n\n\t\t\tp.Logger.Warningf(\"Allowlist %s not found\", unsubscribeMsg.Name)\n\t\t}\n\n\t\treturn nil\n\tdefault:\n\t\treturn fmt.Errorf(\"unknown command '%s' for operation type '%s'\", message.Header.OperationCmd, message.Header.OperationType)\n\t}\n\n\treturn nil","sourceCodeStart":290,"sourceCodeEnd":326,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/apiserver/papi_cmd.go#L290-L326","documentation":"ManagementCmd in the PAPI command handler processes 'allowlist_unsubscribe' messages received from PAPI. Before acting, it validates that the decoded unsubscribe payload carries both a name and an id. This error is returned when message.Header.OperationType indicates an allowlist unsubscribe, but the payload's Id field is empty, so the allowlist cannot be identified for deletion.","triggerScenarios":"A PAPI-sent allowlist_unsubscribe command message whose parsed unsubscribeMsg.Id is the empty string when ManagementCmd runs (pkg/apiserver/papi_cmd.go:308).","commonSituations":"Upstream PAPI publishing malformed/incomplete allowlist unsubscribe payloads; schema drift between the PAPI sender and the local decoder leaving Id unset; a manually crafted or replayed message missing the id field.","solutions":["Check the sender (PAPI side) so every allowlist_unsubscribe message includes a non-empty 'id' field in its payload.","Verify the message encoding/decoding path so the Id field is correctly populated (field name/tag mismatch in JSON unmarshal).","Pin sender and receiver to matching message schema versions to avoid drift where 'id' was renamed or omitted."],"exampleFix":"// before: sending an unsubscribe without id\nmsg := AllowListUnsubscribeMsg{Name: \"my-allowlist\"}\n// after\nif msg.Id == \"\" { return errors.New(\"allowlist unsubscribe requires id\") }\nmsg := AllowListUnsubscribeMsg{Name: \"my-allowlist\", Id: \"abc123\"}","handlingStrategy":"validation","validationCode":"if msg.Header.OperationType == \"allowlist_unsubscribe\" && msg.Payload.Id == \"\" { return errors.New(\"cannot send unsubscribe: missing allowlist id\") }","typeGuard":null,"tryCatchPattern":"if err := papi.Send(msg); err != nil { if strings.Contains(err.Error(), \"missing allowlist id\") { /* repair payload and resend */ } return err }","preventionTips":["Always populate both Name and Id in allowlist unsubscribe payloads","Validate outgoing PAPI messages against the schema before publishing","Add integration tests covering empty-field payloads"],"tags":["allowlist","papi","message-validation","crowdsec"],"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-14T05:17:10.506Z"}