security: close log-guard symlink race (O_EXCL create, -type f chown, delete links)

This commit is contained in:
inference-admin committed 2026-11-19 23:44:11 +00:00
1 parent 225107006a
commit 02b9c1ad3e
1 file changed
+10 -3
+10 -3
View File
@@ -24,10 +24,17 @@ while true; do
[ -z "$d" ] && continue [ -z "$d" ] && continue
for prefix in error meiliSync; do for prefix in error meiliSync; do
f="$LOGDIR/${prefix}-${d}.log" f="$LOGDIR/${prefix}-${d}.log"
[ -e "$f" ] || : > "$f" # Create with O_EXCL and never follow a symlink: a `cloudron` process
# that wins the race with a symlink must not make root truncate a
# file outside the log directory.
if [ ! -e "$f" ] && [ ! -L "$f" ]; then
( set -C; : > "$f" ) 2>/dev/null || true
fi
done done
done done
# Repair any root-owned strays (covers unknown file prefixes too). # Refuse symlinks outright (delete them), then repair regular-file
find "$LOGDIR" ! -user cloudron -exec chown cloudron:cloudron {} \; 2>/dev/null # ownership only — chown must not follow a link swapped in by cloudron.
find "$LOGDIR" -type l -delete 2>/dev/null
find "$LOGDIR" -type f ! -user cloudron -exec chown cloudron:cloudron {} + 2>/dev/null
sleep 60 sleep 60
done done