{"id":"693f243481802dce","repo":"websockets/ws","slug":"invalid-value-for-parameter-key-value","errorCode":null,"errorMessage":"Invalid value for parameter \"${key}\": ${value}","messagePattern":"Invalid value for parameter \"(.+?)\": (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"lib/permessage-deflate.js","lineNumber":259,"sourceCode":"   * @return {Array} The offers/response with normalized parameters\n   * @private\n   */\n  normalizeParams(configurations) {\n    configurations.forEach((params) => {\n      Object.keys(params).forEach((key) => {\n        let value = params[key];\n\n        if (value.length > 1) {\n          throw new Error(`Parameter \"${key}\" must have only a single value`);\n        }\n\n        value = value[0];\n\n        if (key === 'client_max_window_bits') {\n          if (value !== true) {\n            const num = +value;\n            if (!Number.isInteger(num) || num < 8 || num > 15) {\n              throw new TypeError(\n                `Invalid value for parameter \"${key}\": ${value}`\n              );\n            }\n            value = num;\n          } else if (!this._isServer) {\n            throw new TypeError(\n              `Invalid value for parameter \"${key}\": ${value}`\n            );\n          }\n        } else if (key === 'server_max_window_bits') {\n          const num = +value;\n          if (!Number.isInteger(num) || num < 8 || num > 15) {\n            throw new TypeError(\n              `Invalid value for parameter \"${key}\": ${value}`\n            );\n          }\n          value = num;\n        } else if (","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/websockets/ws/blob/ae1de54330cef77e487548890fabfeb9aae1d83d/lib/permessage-deflate.js#L241-L277","documentation":"Thrown as a TypeError by normalizeParams() (permessage-deflate.js:256-261) when a client_max_window_bits parameter has a value that is not the boolean true and is not an integer in the range [8, 15]. The value is coerced with the unary + operator and checked with Number.isInteger; values like '7', '16', 'abc', '10.5', or '' all fail. RFC 7692 restricts the window-bits parameter to 9-15, but ws's normalizeParams enforces 8-15 here.","triggerScenarios":"normalizeParams() is called with a configuration where client_max_window_bits is set to a value outside [8, 15] or a non-integer string. This comes from a header like 'permessage-deflate; client_max_window_bits=7', '...=16', '...=abc', or '...=10.5' received from a peer.","commonSituations":"A non-compliant client/server sends a window-bits value outside the valid range. A developer hard-codes an incorrect value. A corrupted header passes a non-numeric value. A version mismatch where a peer uses a range the other side doesn't accept.","solutions":["Ensure the client_max_window_bits value (if numeric) is an integer between 8 and 15 inclusive.","If the parameter is a capability flag (no value), use the bare form 'client_max_window_bits' (parsed as true) rather than assigning a number.","Fix the peer that sends the out-of-range value.","If you cannot control the peer, disable perMessageDeflate to avoid the negotiation."],"exampleFix":"// before — value out of range\nconst header = 'permessage-deflate; client_max_window_bits=7';\n\n// after\nconst header = 'permessage-deflate; client_max_window_bits=10';","handlingStrategy":"validation","validationCode":"// Validate that client_max_window_bits (if numeric) is an integer in [8, 15]\nfunction isValidClientMaxWindowBits(value) {\n  if (value === true) return true;\n  const num = Number(value);\n  return Number.isInteger(num) && num >= 8 && num <= 15;\n}","typeGuard":"function isValidWindowBitsValue(value) {\n  if (value === true) return true;\n  return typeof value === 'number' || /^\\d+$/.test(String(value));\n}","tryCatchPattern":"try {\n  perMessageDeflate.normalizeParams(configurations);\n} catch (err) {\n  if (err instanceof TypeError && err.message.includes('client_max_window_bits')) {\n    console.warn('Invalid client_max_window_bits value:', err.message);\n  } else {\n    throw err;\n  }\n}","preventionTips":["Ensure client_max_window_bits numeric values are integers in the 8-15 range.","Use the bare-flag form (no '=value') when only advertising support.","Validate window-bits values before constructing offers or responses.","Treat peer headers as untrusted and wrap accept() in try-catch."],"tags":["websocket","permessage-deflate","compression","handshake","negotiation","validation"],"analyzedSha":"ae1de54330cef77e487548890fabfeb9aae1d83d","analyzedAt":"2026-08-03T19:11:18.437Z","schemaVersion":2}