extract: own-account links judged re-rooted, normalized, for the trusted username only (N2-1 review 2)
- strip-escaping-links.py: the /home[N]/<user>/ exemption ran on the RAW
target (`/home/u/../../etc/shadow` was exempt) and on usernames taken
from the archive's own top-dir names (an archive could name itself
cpmove-root). Now only the username WHP passes (extract.sh <username> =
IMPORT_USERNAME, validated) is trusted; the target must be normalized; and
it is RE-ROOTED at the link's <top>/homedir in the extract and kept only
if that resolves (realpath strict) inside it. No trusted name: nothing
exempt.
- scan-symlinks.php: same trusted-name rule; a non-normalized absolute
target is DANGEROUS outright (never prefix-compared).
- tests: /home/u/../../etc/shadow, /home/u/./x, re-rooted dangling,
re-rooted through an escaping link, another user's /home, an
archive-named user (cpmove-root) via extract.sh, no/invalid trusted name.
8 checks fail on 72b8fa9.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
72b8fa9d08
commit
36d4949d34
4 files changed
+109
-35
No files matched your search
+5
-8
@@ -179,15 +179,12 @@ tar --no-same-owner --no-same-permissions --no-overwrite-dir \
|
||||
# targets lexically, so a chain through another link (a -> b/.., b -> x/y/z)
|
||||
# can pass it. strip-escaping-links.py asks realpath() where every extracted
|
||||
# symlink really lands and removes (records) any that leave $DEST, point at
|
||||
# $DEST itself, dangle or loop — own-account absolute /home/<user>/ targets
|
||||
# excepted. A walk error fails the extract closed.
|
||||
LINK_USERS=("$USERNAME")
|
||||
for top in "$DEST"/*/; do
|
||||
[[ -d "$top" && ! -L "${top%/}" ]] || continue
|
||||
t="$(basename "$top")"; t="${t#cpmove-}"; LINK_USERS+=("$t" "${t##*_}")
|
||||
done
|
||||
# $DEST itself, dangle or loop. A walk error fails the extract closed.
|
||||
# Only the TRUSTED username (<username>, the WHP account WHP passes) is
|
||||
# exempted, and only re-rooted inside the extract's homedir; names read from
|
||||
# the archive (top-dir names) are never trusted.
|
||||
STRIP_RC=0
|
||||
ESCAPING=$(python3 -I "$SCRIPT_DIR/lib/strip-escaping-links.py" "$DEST" "$ACTIONS_OUT" "${LINK_USERS[@]}") || STRIP_RC=$?
|
||||
ESCAPING=$(python3 -I "$SCRIPT_DIR/lib/strip-escaping-links.py" "$DEST" "$ACTIONS_OUT" "$USERNAME") || STRIP_RC=$?
|
||||
if [[ $STRIP_RC -eq 0 && "${ESCAPING:-0}" -gt 0 ]]; then
|
||||
log "stripped $ESCAPING symlink(s) that resolve outside the extract, dangle or loop (post-extract check)"
|
||||
fi
|
||||
|
||||
Reference in new issue
Block a user