Skip to content

fix(rocky9): prevent /health.php from clearing PHP-FPM auto_prepend_file - #787

Open
lgmore wants to merge 1 commit into
scieloorg:codex/php8-rocky9-migration-pushablefrom
lgmore:fix/php-fpm-auto-prepend-poisoning
Open

lgmore wants to merge 1 commit into
scieloorg:codex/php8-rocky9-migration-pushablefrom
lgmore:fix/php-fpm-auto-prepend-poisoning

Conversation

@lgmore

@lgmore lgmore commented Nov 19, 2026

Copy link
Copy Markdown

Summary

Fixes a PHP-FPM worker state poisoning bug observed while validating infrascielo/metodologia:v7.14-qa on SciELO Paraguay staging (PHP 8.5.12):

  • Root cause: docker/rocky9/httpd-scielo.conf sets:
    <Location "/health.php">
        SetEnv PHP_ADMIN_VALUE "auto_prepend_file="
    </Location>
    Because Apache routes PHP requests to persistent PHP-FPM workers over proxy:unix:/run/php-fpm/www.sock|fcgi://localhost/, PHP_ADMIN_VALUE overwrites auto_prepend_file for the lifetime of that PHP-FPM worker process across subsequent requests (pm.max_requests = 250). After Docker's periodic HEALTHCHECK hits /health.php a few times (pm.max_children = 8), all PHP-FPM workers stop loading htdocs/compat.php, causing endpoints that rely on compat.php (sendMail.php, articleRequestGraphicPage.php, and legacy compat.php polyfills) to fail with HTTP 500 (Call to undefined function scielo_utf8_encode()).

Changes

  1. docker/rocky9/compat-prepend.php + docker/rocky9/php-scielo.ini + docker/rocky9/Dockerfile:
    Install /opt/scielo-health/compat-prepend.php (copied and php -l checked during image build) and set auto_prepend_file = /opt/scielo-health/compat-prepend.php. It loads /var/www/html/htdocs/compat.php only when it exists and SCRIPT_FILENAME !== '/opt/scielo-health/health.php', preserving /health.php independence for older mounted trees without mutating worker INI state.
  2. docker/rocky9/httpd-scielo.conf:
    Remove <Location "/health.php"> SetEnv PHP_ADMIN_VALUE "auto_prepend_file=" </Location>.
  3. htdocs/applications/scielo-org/users/functions.php:
    Add a defensive SCIELO_COMPAT_LOADED require_once for htdocs/compat.php (matching the existing pattern in htdocs/oai/scielo-oai.php and htdocs/classMySQLDatabase.php) for standalone/non-container deployments.
  4. tests/security_regression.php:
    Add regression checks verifying httpd-scielo.conf does not set auto_prepend_file= and php-scielo.ini references /opt/scielo-health/compat-prepend.php.

Verification

  • php -l /opt/scielo-health/compat-prepend.php -> No syntax errors detected
  • /opt/httpd/bin/httpd -d /etc/httpd -f conf/httpd.conf -t -> Syntax OK
  • php /var/www/html/tests/security_regression.php inside v7.14-qa staging container -> Security regression tests passed
  • Restarted staging container, executed /health.php 12 times (HTTP 200), then verified sendMail.php and articleRequestGraphicPage.php across 8 consecutive requests (HTTP 200 on all 8/8 vs HTTP 500 before the fix).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant