Skip to main content

SKY-D415 · Security in code

Unix permission value grants write access to all users

MediumCWE-732

Calling std::fs::Permissions::set_readonly(false) sets the Unix write bits for the owner, group and others. Applying the resulting permissions can make the file writable by other users.

Languages
Rust
Quality gate
listed, not counted by the gate (full and diff scans). The advisory stays visible and does not fail the security gate.
Finding type
review
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

A program restoring write access for its own account may grant access to other accounts that can reach the file.

What Skylos flags

src/lib.rs · RustReported on line 3
use std::fs::Permissions;fn enable_writes(perms: &mut Permissions) {    perms.set_readonly(false);}

What Skylos leaves alone

src/lib.rs · Rust
#[cfg(unix)]fn enable_writes(perms: &mut std::fs::Permissions) {    use std::os::unix::fs::PermissionsExt;    perms.set_mode(perms.mode() | 0o200);}

Why Skylos leaves it alone

The code adds write access for the owner while retaining the other bits.

How Skylos decides

  1. Resolves the standard-library type or associated function, including imported aliases, typed parameters and permissions obtained from standard filesystem metadata. The argument must be the literal false.
  2. Checks code that can run on Unix and skips recognized Windows-only guards. The advisory describes the permission value. Writing it to disk requires a separate operation that the finding does not establish.

How to fix it

On Unix, select the accounts that should receive write access by using an explicit mode or named flags.

src/lib.rs · Rust · the fix, against the flagged file
Removed: use std::fs::Permissions;Removed: fn enable_writes(perms: &mut Permissions) {Removed:     perms.set_readonly(false);Added: #[cfg(unix)]Added: fn enable_writes(perms: &mut std::fs::Permissions) {Added:     use std::os::unix::fs::PermissionsExt;Added:     perms.set_mode(perms.mode() | 0o200);}

When it can be wrong

  • A program may intentionally create shared writable files, or discard the modified permissions without applying them.

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • Add a Skylos ignore comment to a reviewed call that intentionally grants write access to every account.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.