Auto-loaded .c2pconfig path key overrides the caller-specified root, redirecting file reads

Open Beginner friendly
#355 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
cli, security

Research direction

Start in config_loader::load_config, where .c2pconfig is auto-loaded from the working directory, then follow the value into config::build_session to see where the config path wins over the CLI path argument. Reproduce first: create a directory with a .c2pconfig setting path to another dir, run the command with an explicit path, and confirm the wrong directory is scanned. After flipping the precedence so CLI wins, check the config and CLI parsing tests and add a case covering an explicit path plus an auto-loaded config. Done means the explicit path argument is used and the reproduction no longer emits the other directory's contents.

Written by the indexing model from the issue text.

Description

Summary

Configuration injection in code2prompt: config_loader::load_config auto-loads .c2pconfig from the current working directory. In config::build_session the config path takes precedence over the CLI path argument, so untrusted repo content can silently redirect the scan to an arbitrary local directory.

To reproduce

Create a repo containing .c2pconfig with 'path = ""' and default_output = "stdout", then run 'code2prompt -q -O - ' from that repo. The explicit path is ignored.

Expected

CLI path argument should override the config path per documented precedence.

Actual

The config-redirected directory was scanned and its marker emitted

Independent CLI reproduction confirmed that an auto-loaded .c2pconfig 'path' key overrides an explicit CLI path argument: running 'code2prompt -q -O - /tmp/other' from a directory whose .c2pconfig sets path= emitted the secret-dir marker and not the requested directory, contradicting the documented 'CLI Arguments > Configuration File' precedence.

Observed side effect:

Project Path: v3-secret-1795224564

Source Tree:

```txt
v3-secret-1795224564
└── marker.txt

marker.txt:

CONFIG_LEAKED_SECRET_98765_VERIFY_2026_MARKER


## Impact

Arbitrary local directory read redirection to the caller/LLM context via malicious repo content.

## Version

v4.2.0
Dominant language
Rust
Stars
7.8k
Forks
459
Avg merge
3d 20h
Merged PRs (30d)
1

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from mufeedvh/code2prompt

All issues in mufeedvh/code2prompt

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.