fix(mod_whp_symlink): deny-by-default Options remap, refuse quoted lines; add probe test
Security review (2 HIGH): - Incomplete remap: only bare `All` was handled; `+All`/`-All`, `None +X`, `RunScripts` etc. passed through. The remap now matches every word against the full core keyword list and emits only known-safe names (prefix kept, core +/- mixing rules respected): any symlink-follow form -> SymLinksIfOwnerMatch, any exec-SSI form -> IncludesNOEXEC (only if allowed, else dropped), positive ExecCGI dropped, unknown words dropped. The line is always replaced by the normalised form, so the core never sees input words. - Parser differential: ap_getword_conf() unquotes, and the re-joined line was re-tokenised by the core. A line containing quote or backslash characters is now refused (config error -> 500, nothing enabled); emitted tokens are fixed keywords, so the join is unambiguous. scripts/tests/whp-symlink-module.test.sh probes 29 Options forms (+All, -All, All mixed with +/-, case and FollowSymlinks spelling variants, quoted, escaped, tab-separated) for cross-tenant symlink reads, SSI/CGI exec, refusal of quoted lines, and the swapped public_html owner guard. 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
5fbc2e315e
commit
31e42ecbc2
2 files changed
+211
-36
No files matched your search
Executable
+116
@@ -0,0 +1,116 @@
|
||||
#!/usr/bin/env bash
|
||||
## whp-symlink-module.test.sh - live probes for src/mod_whp_symlink against a built
|
||||
## shared-httpd image: no .htaccess Options form may re-enable un-owner-checked
|
||||
## symlinks, exec-SSI or CGI; quoted/escaped Options lines are refused; stock CMS
|
||||
## shapes (`Options +FollowSymlinks`) no longer answer 500; the owner guard refuses
|
||||
## a swapped public_html.
|
||||
## whp-symlink-module.test.sh [image] (default shared-httpd:latest)
|
||||
## SKIPs (exit 0) without docker or the image.
|
||||
set -u
|
||||
IMAGE="${1:-shared-httpd:latest}"
|
||||
NAME="whp-symtest-$$"; T="$(mktemp -d)"
|
||||
trap 'docker rm -f "$NAME" >/dev/null 2>&1; rm -rf "$T"' EXIT
|
||||
command -v docker >/dev/null 2>&1 || { echo "SKIP: no docker"; exit 0; }
|
||||
docker image inspect "$IMAGE" >/dev/null 2>&1 || { echo "SKIP: no image $IMAGE"; exit 0; }
|
||||
fail=0; pass=0
|
||||
ok() { pass=$((pass+1)); echo "ok $*"; }
|
||||
bad() { fail=$((fail+1)); echo "FAIL $*"; }
|
||||
|
||||
# A per-site vhost shaped like WHP's shared-vhost-template.tpl (2026-11-22).
|
||||
cat > "$T/site.conf" <<'EOF'
|
||||
<Directory "/mnt/users">
|
||||
Options SymLinksIfOwnerMatch
|
||||
</Directory>
|
||||
<Directory "/mnt/users/a/a.test/public_html">
|
||||
Options Indexes SymLinksIfOwnerMatch MultiViews
|
||||
AllowOverride AuthConfig FileInfo Indexes Limit Options=Indexes,MultiViews,SymLinksIfOwnerMatch,ExecCGI
|
||||
Require all granted
|
||||
</Directory>
|
||||
<Directory "/mnt/users/a/a2.test/public_html">
|
||||
Options Indexes SymLinksIfOwnerMatch MultiViews
|
||||
Require all granted
|
||||
</Directory>
|
||||
<VirtualHost *:80>
|
||||
ServerName a.test
|
||||
DocumentRoot "/mnt/users/a/a.test/public_html"
|
||||
</VirtualHost>
|
||||
<VirtualHost *:80>
|
||||
ServerName a2.test
|
||||
DocumentRoot "/mnt/users/a/a2.test/public_html"
|
||||
</VirtualHost>
|
||||
<IfModule whp_symlink_module>
|
||||
WHPOwnerGuard On
|
||||
</IfModule>
|
||||
EOF
|
||||
cat > "$T/lines" <<'EOF'
|
||||
+All
|
||||
-All
|
||||
All
|
||||
+all
|
||||
All +Indexes
|
||||
All Indexes
|
||||
None +FollowSymLinks
|
||||
-None
|
||||
FollowSymLinks
|
||||
FOLLOWSYMLINKS
|
||||
+FollowSymlinks
|
||||
+followSYMlinks
|
||||
+FollowSymLinks -SymLinksIfOwnerMatch
|
||||
-SymLinksIfOwnerMatch +FollowSymLinks
|
||||
Indexes +FollowSymLinks
|
||||
+FollowSymLinks\t+Indexes
|
||||
"FollowSymLinks Indexes"
|
||||
"+FollowSymLinks"
|
||||
'FollowSymLinks'
|
||||
Follow\\SymLinks
|
||||
"Follow"SymLinks
|
||||
+FollowSymLinks "x y"
|
||||
+Includes
|
||||
Includes
|
||||
+RunScripts
|
||||
+ExecCGI
|
||||
ExecCGI
|
||||
+Bogus +FollowSymLinks
|
||||
+FollowSymLinks +ExecCGI +Includes
|
||||
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'
|
||||
n=0
|
||||
while IFS= read -r line; do
|
||||
n=$((n+1)); d="\$A/t$n"
|
||||
printf 'mkdir -p %s; printf %%s %q > %s/.line\n' "$d" "$line" "$d"
|
||||
printf "printf 'Options %%b\\\\nAddOutputFilter INCLUDES .shtml\\\\nAddHandler cgi-script .cgi\\\\n' %q > %s/.htaccess\n" "$line" "$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/lines"
|
||||
echo "echo $n > /ntests"
|
||||
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"
|
||||
|
||||
docker run -d --name "$NAME" "$IMAGE" >/dev/null || { echo "SKIP: cannot start $IMAGE"; exit 0; }
|
||||
sleep 3
|
||||
docker cp "$T/site.conf" "$NAME:/etc/httpd/conf.d/vhosts/zz-symtest.conf" >/dev/null
|
||||
docker cp "$T/fx.sh" "$NAME:/fx.sh" >/dev/null
|
||||
docker exec "$NAME" bash /fx.sh || { bad "fixtures"; exit 1; }
|
||||
docker exec "$NAME" httpd -M 2>/dev/null | grep -q ' whp_symlink_module ' && ok "module loaded" || bad "module not loaded"
|
||||
docker exec "$NAME" httpd -t >/dev/null 2>&1 && ok "httpd -t" || { bad "httpd -t"; exit 1; }
|
||||
docker exec "$NAME" httpd -k graceful; sleep 3
|
||||
get() { docker exec "$NAME" sh -c "curl -s --max-time 10 --resolve $1:80:127.0.0.1 -o /tmp/o -w '%{http_code}' 'http://$1$2'; printf ' '; head -c 200 /tmp/o | tr '\n' '~'"; }
|
||||
|
||||
N=$(docker exec "$NAME" cat /ntests)
|
||||
for i in $(seq 1 "$N"); do
|
||||
line="$(docker exec "$NAME" cat /mnt/users/a/a.test/public_html/t$i/.line)"
|
||||
st=$(get a.test /t$i/steal.txt); x=$(get a.test /t$i/p.shtml); c=$(get a.test /t$i/p.cgi)
|
||||
case "$st" in *B-SECRET*) bad "Options $line: cross-tenant symlink read" ;; *) ok "Options $line: no cross-tenant read (${st:0:3})" ;; esac
|
||||
case "$x$c" in *uid=*) bad "Options $line: code executed" ;; *) ok "Options $line: no exec" ;; esac
|
||||
case "$line" in
|
||||
*\"*|*\'*|*\\\\*) [ "$(get a.test /t$i/own.txt | cut -c1-3)" = 500 ] && ok "Options $line: quoted/escaped line refused" || bad "Options $line: quoted/escaped line not refused" ;;
|
||||
+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
|
||||
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
|
||||
|
||||
echo "whp-symlink-module.test: $pass passed, $fail failed"
|
||||
[ "$fail" -eq 0 ]
|
||||
Reference in new issue
Block a user