{"record":{"id":"9fb8d0ee4112b969","repo":"Fission-AI/OpenSpec","slug":"refusing-to-manage-an-artifact-outside-the-project","errorCode":null,"errorMessage":"Refusing to manage an artifact outside the project: ${artifactPath}","messagePattern":"Refusing to manage an artifact outside the project: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/utils/file-system.ts","lineNumber":129,"sourceCode":"   */\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  }\n\n  static assertProjectArtifactPath(projectPath: string, targetPath: string): void {\n    this.assertPathWithin(projectPath, targetPath);\n  }\n\n  private static isPathWithin(allowedDirectory: string, targetPath: string): boolean {\n    const relative = path.relative(allowedDirectory, targetPath);\n    return (\n      relative === '' ||\n      (relative !== '..' &&\n        !relative.startsWith(`..${path.sep}`) &&\n        !path.isAbsolute(relative))","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/Fission-AI/OpenSpec/blob/6926ccb18afa4ff621112813e9968334576ee11a/src/utils/file-system.ts#L111-L147","documentation":"Thrown by assertPathWithin's second, canonicalized check when the target stays inside the allowed directory textually but escapes it after resolving symlinks (realpath). The guard refuses to manage project artifacts that canonically live outside the project.","triggerScenarios":"Thrown at src/utils/file-system.ts:129 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Remove or repoint symlinks in the target path that escape the project","Use a real path inside the project directory"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"6926ccb18afa4ff621112813e9968334576ee11a","analyzedAt":"2026-08-25T12:29:45.729Z","contentChangedAt":"2026-08-25T12:29:45.729Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}