{"record":{"id":"19b2395317182214","repo":"Mintplex-Labs/anything-llm","slug":"access-denied-path-outside-allowed-directories","errorCode":null,"errorMessage":"Access denied - path outside allowed directories.","messagePattern":"Access denied - path outside allowed directories\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/agents/aibitat/plugins/filesystem/lib.js","lineNumber":429,"sourceCode":"   */\n  async validatePath(requestedPath) {\n    await this.ensureInitialized();\n    const expandedPath = this.#expandHome(requestedPath);\n    const absolute = path.isAbsolute(expandedPath)\n      ? path.resolve(expandedPath)\n      : this.#resolveRelativePathAgainstAllowedDirectories(expandedPath);\n\n    const normalizedRequested = this.#normalizePath(absolute);\n\n    const isAllowed = this.#isPathWithinAllowedDirectories(\n      normalizedRequested,\n      this.#allowedDirectories\n    );\n    if (!isAllowed) {\n      console.log(\n        `[validatePath] Access denied - path outside allowed directories: ${absolute} not in ${this.#allowedDirectories.join(\", \")}`\n      );\n      throw new Error(`Access denied - path outside allowed directories.`);\n    }\n\n    try {\n      const realPath = await fs.realpath(absolute);\n      const normalizedReal = this.#normalizePath(realPath);\n      if (\n        !this.#isPathWithinAllowedDirectories(\n          normalizedReal,\n          this.#allowedDirectories\n        )\n      ) {\n        console.log(\n          `[validatePath] Access denied - symlink target outside allowed directories: ${realPath} not in ${this.#allowedDirectories.join(\", \")}`\n        );\n        throw new Error(\n          `Access denied - symlink target outside allowed directories.`\n        );\n      }","sourceCodeStart":411,"sourceCodeEnd":447,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/agents/aibitat/plugins/filesystem/lib.js#L411-L447","documentation":"Thrown by Filesystem.validatePath() when the requested path, after home-expansion and normalization, does not resolve within any allowed directory. This is the primary sandbox boundary check that confines all filesystem tool access to the configured workspace. The detailed offending path and allowed dirs are logged to the console but not exposed in the error message.","triggerScenarios":"Passing an absolute path outside the workspace (e.g., /etc/passwd), a relative path that resolves outside via ../ traversal, or a path whose normalized form falls outside every allowed directory entry. Any filesystem tool call routes through validatePath first.","commonSituations":"An absolute path like /tmp/x when only the workspace is allowed; ../ sequences escaping the workspace root; a misconfiguration where allowedDirectories does not include the intended working area.","solutions":["Use paths relative to the workspace root, or absolute paths confirmed to be inside an allowed directory.","Avoid ../ sequences that escape the workspace.","Check filesystem.getAllowedDirectories() to see what roots are permitted.","If a legitimate directory is excluded, configure it as an allowed directory before use."],"exampleFix":"// before - absolute path outside workspace\nawait filesystem.readFileContent(\"/etc/passwd\");\n// after - path inside the allowed workspace\nawait filesystem.readFileContent(\"workspace/config.txt\");","handlingStrategy":"validation","validationCode":"// resolve and check against allowed dirs before calling any filesystem tool\nfunction isWithinAllowed(p, allowedDirs) {\n  const resolved = path.resolve(p);\n  return allowedDirs.some((d) => resolved === path.resolve(d) || resolved.startsWith(path.resolve(d) + path.sep));\n}\nif (!isWithinAllowed(requestedPath, filesystem.getAllowedDirectories()))\n  throw new Error(\"Path outside workspace\");","typeGuard":null,"tryCatchPattern":"try {\n  const valid = await filesystem.validatePath(p);\n} catch (e) {\n  if (e.message.includes(\"outside allowed directories\")) { /* use a workspace-relative path */ }\n  else throw e;\n}","preventionTips":["Always use workspace-relative paths when calling filesystem tools.","Avoid ../ sequences that escape the workspace root.","Check getAllowedDirectories() when unsure which roots are permitted."],"tags":["filesystem","security","sandbox","path-validation"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}