{"record":{"id":"79186f7106f001ff","repo":"dotnet/aspnetcore","slug":"withcredentials-option-was-not-a-boolean-or-und","errorCode":null,"errorMessage":"withCredentials option was not a 'boolean' or 'undefined' value","messagePattern":"withCredentials option was not a 'boolean' or 'undefined' value","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/SignalR/clients/ts/signalr/src/HttpConnection.ts","lineNumber":95,"sourceCode":"    public baseUrl: string;\n    public connectionId?: string;\n    public onreceive: ((data: string | ArrayBuffer) => void) | null;\n    public onclose: ((e?: Error) => void) | null;\n\n    private readonly _negotiateVersion: number = 1;\n\n    constructor(url: string, options: IHttpConnectionOptions = {}) {\n        Arg.isRequired(url, \"url\");\n\n        this._logger = createLogger(options.logger);\n        this.baseUrl = this._resolveUrl(url);\n\n        options = options || {};\n        options.logMessageContent = options.logMessageContent === undefined ? false : options.logMessageContent;\n        if (typeof options.withCredentials === \"boolean\" || options.withCredentials === undefined) {\n            options.withCredentials = options.withCredentials === undefined ? true : options.withCredentials;\n        } else {\n            throw new Error(\"withCredentials option was not a 'boolean' or 'undefined' value\");\n        }\n        options.timeout = options.timeout === undefined ? 100 * 1000 : options.timeout;\n\n        let webSocketModule: any = null;\n        let eventSourceModule: any = null;\n\n        if (Platform.isNode && typeof require !== \"undefined\") {\n            // In order to ignore the dynamic require in webpack builds we need to do this magic\n            // @ts-ignore: TS doesn't know about these names\n            const requireFunc = typeof __webpack_require__ === \"function\" ? __non_webpack_require__ : require;\n            webSocketModule = requireFunc(\"ws\");\n            eventSourceModule = requireFunc(\"eventsource\");\n        }\n\n        if (!Platform.isNode && typeof WebSocket !== \"undefined\" && !options.WebSocket) {\n            options.WebSocket = WebSocket;\n        } else if (Platform.isNode && !options.WebSocket) {\n            if (webSocketModule) {","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/SignalR/clients/ts/signalr/src/HttpConnection.ts#L77-L113","documentation":"Thrown by the HttpConnection constructor when the IHttpConnectionOptions.withCredentials field is present but is neither a boolean nor undefined. The constructor uses this value to decide whether cross-site XHR/fetch requests carry cookies and credentials, so an invalid type would propagate as ambiguous behavior. The guard at HttpConnection.ts:92-96 fails fast instead of coercing.","triggerScenarios":"Constructing `new HttpConnection(url, options)` or `HubConnectionBuilder.withUrl(url, options)` where `options.withCredentials` is a string (e.g. \"true\"), a number (e.g. 1), an object, or null. The check rejects anything where `typeof` is not exactly \"boolean\" or \"undefined\".","commonSituations":"Reading the value from a JSON config file or environment variable where it arrives as the string \"true\"/\"false\"; deserializing options from query strings; passing a truthy non-boolean like 1 or \"yes\"; assigning `null` to explicitly disable it (null is typeof \"object\").","solutions":["Coerce the value to a boolean before passing it: `options.withCredentials = Boolean(options.withCredentials)` or `options.withCredentials = options.withCredentials === true`.","If loading config from JSON/env, parse explicitly: `withCredentials: String(config.CORS_CREDENTIALS).toLowerCase() === 'true'`.","Omit the field entirely to accept the default of `true`.","Delete the field if previously set to a non-boolean: `delete options.withCredentials`."],"exampleFix":"// before\nconst options = { withCredentials: \"true\" };\nnew HttpConnection(url, options);\n\n// after\nconst options = { withCredentials: String(config.withCredentials).toLowerCase() === 'true' };\nnew HttpConnection(url, options);","handlingStrategy":"validation","validationCode":"function sanitizeHttpOptions(opts) {\n  if (opts && 'withCredentials' in opts) {\n    const v = opts.withCredentials;\n    if (typeof v !== 'boolean' && v !== undefined) {\n      // coerce or throw early with a clear message\n      opts.withCredentials = v === 'true' || v === 1 || v === 'yes';\n    }\n  }\n  return opts;\n}\n// use: new HttpConnection(url, sanitizeHttpOptions(rawOptions));","typeGuard":"function isWithCredentials(v: unknown): v is boolean | undefined {\n  return v === undefined || typeof v === 'boolean';\n}","tryCatchPattern":"try {\n  const conn = new HttpConnection(url, options);\n} catch (e) {\n  if (/withCredentials/.test(String(e))) {\n    options.withCredentials = Boolean(options.withCredentials);\n    return new HttpConnection(url, options);\n  }\n  throw e;\n}","preventionTips":["Type your config objects as IHttpConnectionOptions so the compiler rejects non-boolean values.","Never pass values parsed from JSON/env directly; coerce booleans explicitly.","Centralize HttpConnection option construction in one helper so the rule is enforced once."],"tags":["configuration","typescript","validation","constructor"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}