{"record":{"id":"537d813cbcf3071e","repo":"Significant-Gravitas/AutoGPT","slug":"response-too-large","errorCode":null,"errorMessage":"Response too large.","messagePattern":"Response too large\\.","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"autogpt_platform/frontend/src/app/(platform)/library/components/LibraryImportDialog/components/ExternalWorkflowTab/fetchWorkflowFromUrl.ts","lineNumber":73,"sourceCode":"      error: err instanceof Error ? err.message : \"Failed to fetch workflow.\",\n    };\n  }\n}\n\nasync function fetchN8nWorkflow(templateId: string): Promise<string> {\n  // Only ever fetch from the hardcoded API base + numeric ID.\n  // parseInt + toString round-trips to guarantee the value is purely numeric,\n  // preventing any path-traversal or SSRF via the interpolated segment.\n  const safeId = parseInt(templateId, 10);\n  if (!Number.isFinite(safeId) || safeId <= 0) {\n    throw new Error(\"Invalid template ID\");\n  }\n  const res = await fetch(`${N8N_TEMPLATES_API}/${safeId.toString()}`);\n  if (!res.ok) throw new Error(`n8n template not found (${res.status})`);\n\n  const contentLength = res.headers.get(\"content-length\");\n  if (contentLength && parseInt(contentLength, 10) > MAX_RESPONSE_BYTES) {\n    throw new Error(\"Response too large.\");\n  }\n\n  const text = await res.text();\n  if (text.length > MAX_RESPONSE_BYTES) throw new Error(\"Response too large.\");\n\n  const data = JSON.parse(text);\n  const template = data?.workflow ?? data;\n  const workflow = template?.workflow ?? template;\n  if (!workflow?.nodes) throw new Error(\"Unexpected n8n API response format\");\n  if (!workflow.name) workflow.name = template?.name ?? data?.name ?? \"\";\n  return JSON.stringify(workflow);\n}\n","sourceCodeStart":55,"sourceCodeEnd":86,"githubUrl":"https://github.com/Significant-Gravitas/AutoGPT/blob/9c8bb5550f446ba5d3046b78896578742495b3cf/autogpt_platform/frontend/src/app/(platform)/library/components/LibraryImportDialog/components/ExternalWorkflowTab/fetchWorkflowFromUrl.ts#L55-L86","documentation":"First of two size guards in fetchN8nWorkflow: before reading the body, it checks the Content-Length response header against MAX_RESPONSE_BYTES and throws 'Response too large.' if the declared size exceeds the cap. This prevents buffering multi-megabyte template payloads. Because Content-Length is optional (absent on chunked/streamed responses), this guard only fires when the server declares a size — the second guard (error 27) covers the rest.","triggerScenarios":"GET to the n8n templates API returning Content-Length > MAX_RESPONSE_BYTES for a template with an unusually large workflow JSON (thousands of nodes, embedded base64 assets).","commonSituations":"Importing a community mega-template; n8n API changing response format (wrapping templates with extra payload) pushing sizes over the cap; MAX_RESPONSE_BYTES tuned down locally.","solutions":["Pick a smaller template — this is a client-side protective cap, and the template genuinely exceeds it.","If you need the template, open it on n8n.io, export the workflow JSON manually, and use the file import path instead of the URL fetch.","Self-hosters can raise MAX_RESPONSE_BYTES in the module if they accept the memory cost.","Check n8n API changes if ALL templates suddenly trip the guard (response envelope grew)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"function withinSizeCap(contentLength: string | null, cap: number): boolean {\n  if (!contentLength) return true; // unknown yet, second guard will decide\n  const n = parseInt(contentLength, 10);\n  return Number.isFinite(n) && n <= cap;\n}","typeGuard":"function isResponseTooLarge(err: unknown): boolean {\n  return err instanceof Error && err.message === \"Response too large.\";\n}","tryCatchPattern":"try {\n  await importFromN8nUrl(url);\n} catch (error) {\n  if (isResponseTooLarge(error)) {\n    toast({ description: \"This template is too large to import automatically — download its JSON and use file import.\" });\n  }\n}","preventionTips":["Always check Content-Length before res.text() when fetching third-party JSON — this code is the pattern to copy.","Keep the file-import path available as the escape hatch for oversized templates.","Don't raise MAX_RESPONSE_BYTES without considering client memory (res.text() buffers the whole body)."],"tags":["n8n","import","content-length","size-limit","frontend"],"backgroundTag":null,"analyzedSha":"9c8bb5550f446ba5d3046b78896578742495b3cf","analyzedAt":"2026-08-14T17:17:21.957Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}