{"record":{"id":"330503a92cafc9e5","repo":"Mintplex-Labs/anything-llm","slug":"failed-integrity-signature-check","errorCode":null,"errorMessage":"Failed integrity signature check.","messagePattern":"Failed integrity signature check\\.","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"collector/middleware/verifyIntegrity.js","lineNumber":17,"sourceCode":"const { CommunicationKey } = require(\"../utils/comKey\");\nconst RuntimeSettings = require(\"../utils/runtimeSettings\");\nconst runtimeSettings = new RuntimeSettings();\n\nfunction verifyPayloadIntegrity(request, response, next) {\n  const comKey = new CommunicationKey();\n  if (process.env.NODE_ENV === \"development\") {\n    comKey.log(\"verifyPayloadIntegrity is skipped in development.\");\n    runtimeSettings.parseOptionsFromRequest(request);\n    next();\n    return;\n  }\n\n  const signature = request.header(\"X-Integrity\");\n  if (!signature)\n    return response\n      .status(400)\n      .json({ msg: \"Failed integrity signature check.\" });\n\n  const validSignedPayload = comKey.verify(signature, request.body);\n  if (!validSignedPayload)\n    return response\n      .status(400)\n      .json({ msg: \"Failed integrity signature check.\" });\n\n  runtimeSettings.parseOptionsFromRequest(request);\n  next();\n}\n\nmodule.exports = {\n  verifyPayloadIntegrity,\n};\n","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/collector/middleware/verifyIntegrity.js#L1-L33","documentation":"Collector middleware verifyPayloadIntegrity rejects any request missing the X-Integrity header when NODE_ENV is not 'development'. Every collector API call must carry an HMAC signature computed over the exact request body with the instance communication key; absence yields 400 'Failed integrity signature check.'.","triggerScenarios":"Calling collector endpoints directly (curl, custom scripts, third-party integrations) without signing; sending the signature under a different header name; an intermediate proxy stripping the X-Integrity header; NODE_ENV left as production while testing by hand.","commonSituations":"Custom integration script hits the collector API and forgets header signing; corporate proxy removes custom headers; developer tests against a production-mode instance the way they tested in development mode (where the middleware is skipped).","solutions":["Sign the exact request body with the instance communication key and send the result in the X-Integrity header, mirroring the built-in collector logic.","For local testing only, run the collector with NODE_ENV=development so the middleware logs and skips — never do this in production.","Ensure no proxy between client and collector strips the X-Integrity header.","Confirm the header name capitalization and that it is sent on every collector API request."],"exampleFix":"// before\nawait fetch(`${collectorUrl}/api/upload`, {\n  method: 'POST',\n  headers: { 'Content-Type': 'application/json' },\n  body: JSON.stringify(payload),\n}); // 400 Failed integrity signature check.\n\n// after\nconst comKey = new CommunicationKey();\nconst body = JSON.stringify(payload);\nawait fetch(`${collectorUrl}/api/upload`, {\n  method: 'POST',\n  headers: { 'Content-Type': 'application/json', 'X-Integrity': comKey.sign(body) },\n  body,\n});","handlingStrategy":"validation","validationCode":"function hasIntegrityHeader(headers) {\n  return typeof headers['X-Integrity'] === 'string' && headers['X-Integrity'].length > 0;\n}\n// Before sending to the collector:\nif (!hasIntegrityHeader(reqHeaders)) throw new Error('Request must be signed (X-Integrity header missing).');","typeGuard":null,"tryCatchPattern":"const res = await fetch(collectorUrl, opts);\nif (res.status === 400) {\n  const body = await res.json();\n  if (body.msg === 'Failed integrity signature check.') {\n    // Missing header or bad signature — do not retry blindly; fix signing first\n    throw new Error('Collector rejected request: ' + (hasIntegrityHeader(opts.headers) ? 'signature mismatch' : 'X-Integrity header missing'));\n  }\n}","preventionTips":["Centralize request signing in one client helper so no call path can forget the X-Integrity header.","Never run tests against a production-mode collector without signing, even 'just to check'.","Alert on 400 integrity responses — they indicate an unsigned or misconfigured integration, not a transient fault."],"tags":["collector","integrity","hmac","middleware","api-security"],"backgroundTag":"missing-signature-header","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}