review(mod_whp_symlink): no uninitialised uid in the guard log; document guard gaps; container probes
- guard_filter logged fi.user uninitialised when fstat of the served fd failed (refusal itself was already fail-closed); now -1. - Drop the unused guard_ctx.checked_ok. - Header: state what the fd guard cannot see (no FILE bucket): 304 to a conditional request (confirms a wrong-owner target's ETag, measured), mod_autoindex listings (a swapped public_html still lists the other tenant's directory names with guard On and no WHP <Directory /mnt/users> fix, measured), PHP via FPM. - whp-symlink-module.test.sh: Options inside nested <If>, <ElseIf>, <Else>, <Files>+<If>, <FilesMatch>, <IfModule>/<IfDefine>/<IfVersion>, <Limit>, mod_macro expansion, backslash line continuation; and a tenant .htaccess setting WHPOwnerGuard / WHPHtaccessOptionsRemap (also inside <If>) must 500. 100/100 against the rebuilt image. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
This commit is contained in:
1 parent
31e42ecbc2
commit
1953a176f5
2 files changed
+45
-1
No files matched your search
@@ -73,6 +73,20 @@ ExecCGI
|
|||||||
+Bogus +FollowSymLinks
|
+Bogus +FollowSymLinks
|
||||||
+FollowSymLinks +ExecCGI +Includes
|
+FollowSymLinks +ExecCGI +Includes
|
||||||
EOF
|
EOF
|
||||||
|
# Whole .htaccess bodies (\n = newline): Options inside every container a
|
||||||
|
# tenant may use, mod_macro expansion, line continuation; the module rewrites at
|
||||||
|
# parse time, so each must behave like a top-level line. Directory must work (200).
|
||||||
|
cat > "$T/blocks" <<'EOF'
|
||||||
|
<If "true">\n<If "true">\nOptions FollowSymLinks\n</If>\n</If>
|
||||||
|
<If "false">\n</If>\n<ElseIf "true">\nOptions +FollowSymLinks\n</ElseIf>
|
||||||
|
<If "false">\n</If>\n<Else>\nOptions All\n</Else>
|
||||||
|
<Files *>\n<If "true">\nOptions +FollowSymLinks -SymLinksIfOwnerMatch +ExecCGI\n</If>\n</Files>
|
||||||
|
<FilesMatch ".*">\nOptions +FollowSymLinks +Includes\n</FilesMatch>
|
||||||
|
<IfModule !nope_module>\n<IfDefine !NOPE>\n<IfVersion >= 2.4>\nOptions +FollowSymLinks\n</IfVersion>\n</IfDefine>\n</IfModule>
|
||||||
|
<Limit GET>\nOptions +FollowSymLinks\n</Limit>
|
||||||
|
<Macro WhpT $o>\nOptions $o\n</Macro>\nUse WhpT +FollowSymLinks
|
||||||
|
Options +FollowSymLinks \\\n +ExecCGI
|
||||||
|
EOF
|
||||||
{
|
{
|
||||||
echo 'set -e; A=/mnt/users/a/a.test/public_html; B=/mnt/users/b/b.test/public_html'
|
echo 'set -e; A=/mnt/users/a/a.test/public_html; B=/mnt/users/b/b.test/public_html'
|
||||||
echo 'mkdir -p $A $B /mnt/users/a/a2.test; echo B-SECRET > $B/secret.txt; ln -s $B /mnt/users/a/a2.test/public_html'
|
echo 'mkdir -p $A $B /mnt/users/a/a2.test; echo B-SECRET > $B/secret.txt; ln -s $B /mnt/users/a/a2.test/public_html'
|
||||||
@@ -85,6 +99,18 @@ EOF
|
|||||||
printf "printf 'S<!--#exec cmd=\"id\" -->E\\\\n' > %s/p.shtml; printf '#!/bin/sh\\\\necho Content-type: text/plain\\\\necho\\\\nid\\\\n' > %s/p.cgi; chmod 755 %s/p.cgi\n" "$d" "$d" "$d"
|
printf "printf 'S<!--#exec cmd=\"id\" -->E\\\\n' > %s/p.shtml; printf '#!/bin/sh\\\\necho Content-type: text/plain\\\\necho\\\\nid\\\\n' > %s/p.cgi; chmod 755 %s/p.cgi\n" "$d" "$d" "$d"
|
||||||
done < "$T/lines"
|
done < "$T/lines"
|
||||||
echo "echo $n > /ntests"
|
echo "echo $n > /ntests"
|
||||||
|
n=0
|
||||||
|
while IFS= read -r blk; do
|
||||||
|
n=$((n+1)); d="\$A/b$n"
|
||||||
|
printf 'mkdir -p %s; printf %%s %q > %s/.line\n' "$d" "$blk" "$d"
|
||||||
|
printf "printf '%%b\\\\nAddOutputFilter INCLUDES .shtml\\\\nAddHandler cgi-script .cgi\\\\n' %q > %s/.htaccess\n" "$blk" "$d"
|
||||||
|
printf 'echo OWN > %s/own.txt; ln -s $B/secret.txt %s/steal.txt\n' "$d" "$d"
|
||||||
|
printf "printf 'S<!--#exec cmd=\"id\" -->E\\\\n' > %s/p.shtml; printf '#!/bin/sh\\\\necho Content-type: text/plain\\\\necho\\\\nid\\\\n' > %s/p.cgi; chmod 755 %s/p.cgi\n" "$d" "$d" "$d"
|
||||||
|
done < "$T/blocks"
|
||||||
|
echo "echo $n > /nblocks"
|
||||||
|
# a tenant must not be able to switch the module off
|
||||||
|
echo 'mkdir -p $A/g1 $A/g2; echo OWN > $A/g1/own.txt; echo OWN > $A/g2/own.txt'
|
||||||
|
echo 'printf "WHPOwnerGuard Off\n" > $A/g1/.htaccess; printf "<If \"true\">\nWHPHtaccessOptionsRemap Off\n</If>\n" > $A/g2/.htaccess'
|
||||||
echo 'chmod -R a+rX /mnt/users; chown -R -h 1006:1006 /mnt/users/a; chown -R -h 1003:1003 /mnt/users/b'
|
echo 'chmod -R a+rX /mnt/users; chown -R -h 1006:1006 /mnt/users/a; chown -R -h 1003:1003 /mnt/users/b'
|
||||||
} > "$T/fx.sh"
|
} > "$T/fx.sh"
|
||||||
|
|
||||||
@@ -109,6 +135,17 @@ for i in $(seq 1 "$N"); do
|
|||||||
+FollowSymlinks|FollowSymLinks|All|+All) o=$(get a.test /t$i/own.txt); [ "${o:0:3}" = 200 ] && ok "Options $line: directory works (200)" || bad "Options $line: own file ${o:0:3}" ;;
|
+FollowSymlinks|FollowSymLinks|All|+All) o=$(get a.test /t$i/own.txt); [ "${o:0:3}" = 200 ] && ok "Options $line: directory works (200)" || bad "Options $line: own file ${o:0:3}" ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
N=$(docker exec "$NAME" cat /nblocks)
|
||||||
|
for i in $(seq 1 "$N"); do
|
||||||
|
blk="$(docker exec "$NAME" cat /mnt/users/a/a.test/public_html/b$i/.line)"
|
||||||
|
st=$(get a.test /b$i/steal.txt); x=$(get a.test /b$i/p.shtml); c=$(get a.test /b$i/p.cgi); o=$(get a.test /b$i/own.txt)
|
||||||
|
case "$st" in *B-SECRET*) bad "block $blk: cross-tenant symlink read" ;; *) ok "block $blk: no cross-tenant read (${st:0:3})" ;; esac
|
||||||
|
case "$x$c" in *uid=*) bad "block $blk: code executed" ;; *) ok "block $blk: no exec" ;; esac
|
||||||
|
[ "${o:0:3}" = 200 ] && ok "block $blk: directory works (200)" || bad "block $blk: own file ${o:0:3}"
|
||||||
|
done
|
||||||
|
for g in g1 g2; do
|
||||||
|
o=$(get a.test /$g/own.txt); [ "${o:0:3}" = 500 ] && ok "tenant cannot set module directives ($g: 500)" || bad "tenant module directive accepted ($g: ${o:0:3})"
|
||||||
|
done
|
||||||
r=$(get a2.test /secret.txt)
|
r=$(get a2.test /secret.txt)
|
||||||
case "$r" in *B-SECRET*) bad "swapped public_html served another tenant's file" ;; *) ok "swapped public_html refused (${r:0:3})" ;; esac
|
case "$r" in *B-SECRET*) bad "swapped public_html served another tenant's file" ;; *) ok "swapped public_html refused (${r:0:3})" ;; esac
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,12 @@
|
|||||||
* mismatch is logged and (On) answered 404, like the Bluehost patch.
|
* mismatch is logged and (On) answered 404, like the Bluehost patch.
|
||||||
* Closes the check-then-open symlink race of SymLinksIfOwnerMatch for
|
* Closes the check-then-open symlink race of SymLinksIfOwnerMatch for
|
||||||
* static files (and any other handler that sends FILE buckets).
|
* static files (and any other handler that sends FILE buckets).
|
||||||
|
* Not covered, because no FILE bucket is sent: a 304 Not Modified to a
|
||||||
|
* conditional request (its ETag/Last-Modified come from the walk-time
|
||||||
|
* stat, so a wrong-owner target is confirmed, not read), mod_autoindex
|
||||||
|
* listings (names only), and PHP (read by the tenant's own FPM). The
|
||||||
|
* swapped-public_html listing needs WHP's <Directory "/mnt/users">
|
||||||
|
* Options SymLinksIfOwnerMatch; the guard alone does not close it.
|
||||||
*
|
*
|
||||||
* 3. WHPSymlinkWalk Off|Log|On (+ WHPOwnerGuardRoot <prefix>)
|
* 3. WHPSymlinkWalk Off|Log|On (+ WHPOwnerGuardRoot <prefix>)
|
||||||
* Prototype of "re-implement SymLinksIfOwnerMatch after the walk": a
|
* Prototype of "re-implement SymLinksIfOwnerMatch after the walk": a
|
||||||
@@ -315,7 +321,6 @@ static int under_root(const whp_dir_conf *dc, const char *f)
|
|||||||
/* 2. Owner guard on the served file descriptor */
|
/* 2. Owner guard on the served file descriptor */
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int checked_ok;
|
|
||||||
uid_t owner;
|
uid_t owner;
|
||||||
int have_owner;
|
int have_owner;
|
||||||
} guard_ctx;
|
} guard_ctx;
|
||||||
@@ -353,6 +358,8 @@ static apr_status_t guard_filter(ap_filter_t *f, apr_bucket_brigade *bb)
|
|||||||
if (!APR_BUCKET_IS_FILE(b))
|
if (!APR_BUCKET_IS_FILE(b))
|
||||||
continue;
|
continue;
|
||||||
fb = b->data;
|
fb = b->data;
|
||||||
|
/* logged below even when fstat fails: never print stack garbage */
|
||||||
|
fi.user = (apr_uid_t)-1;
|
||||||
if (apr_file_info_get(&fi, APR_FINFO_USER, fb->fd) != APR_SUCCESS
|
if (apr_file_info_get(&fi, APR_FINFO_USER, fb->fd) != APR_SUCCESS
|
||||||
|| !ctx->have_owner || fi.user != ctx->owner) {
|
|| !ctx->have_owner || fi.user != ctx->owner) {
|
||||||
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
|
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
|
||||||
|
|||||||
Reference in new issue
Block a user