AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Deprecated Prompt Loaders Follow Relative Symlinks Outside The Working Directory, Bypassing Allow_dangerous_paths=False

langchain-core deprecated prompt loading functions (load_prompt and load_prompt_from_config) validate only the path string, not the resolved real path. When allow_dangerous_paths=False, a relative symlink with an accepted suffix can point to a file outside the current working directory and be read, leaking arbitrary .json/.yaml/.txt content.

highConfidence 94%LangChainVector Storeslangchain-coreChat ModelsAffected V1.2.30Affected V1.3.0a2

Origin Analysis

The loading functions open the user-supplied relative path without resolving symlinks. Since allow_dangerous_paths=False only inspects the string, a symlink whose target has an allowed suffix escapes the working directory check. Path canonicalization is missing.
Create a temporary working directory and an outside directory. Place examples.json with secret data outside. Symlink safe/examples.json to outside/examples.json. From safe working directory, call load_prompt_from_config with examples='examples.json' and allow_dangerous_paths=False; the secret is printed. Repeat for template_path and load_prompt('prompt.json') with symlink targets.

Fixing Code Block

Edge Case Audit

The resolution check is subject to a TOCTOU race: an attacker can replace a symlink after validation and before open. For a secure implementation, use file descriptors with O_NOFOLLOW or openat and fstat. The patch also mutates config values to absolute paths for safe loads, which may surprise downstream consumers expecting the original relative string. It intentionally breaks previously symlink-escaped loads; rollback by reverting the diff. Cross-platform differences (Windows junctions, Python 3.8 Path.relative_to) should be tested; langchain-core supports Python 3.9+, but verify before release.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state