Skip to content

Don't follow symlinks when writing htop_history#1945

Open
Explorer09 wants to merge 1 commit intohtop-dev:mainfrom
Explorer09:history-nofollow
Open

Don't follow symlinks when writing htop_history#1945
Explorer09 wants to merge 1 commit intohtop-dev:mainfrom
Explorer09:history-nofollow

Conversation

@Explorer09
Copy link
Copy Markdown
Contributor

@Explorer09 Explorer09 commented Apr 6, 2026

Prevent a symlink attack that allows an attacker to empty any file a user has write permission to.

@Explorer09 Explorer09 force-pushed the history-nofollow branch 2 times, most recently from 634f8d0 to 17c1609 Compare April 6, 2026 09:54
@fasterit
Copy link
Copy Markdown
Member

fasterit commented Apr 6, 2026

What is a realistic attack scenario here?

@Explorer09
Copy link
Copy Markdown
Contributor Author

What is a realistic attack scenario here?

The attack is possible when the directory that the htoprc file resides is writable by the public or a local group. Then, suppose Mallory has write access to the directory, and he ln -s /home/alice/some_important_data htop_history to create a symlink. He can then wait for Alice to load that htoprc file and get hit.

If Alice runs htop with sudo privilege, things can get worse. I think you can get the idea.

@fasterit
Copy link
Copy Markdown
Member

fasterit commented Apr 6, 2026

The same is true for htoprc.

$ htop
Configuration /home/daniel/.config/htop/htoprc was resolved to /etc/passwd
Cannot save configuration to /etc/passwd: Permission denied

@Explorer09
Copy link
Copy Markdown
Contributor Author

The same is true for htoprc.

$ htop
Configuration /home/daniel/.config/htop/htoprc was resolved to /etc/passwd
Cannot save configuration to /etc/passwd: Permission denied

Gee. You motivated me to write this: #1947

@Explorer09 Explorer09 force-pushed the history-nofollow branch 2 times, most recently from 1d87942 to 6cc06f7 Compare April 7, 2026 11:07
@Explorer09
Copy link
Copy Markdown
Contributor Author

For your info, the Settings_resolveSymlink function I introduced in #1947 can be easily adapted to work with htop_history file, too. If you people want it.
(The function adds a simple safeguard for symbolic links by checking the ownership of the link. It follows the symlink only if the link is owned by either root or the EUID running the htop instance.)

Prevent a symlink attack that allows an attacker to empty any file a
user has write permission to.

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants