DRAFT: shared-httpd mod_whp_symlink (.htaccess Options remap + served-file owner guard) #60
No files matched your search
@@ -73,6 +73,20 @@ ExecCGI
|
||||
+Bogus +FollowSymLinks
|
||||
+FollowSymLinks +ExecCGI +Includes
|
||||
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 '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"
|
||||
done < "$T/lines"
|
||||
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'
|
||||
} > "$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}" ;;
|
||||
esac
|
||||
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)
|
||||
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.
|
||||
* Closes the check-then-open symlink race of SymLinksIfOwnerMatch for
|
||||
* 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>)
|
||||
* 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 */
|
||||
|
||||
typedef struct {
|
||||
int checked_ok;
|
||||
uid_t owner;
|
||||
int have_owner;
|
||||
} 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))
|
||||
continue;
|
||||
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
|
||||
|| !ctx->have_owner || fi.user != ctx->owner) {
|
||||
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
|
||||
|
||||
Reference in new issue
Block a user