Skip to content

Commit d0abe6b

Browse files
committed
fix: Adjust the config file search path for security reasons
1 parent 2680cdc commit d0abe6b

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

text/3502-cargo-script.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,12 @@ fn main() {
370370
println!("Hello world");
371371
}
372372
```
373-
- Like with `cargo install`, `.cargo/config.toml` will be read based on the
374-
scripts location rather than the current-dir.
375-
- And like [`cargo install`](https://github.com/rust-lang/cargo/issues/7312), the current-dir `rust-toolchain.toml` is respected
373+
- In contrast to `cargo run --manifest-path <file>.rs`, `.cargo/config.toml` will not be loaded from the current-dir will instead be loaded from `CARGO_HOME`.
374+
- This is inspired by `cargo install` though its logic is different:
375+
- `cargo install --path <path>` will load config from `<path>`
376+
- All other `cargo install`s will load config from `CARGO_HOME`
377+
- Unlike `cargo install`, we expect people to run single-file packages in unsafe locations, like temp directories or download directories, and don't want to pick up less trustworthy configs
378+
- Like all cargo commands, including `cargo install`, the current-dir `rust-toolchain.toml` is respected ([cargo#7312](https://github.com/rust-lang/cargo/issues/7312))
376379
- `--release` is not passed in because the primary use case is for exploratory
377380
programming, so the emphasis will be on build-time performance and debugging,
378381
rather than runtime performance
@@ -1064,6 +1067,16 @@ This could serve as an alternative to
10641067
[`cargo xtask`](https://github.com/matklad/cargo-xtask) with scripts sharing
10651068
the lockfile and `target/` directory.
10661069

1070+
## Script-relative config
1071+
1072+
As `.cargo/config.toml` is loaded from `CARGO_HOME`, there isn't a way to ensure that we load the config for a script in a repo (e.g. an xtask).
1073+
This could become more of prevalent of an issue when workspaces are supported.
1074+
1075+
Options
1076+
- A way to opt-in saying that the parent directories are assumed to be safe directories (see also [RFC #3279](https://github.com/rust-lang/rfcs/pull/3279)).
1077+
- Key off of workspace membership (as then it won't likely be a temp file)
1078+
- This has a chicken-and-egg problem as we need to load config before we load manifests
1079+
10671080
## Scaling up
10681081

10691082
We provide a workflow for turning a single-file package into a multi-file

0 commit comments

Comments
 (0)