Skip to content

fix: enforce POSIX sticky bit on unlink/rmdir/rename#369

Draft
toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
toddr-bot:koan.toddr.bot/enforce-sticky-bit-unlink-rename
Draft

fix: enforce POSIX sticky bit on unlink/rmdir/rename#369
toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
toddr-bot:koan.toddr.bot/enforce-sticky-bit-unlink-rename

Conversation

@toddr-bot
Copy link
Copy Markdown
Collaborator

@toddr-bot toddr-bot commented Apr 11, 2026

What

Enforce sticky bit (S_ISVTX / 01000) restrictions on unlink(), rmdir(), and rename() when set_user() is active.

Why

POSIX requires that directories with the sticky bit (e.g., /tmp mode 1777) restrict deletion/renaming to the file owner, directory owner, or root. Without this check, any user with write permission on a sticky directory can remove other users' files — breaking the security model that set_user() is designed to test.

How

  • Added S_ISVTX constant (01000) alongside existing S_IF* constants
  • Added _check_sticky_bit($parent_path, $file_path) helper: checks if parent dir has sticky bit, and if so, verifies the mock user is the file owner, dir owner, or root
  • Integrated into __unlink, __rmdir, and __rename (both source and destination parent dirs for rename)

Testing

  • 11 new tests in t/sticky_bit.t covering:
    • Non-owner blocked from unlink/rmdir/rename in sticky dir (EACCES)
    • File owner, directory owner, and root all allowed
    • Non-sticky directory still permits any writer to delete
    • Cross-directory rename with sticky destination
  • Full test suite passes (1597 tests, only pre-existing fh-ref-leak.t failure)

🤖 Generated with Claude Code


Quality Report

Changes: 2 files changed, 235 insertions(+)

Code scan: clean

Tests: failed (4 Failed, 95 test)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

POSIX requires that when a directory has the sticky bit set (mode 01000,
e.g. /tmp with mode 1777), only the file owner, directory owner, or root
can delete or rename entries. Without this check, any user with write
permission on the directory could remove other users' files.

Adds S_ISVTX constant, _check_sticky_bit() helper, and enforcement in
__unlink, __rmdir, and __rename (both source and destination dirs).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.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.

1 participant