Course contentsShow
← Linux
Lesson 356 of 1,8194. Advanced Access Control ModelsFree lesson

Security Risks of Improper World-Writable Directories

Identify the vector of attacks facilitated by insecure directory access and mitigate using restricted flags.

In this lesson, you will learn how world-writable directories create security vulnerabilities and how to mitigate them using the "sticky bit."

The Danger of World-Writable Directories

In the Linux UGO (User, Group, Other) model, a directory that is "world-writable" (permissions like 777) allows any user on the system to add, rename, or delete files within that folder, regardless of who owns those files.

While this sounds like a great way to facilitate sharing, it is a significant security risk. If a directory is world-writable, a malicious user can delete critical files created by others or replace legitimate files with malicious scripts or symlinks. Imagine a shared /tmp directory: without protection, any user could delete a temporary file being used by another process, potentially causing a system crash or a denial-of-service attack.

Securing Directories with the Sticky Bit

To mitigate this, we use a special flag called the sticky bit. When applied to a directory, it restricts the deletion or renaming of files to only the file owner, the directory owner, or the root user. Even if the directory remains world-writable, users can no longer delete each other's work.

You can set this bit using the chmod command with the special +t flag:

# Add the sticky bit to a shared directory
chmod +t /shared_folder

# Or using the octal representation (1 represents the sticky bit)
chmod 1777 /shared_folder

When you list a directory with the sticky bit set using ls -ld, you will see a t at the end of the permissions string:

drwxrwxrwt 2 root root 4096 May 20 10:00 /shared_folder

The t (instead of an x) indicates that the sticky bit is active. This simple configuration is why standard directories like /tmp are inherently more secure; they allow everyone to write, but ensure that users cannot interfere with one another’s data.

Key Takeaway: The sticky bit is an essential access control mechanism that prevents users from deleting or renaming files they do not own, effectively neutralizing the primary attack vectors associated with world-writable directories.