Skip to content

Do not run rfc1867 upload progress cleanup when no file was uploaded - #25839

Open
hohphu8 wants to merge 1 commit into
php:PHP-8.4from
hohphu8:fix-session-rfc1867-cleanup-no-file
Open

hohphu8 wants to merge 1 commit into
php:PHP-8.4from
hohphu8:fix-session-rfc1867-cleanup-no-file

Conversation

@hohphu8

@hohphu8 hohphu8 commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

In php_session_rfc1867_callback() (ext/session/session.c), php_rinit_session(0), PS(id), and PS(send_cookie) = 0 are only initialized on the first MULTIPART_EVENT_FILE_START event (when progress->data is allocated). On MULTIPART_EVENT_END, the else (session.upload_progress.cleanup=0) branch checks !Z_ISUNDEF(progress->data), but the PS(rfc1867_cleanup) branch does not.

When a multipart POST carries PHP_SESSION_UPLOAD_PROGRESS and a session ID cookie/field without any file part, MULTIPART_EVENT_END calls php_session_rfc1867_cleanup() before RINIT with PS(id) == NULL and PS(send_cookie) == 1, which creates a new session file on disk and queues a Set-Cookie header even though user code never calls session_start().

This moves the !Z_ISUNDEF(progress->data) check to the enclosing if so neither cleanup nor php_rshutdown_session_globals() runs when no upload progress data was initialized.

Adds ext/session/tests/rfc1867_cleanup_no_file.phpt, which verifies that a multipart request with PHP_SESSION_UPLOAD_PROGRESS and no file part emits no Set-Cookie header and creates no session file. Verified FAIL -> PASS on PHP-8.4 (Debug + ZTS) with ext/session/tests/ passing.

Found through AI-assisted source inspection, independently reproduced and verified.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant