{"record":{"id":"404a2aca15c2849d","repo":"Kong/insomnia","slug":"writeresponsebodytofile-sourcepath-is-outside-the","errorCode":null,"errorMessage":"writeResponseBodyToFile: sourcePath is outside the allowed responses directory or does not end in .response","messagePattern":"writeResponseBodyToFile: sourcePath is outside the allowed responses directory or does not end in \\.response","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/insomnia/src/main/ipc/main.ts","lineNumber":159,"sourceCode":"        };\n      })\n      .filter(file => file.type !== 'other');\n  } catch (err) {\n    throw new Error(`Failed to read directory: ${err}`);\n  }\n};\n\nconst writeResponseBodyToFile = async (\n  _: unknown,\n  options: { sourcePath: string; destinationPath: string; bodyCompression?: 'zip' | null },\n) => {\n  // Validate sourcePath is within the expected responses directory to prevent a\n  // compromised renderer from using this handler to read arbitrary files on disk.\n  const userdataDirectory = process.env.INSOMNIA_DATA_PATH || app.getPath('userData');\n  const allowedResponsesDir = path.join(userdataDirectory, 'responses');\n  const resolvedSource = path.resolve(options.sourcePath);\n  if (!resolvedSource.startsWith(allowedResponsesDir + path.sep) || !resolvedSource.endsWith('.response')) {\n    throw new Error(\n      'writeResponseBodyToFile: sourcePath is outside the allowed responses directory or does not end in .response',\n    );\n  }\n\n  try {\n    const dir = path.dirname(options.destinationPath);\n    await fs.promises.mkdir(dir, { recursive: true });\n\n    await (options.bodyCompression === 'zip'\n      ? pipeline(\n          fs.createReadStream(options.sourcePath),\n          zlib.createGunzip(),\n          fs.createWriteStream(options.destinationPath),\n        )\n      : fs.promises.copyFile(options.sourcePath, options.destinationPath));\n\n    return options.destinationPath;\n  } catch (err) {","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/Kong/insomnia/blob/d9bb2b0142600f21309832daea3317942d285984/packages/insomnia/src/main/ipc/main.ts#L141-L177","documentation":"Error \"writeResponseBodyToFile: sourcePath is outside the allowed responses directory or does not end in .response\" thrown in Kong/insomnia.","triggerScenarios":"Thrown at packages/insomnia/src/main/ipc/main.ts:159 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"d9bb2b0142600f21309832daea3317942d285984","analyzedAt":"2026-08-26T18:04:05.187Z","schemaVersion":2},"datasetVersion":"2026-08-26T21:11:00.512Z"}