{"record":{"id":"aaefee41c809b22a","repo":"denoland/deno","slug":"invalid-status-text-init-statustext","errorCode":null,"errorMessage":"Invalid status text: \"${init.statusText}\"","messagePattern":"Invalid status text: \"(.+?)\"","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/fetch/23_response.js","lineNumber":528,"sourceCode":"  response,\n  init,\n  bodyWithType,\n  prefix,\n  context,\n) {\n  // 1.\n  if ((init.status < 200 || init.status > 599) && init.status != 101) {\n    throw new RangeError(\n      `The status provided (${init.status}) is not equal to 101 and outside the range [200, 599]`,\n    );\n  }\n\n  // 2.\n  if (\n    init.statusText &&\n    RegExpPrototypeExec(REASON_PHRASE_RE, init.statusText) === null\n  ) {\n    throw new TypeError(\n      `Invalid status text: \"${init.statusText}\"`,\n    );\n  }\n\n  // 3.\n  response[_response].status = init.status;\n\n  // 4.\n  response[_response].statusMessage = init.statusText;\n  // 5.\n  if (init.headers !== undefined) {\n    const list = responseHeaderList(response);\n    if (\n      !tryFillSingleContentTypeHeader(\n        list,\n        init.headers,\n      )\n    ) {","sourceCodeStart":510,"sourceCodeEnd":546,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/fetch/23_response.js#L510-L546","documentation":"initializeAResponse validates init.statusText against the reason-phrase regex (visible ASCII plus tab and space, no control characters). A status text containing CR, LF, other control bytes, or non-Latin-1 characters fails the regex and throws TypeError 'Invalid status text: \"...\"' — the CRLF restriction prevents response splitting via the status line.","triggerScenarios":"new Response(body, { status: 200, statusText: \"OK\\r\\nSet-Cookie: x=1\" }); statusText containing \\n; statusText with a control character like \\x01.","commonSituations":"Putting dynamic/header-like content into statusText; forwarding statusText from an upstream server verbatim (rare upstream bugs send embedded CRLF); template strings with trailing newlines.","solutions":["Keep statusText to plain visible text: \"OK\", \"Created\", \"Upstream Error\"","Strip CR/LF from any dynamic text: text.replace(/[\\r\\n\\x00-\\x1f]/g, \" \")","Put machine-readable data in headers or the body, never in statusText"],"exampleFix":"// before\nnew Response(\"ok\", { status: 200, statusText: \"OK\\r\\nX-Injected: 1\" }); // throws\n\n// after\nnew Response(\"ok\", { status: 200, statusText: \"OK\" });","handlingStrategy":"validation","validationCode":"function safeStatusText(text) {\n  return String(text ?? \"\").replace(/[\\r\\n\\x00-\\x1f\\x7f]/g, \" \").trim() || \"OK\";\n}\nnew Response(body, { status: 200, statusText: safeStatusText(dynamicText) });","typeGuard":"const REASON_PHRASE_OK = /^[\\t \\x21-\\x7e\\x80-\\xff]*$/;\nfunction isValidStatusText(t: string): boolean {\n  return REASON_PHRASE_OK.test(t);\n}","tryCatchPattern":"try {\n  return new Response(body, { status, statusText });\n} catch (err) {\n  if (err instanceof TypeError && err.message.includes(\"Invalid status text\")) {\n    return new Response(body, { status }); // omit statusText entirely\n  }\n  throw err;\n}","preventionTips":["Strip CR/LF and control characters from any dynamic statusText","Keep statusText human-readable only; put data in headers/body","Treat embedded CRLF in upstream reason phrases as hostile input"],"tags":["fetch","response","status-text","validation"],"backgroundTag":"invalid-status-text","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}