Skip to content

Commit 8808d5a

Browse files
committed
std(docs): clarify how std::fs::set_permisions works with symlinks
fixes #75942 fixes #124201
1 parent ae9173d commit 8808d5a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

library/std/src/fs.rs

+13
Original file line numberDiff line numberDiff line change
@@ -2980,6 +2980,19 @@ pub fn read_dir<P: AsRef<Path>>(path: P) -> io::Result<ReadDir> {
29802980
///
29812981
/// [changes]: io#platform-specific-behavior
29822982
///
2983+
/// # Symlinks
2984+
/// On UNIX systems, it is impossible to manipulate the permission bits of a symlink itself[^1].
2985+
/// Because of this, on those systems, this function will update the permission bits
2986+
/// of the file pointed to by the symlink.
2987+
///
2988+
/// Note that this behavior can lead to privalage escalation vulnerabilites,
2989+
/// where the ability to write a symlink in one directory allows you to
2990+
/// cause the permissions of another directory to be modified.
2991+
///
2992+
/// For this reason, using this function with symlinks should be avoided.
2993+
/// When possible, permissions should be set at creation time instead.
2994+
///
2995+
/// [^1]: even if it were possible, the permissions on a symlink are ignored.
29832996
/// # Errors
29842997
///
29852998
/// This function will return an error in the following situations, but is not

0 commit comments

Comments
 (0)