{"record":{"id":"35f5bc9b0b9b7c7a","repo":"Fission-AI/OpenSpec","slug":"path-is-outside-the-allowed-directory-targetpat","errorCode":null,"errorMessage":"Path is outside the allowed directory: ${targetPath}","messagePattern":"Path is outside the allowed directory: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/utils/file-system.ts","lineNumber":117,"sourceCode":"      try {\n        return nodeFs.realpathSync(targetPath);\n      } catch {\n        return path.resolve(targetPath);\n      }\n    }\n  }\n\n  /**\n   * Refuses a target that leaves an allowed directory, including through an\n   * existing symlink in either the target or one of its parent directories.\n   * Missing suffixes are resolved from their nearest existing ancestor.\n   */\n  static assertPathWithin(allowedDirectory: string, targetPath: string): void {\n    const resolvedDirectory = path.resolve(allowedDirectory);\n    const resolvedTarget = path.resolve(targetPath);\n\n    if (!this.isPathWithin(resolvedDirectory, resolvedTarget)) {\n      throw new Error(`Path is outside the allowed directory: ${targetPath}`);\n    }\n\n    const canonicalDirectory = this.canonicalizePotentialPath(resolvedDirectory);\n    const canonicalTarget = this.canonicalizePotentialPath(resolvedTarget);\n    if (!this.isPathWithin(canonicalDirectory, canonicalTarget)) {\n      throw new Error(`Path is outside the allowed directory: ${targetPath}`);\n    }\n  }\n\n  static resolveProjectArtifactPath(projectPath: string, artifactPath: string): string {\n    if (path.isAbsolute(artifactPath)) {\n      throw new Error(`Refusing to manage an artifact outside the project: ${artifactPath}`);\n    }\n\n    const targetPath = path.join(projectPath, artifactPath);\n    this.assertPathWithin(projectPath, targetPath);\n    return targetPath;\n  }","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/Fission-AI/OpenSpec/blob/6926ccb18afa4ff621112813e9968334576ee11a/src/utils/file-system.ts#L99-L135","documentation":"Error \"Path is outside the allowed directory: ${targetPath}\" thrown in Fission-AI/OpenSpec.","triggerScenarios":"Thrown at src/utils/file-system.ts:117 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":"6926ccb18afa4ff621112813e9968334576ee11a","analyzedAt":"2026-08-25T12:29:45.729Z","schemaVersion":2},"datasetVersion":"2026-08-25T16:17:27.014Z"}