Skip to content

Instantly share code, notes, and snippets.

@sickcodes
Created October 21, 2026 07:52
Show Gist options
  • Select an option

  • Save sickcodes/c2a080d8cd40f9d0116b86c412f07a8d to your computer and use it in GitHub Desktop.

Select an option

Save sickcodes/c2a080d8cd40f9d0116b86c412f07a8d to your computer and use it in GitHub Desktop.
PHP session.upload_progress.enabled slop fix
#!/usr/bin/env bash
# Audit (and optionally disable) session.upload_progress across every PHP
# install, on any layout: Debian/Ubuntu (/etc/php/X.Y/SAPI/), RHEL+Remi
# (/etc/php.ini, /etc/opt/remi/phpXY/), SCL, cPanel/EA4, Hestia, custom.
#
# ./fix-upload-progress.sh # report only, changes nothing
# ./fix-upload-progress.sh --apply # back up, then set Off
# ./fix-upload-progress.sh --root /tmp/fx # test against a copied tree
set -uo pipefail
VERSION=5
APPLY=0
ROOT=''
while [[ $# -gt 0 ]]; do
case "$1" in
--apply) APPLY=1; shift ;;
--root) ROOT="${2%/}"; shift 2 ;;
--version) echo "fix-upload-progress.sh v$VERSION"; exit 0 ;;
*) echo "usage: $0 [--apply] [--root DIR]" >&2; exit 2 ;;
esac
done
STAMP=$(date +%Y%m%d-%H%M%S)
D='session\.upload_progress\.enabled'
# ---------------------------------------------------------------- discovery
# Search every plausible config root. Prune share/doc so packaged templates
# (php.ini-production et al) never enter the list.
# /usr/local as a whole, not /usr/local/{etc,lib,php} - control panels put
# their bundled PHP elsewhere under it (Hestia/Vesta /usr/local/hestia/php/lib,
# DirectAdmin, Plesk). v1 named /usr/local/hestia explicitly; v2 generalised
# the roots and lost it. Same for /opt, which holds cPanel EA4 and Remi SCL.
SEARCH=()
for d in "$ROOT/etc" "$ROOT/usr/local" "$ROOT/opt" "$ROOT/usr/lib/php" \
"$ROOT/usr/lib64/php" "$ROOT/usr/share/php"; do
[[ -d $d ]] && SEARCH+=("$d")
done
[[ ${#SEARCH[@]} -eq 0 ]] && { echo "no config roots under '${ROOT:-/}'" >&2; exit 1; }
mapfile -t FOUND < <(
find "${SEARCH[@]}" \
\( -path '*/share/doc/*' -o -path '*/share/man/*' -o -name 'node_modules' \
-o -name '.git' -o -name 'vendor' -o -path '*/backup/*' \) -prune -o \
-type f \( -name 'php.ini' -o -path '*php*.d/*.ini' -o -path '*php*/conf.d/*.ini' \
-o -name 'php.ini-*' -o -name 'php.ini.*' \) -print 2>/dev/null \
| sort -u
)
# Keep only files PHP actually parses: the main php.ini, plus scan-dir
# fragments (php.d/, conf.d/) which are parsed AFTER php.ini and so override it.
LIVE=(); SKIP=(); SEED=()
for f in "${FOUND[@]}"; do
b=${f##*/}
case "$b" in
# Backup/package leftovers and doc templates are never loaded.
*.rpmnew|*.rpmsave|*.rpmorig|*.dpkg-dist|*.dpkg-new|*.dpkg-old|\
*.ucf-dist|*.ucf-old|*.bak|*.bak.*|*.orig|*.old|*~|php.ini-*)
SKIP+=("$f"); continue ;;
esac
# Packaging/install/template trees are NOT parsed by PHP, but they are the
# source that live config gets regenerated FROM (Vesta/Hestia rebuilds,
# rpmbuild). Editing them fixes nothing today; leaving them On can undo a
# fix tomorrow. Separate category, reported but never edited.
case "$f" in
*/src/*|*/SOURCES/*|*/SPECS/*|*/packaging/*|*/debian/*|\
*/install/*|*/templates/*|*/skel/*|*/.git/*)
SEED+=("$f"); continue ;;
esac
# Scan dirs are parsed AFTER php.ini and override it. Match them broadly:
# php.d, php-zts.d, php7.4-fpm.d, conf.d ... any of these can be a real
# scan dir for some SAPI or build (ZTS in particular).
if [[ $b == php.ini ]] || [[ $f == */php*.d/*.ini ]] || [[ $f == */conf.d/*.ini ]]; then
LIVE+=("$f")
else
SKIP+=("$f")
fi
done
if [[ ${#LIVE[@]} -eq 0 ]]; then
echo "No live php.ini found under '${ROOT:-/}'." >&2
echo "Widen manually: find / -name 'php.ini' -not -path '*/share/doc/*'" >&2
exit 1
fi
# ------------------------------------------------------------------- report
echo "fix-upload-progress.sh v$VERSION host=$(hostname -s 2>/dev/null) root='${ROOT:-/}'"
echo "scanned: ${#LIVE[@]} live file(s) from ${#SEARCH[@]} config root(s)"
echo
printf '%-52s %-9s %s\n' FILE STATE ACTION
printf '%.0s-' {1..92}; echo
changed=0; vuln=0
for f in "${LIVE[@]}"; do
disp=${f#"$ROOT"}
is_frag=0
[[ ${f##*/} != php.ini ]] && is_frag=1
active=$(grep -Ec "^[[:space:]]*${D}[[:space:]]*=" "$f" 2>/dev/null) || active=0
commented=$(grep -Ec "^[[:space:]]*;[[:space:]]*${D}[[:space:]]*=" "$f" 2>/dev/null) || commented=0
if [[ $active -gt 0 ]]; then
val=$(sed -nE "s/^[[:space:]]*${D}[[:space:]]*=[[:space:]]*//p" "$f" \
| tail -n1 | tr -d '"'"'"' \r')
case "${val,,}" in
off|0|false|no|'') state=off ;;
*) state=ON ;;
esac
elif [[ $is_frag -eq 1 ]]; then
# A fragment that says nothing about the directive is irrelevant - it is
# php.ini's absence that matters, not every conf.d file's.
state=n/a
else
# Absent or commented in a main php.ini == compiled-in default == On.
state=ON
fi
[[ $state == ON ]] && vuln=$((vuln+1))
if [[ $state != ON ]]; then
printf '%-52s %-9s %s\n' "$disp" "$state" \
"$([[ $state == off ]] && echo 'ok, no change' || echo 'no directive (inherits php.ini)')"
continue
fi
if [[ $APPLY -eq 0 ]]; then
reason='commented/absent -> default On'
[[ $active -gt 0 ]] && reason='explicitly On'
printf '%-52s %-9s %s\n' "$disp" 'ON' "would set Off ($reason)"
continue
fi
[[ -w $f ]] || { printf '%-52s %-9s %s\n' "$disp" 'ON' 'NOT WRITABLE (run as root)'; continue; }
cp -a -- "$f" "${f}.bak.${STAMP}" || { printf '%-52s %-9s %s\n' "$disp" 'ON' 'BACKUP FAILED, skipped'; continue; }
if [[ $active -gt 0 ]]; then
sed -ri "s|^[[:space:]]*(${D})[[:space:]]*=.*|\1 = Off|" -- "$f"
act='rewrote active line'
elif [[ $commented -gt 0 ]]; then
sed -ri "0,/^[[:space:]]*;[[:space:]]*${D}[[:space:]]*=/{
s|^[[:space:]]*;[[:space:]]*(${D})[[:space:]]*=.*|\1 = Off|
}" -- "$f"
act='uncommented, set Off'
else
printf '\n; CVE-2026-109618 / CVE-2026-109619 mitigation (%s)\n%s\n' \
"$STAMP" 'session.upload_progress.enabled = Off' >> "$f"
act='appended directive'
fi
if grep -Eq "^[[:space:]]*${D}[[:space:]]*=[[:space:]]*(Off|0|false)" "$f"; then
printf '%-52s %-9s %s\n' "$disp" 'ON->off' "$act"
changed=$((changed+1))
else
cp -a -- "${f}.bak.${STAMP}" "$f"
printf '%-52s %-9s %s\n' "$disp" 'ON' 'WRITE FAILED - restored from backup'
fi
done
# Separate pass purely so you can SEE that doc templates and package
# leftovers were considered and correctly ignored, rather than just missed.
mapfile -t IGNORED < <(
find "${SEARCH[@]}" "$ROOT/usr/share/doc" -type f \
\( -name 'php.ini-*' -o -name 'php.ini.rpmnew' -o -name 'php.ini.rpmsave' \
-o -name 'php.ini.dpkg-*' -o -name 'php.ini.ucf-*' \) -print 2>/dev/null \
| sort -u
)
IGNORED+=("${SKIP[@]}")
if [[ ${#IGNORED[@]} -gt 0 ]]; then
echo
echo "Not parsed by PHP - correctly left alone (${#IGNORED[@]}):"
printf ' %s\n' "${IGNORED[@]#"$ROOT"}" | sort -u | head -30
fi
# Packaging/template seeds: not live, but can re-seed live config on rebuild.
if [[ ${#SEED[@]} -gt 0 ]]; then
echo
echo "Packaging/template sources - NOT live, never edited (${#SEED[@]}):"
seedwarn=0
for f in "${SEED[@]}"; do
if grep -Eq "^[[:space:]]*${D}[[:space:]]*=[[:space:]]*(On|1|true|yes)" "$f" 2>/dev/null; then
printf ' %-56s %s\n' "${f#"$ROOT"}" 'sets On - WILL RE-ENABLE ON REBUILD'
seedwarn=$((seedwarn+1))
else
printf ' %-56s %s\n' "${f#"$ROOT"}" 'no active On'
fi
done
[[ $seedwarn -gt 0 ]] && echo \
" ^ $seedwarn seed file(s) would undo this fix if the package/panel is rebuilt."
fi
echo
if [[ $APPLY -eq 0 ]]; then
echo "Report only: $vuln live file(s) effectively On. Re-run with --apply."
exit 0
fi
echo "Changed $changed file(s). Backups: *.bak.${STAMP}"
# -------------------------------------------------------------- verification
echo
echo "Effective value per binary (authoritative - honours all scan dirs):"
mapfile -t BINS < <(
{ command -v php php-cgi 2>/dev/null
ls -1 /opt/remi/php*/root/usr/bin/php /opt/*/root/usr/bin/php \
/usr/bin/php[78].[0-9] /usr/local/bin/php \
/opt/cpanel/ea-php*/root/usr/bin/php 2>/dev/null
} | sort -u
)
if [[ ${#BINS[@]} -eq 0 ]]; then
echo " (no php binaries located)"
else
# Use -i, not -r: php-cgi rejects -r and dumps its usage text instead.
for b in "${BINS[@]}"; do
v=$("$b" -i 2>/dev/null \
| sed -nE 's/^session\.upload_progress\.enabled[[:space:]]*=>[[:space:]]*//p' \
| head -n1)
ver=$("$b" -r 'echo PHP_VERSION;' 2>/dev/null || "$b" -v 2>/dev/null | head -n1 | awk '{print $2}')
printf ' %-44s %-8s %s\n' "$b" "${ver:-?}" "${v:-(not reported)}"
done
echo " (Off / no value = disabled, On = STILL VULNERABLE)"
fi
cat <<'EOF'
PHP_INI_PERDIR: restart, do not reload.
RHEL/Remi : systemctl restart php72-php-fpm php70-php-fpm httpd
Debian : systemctl restart 'php*-fpm' apache2 nginx
Then check what overrides php.ini - these win and are NOT touched above:
grep -rn upload_progress /etc/opt/remi/*/php-fpm.d/ /etc/php-fpm.d/ \
/etc/php/*/fpm/pool.d/ 2>/dev/null
find /var/www /home/*/public_html -name '.user.ini' 2>/dev/null
CLI output does not prove the FPM/Apache SAPI is fixed. Confirm with
phpinfo() over a real HTTP request and read the Local vs Master columns.
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment