Skip to content

Commit e966aa7

Browse files
committed
Add documentation for safe.directories.
1 parent 25a21df commit e966aa7

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/doc/src/reference/unstable.md

+30-1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ Each new feature described below should explain how to use it.
103103
* [credential-process](#credential-process) — Adds support for fetching registry tokens from an external authentication program.
104104
* [`cargo logout`](#cargo-logout) — Adds the `logout` command to remove the currently saved registry token.
105105
* [http-registry](#http-registry) — Adds support for fetching from http registries (`sparse+`)
106+
* Misc
107+
* [safe-directories](#safe-directories) — Adds a security check for file discovery.
106108

107109
### allow-features
108110

@@ -1417,6 +1419,33 @@ dep-dev.workspace = true
14171419
[specifying-dependencies]: specifying-dependencies.md
14181420
[renaming-dependencies-in-cargotoml]: specifying-dependencies.md#renaming-dependencies-in-cargotoml
14191421

1422+
### safe-directories
1423+
* Tracking Issue: TODO
1424+
* RFC: [#3279](https://github.com/rust-lang/rfcs/pull/3279)
1425+
1426+
The `CARGO_UNSTABLE_SAFE_DIRECTORIES=true` environment variable enables a mode where Cargo will check the ownership of `Cargo.toml` and `config.toml` files.
1427+
If the files are owned by a user different from the current user,
1428+
then Cargo will generate an error.
1429+
This is a security mechanism to ensure that a malicious user doesn't add one of those files in a parent directory of wherever you run `cargo`.
1430+
See the RFC for more details.
1431+
1432+
The ownership check can be overridden with the `safe.directories` configuration setting.
1433+
This is an array of paths that you explicitly trust even if they are owned by another user.
1434+
1435+
```toml
1436+
[safe]
1437+
directories = ["/path/to/project"]
1438+
```
1439+
1440+
This config setting may only be set in the [Cargo home directory](../guide/cargo-home.md).
1441+
Other file locations are not allowed.
1442+
1443+
This config option can also be set with the `CARGO_SAFE_DIRECTORIES` or `RUSTUP_SAFE_DIRECTORIES` environment variables.
1444+
Multiple paths may be separated with `:` on Unix-like environments or `;` for Windows environments.
1445+
1446+
An entry of an asterisk (such as `CARGO_SAFE_DIRECTORIES=*`) entirely disables the ownership check for all paths.
1447+
1448+
14201449
## Stabilized and removed features
14211450

14221451
### Compile progress
@@ -1597,4 +1626,4 @@ See the [Features chapter](features.md#dependency-features) for more information
15971626

15981627
The `-Ztimings` option has been stabilized as `--timings` in the 1.60 release.
15991628
(`--timings=html` and the machine-readable `--timings=json` output remain
1600-
unstable and require `-Zunstable-options`.)
1629+
unstable and require `-Zunstable-options`.)

0 commit comments

Comments
 (0)