Bug 40953 - Should not send any data in 1xx/204/304 reply from CGI/PHP/Servlet
Summary: Should not send any data in 1xx/204/304 reply from CGI/PHP/Servlet
Status: REOPENED
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: Core (show other bugs)
Version: 2.4.34
Hardware: Other other
: P2 minor with 2 votes (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
URL:
Keywords: MassUpdate, RFC
Depends on:
Blocks:
 
Reported: 2006-11-12 06:19 UTC by Thijs Kinkhorst
Modified: 2018-11-07 23:52 UTC (History)
5 users (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thijs Kinkhorst 2006-11-12 06:19:06 UTC
Hi,

When Apache passes a request of to a CGI or PHP script or the like, and that
script returns a 304 Not Modified header, and that script sends some additional
content, Apache happily sends that content on to the client.

According to RFC 2616, no content must be sent on a 304 Not Modified. This is
ultimately the responsibility of the script in question, but as Apache should be
strict in what it sends, it could stop any script output after it has sent a 304.
Comment 1 Edward Crichton 2008-02-29 02:43:27 UTC
According to RFC 2616:
"All 1xx (informational), 204 (no content), and 304 (not modified) responses
   MUST NOT include a message-body. "

I have just found that Safari - including the latest version - freezes when it gets content for these with other requests pending - i.e. it gets stuck.

Example response:

HTTP/1.1 204 No Content
Date: Fri, 29 Feb 2008 09:45:53 GMT
Server: Apache/2.2.4 (Ubuntu) mod_jk/1.2.23
Content-Length: 8
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html;charset=ISO-8859-1

(The 8 bytes is just whitespace from formatting in a jsp.)

The response is clearly incorrect.

The safest thing for Apache to do would be to set the content-length to 0 and discard any contents up to the advertised content-length from the cgi/php/servlet.
Comment 2 Takashi Sato 2008-02-29 04:06:41 UTC
IMHO if a CGI sends 304 with content and apache sends it to client, this is not an apache's but CGI's fault. So this issue is renhancement request.
Comment 3 Edward Crichton 2008-02-29 04:19:12 UTC
(In reply to comment #2)
> IMHO if a CGI sends 304 with content and apache sends it to client, this is not
> an apache's but CGI's fault. So this issue is renhancement request.
> 
I can accept that it is a fine line between any cgi/script/php/servlet not respecting the RFC and apache not respecting it for 304 not modified but I have a higher opinion of apache.

Should I then open a new bug for the 204 no content response?

What about the 1xx responses?
Comment 4 Takashi Sato 2008-02-29 05:15:06 UTC
> I can accept that it is a fine line between any cgi/script/php/servlet not
> respecting the RFC and apache not respecting it for 304 not modified

I agree.
I still think "Severity" should be "enhancement" but just a little thing.

> Should I then open a new bug for the 204 no content response?
> What about the 1xx responses?

I've renaming this report's sumary.
Comment 5 Edward Crichton 2008-02-29 05:19:19 UTC
(In reply to comment #4)
> I agree.
> I still think "Severity" should be "enhancement" but just a little thing.
> I've renaming this report's sumary.

Thankyou :-) 

Comment 6 Edward Z. Yang 2009-02-18 13:49:04 UTC
We've run into this "feature enhancement request" recently. It's actually a more specific example of the fact that Apache doesn't sanity check Status Code/Content-Length headers that scripts send back. For example, I can take advantage of this to make a CGI script send two HTTP responses back to a user, when Keep-Alive is on and a single connection is used:

PoC: https://scripts.mit.edu/~apo/mitchtest/304.py
Code: http://mit.edu/~mitchb/Public/304.py

If the PoC works (it occasionally fails, if that happens, try again), it will redirect you to https://scripts.mit.edu/~geofft but will display "Injected Content", which was the second HTTP request sent.

There is also a relevant Firefox bug:
https://bugzilla.mozilla.org/show_bug.cgi?id=363109#c12

It would be very nice to see this fixed.
Comment 7 Nick Kew 2009-02-18 16:27:30 UTC
This now looks like two separate issues.  Comment 6 concerns a 302 response with a Content-Length header but too much content.  FWIW, I expect it can be more easily duplicated with mod_asis.

FWIW, I *think* (but haven't tested - bug me if I drop it) the following patch should fix the original issue.  But it won't do anything for your 302 case.

--- server/util_script.c        (revision 745696)
+++ server/util_script.c        (working copy)
@@ -488,6 +488,11 @@
             if ((cgi_status == HTTP_UNSET) && (r->method_number == M_GET)) {
                 cond_status = ap_meets_conditions(r);
             }
+            else if ((cgi_status == HTTP_NO_CONTENT) ||
+                     (cgi_status == HTTP_NOT_MODIFIED) ||
+                     ap_is_HTTP_INFO(cgi_status)) {
+                r->header_only = 1; /* discard any body */
+            }
             apr_table_overlap(r->err_headers_out, merge,
                 APR_OVERLAP_TABLES_MERGE);
             if (!apr_is_empty_table(cookie_table)) {
Comment 8 Nick Kew 2009-03-30 13:53:09 UTC
Fixed in trunk - r760167.

Changed from the patch I posted in that I dropped 1xx responses and just fixup 204/304.  Since this is about httpd correcting a broken script, we should be conservative in correcting something that might possibly be intentional, like a comet-ish script sending a 100-continue followed by more.
Comment 9 Edward Z. Yang 2009-03-31 07:39:32 UTC
Patch was vetoed by Roy T. Fielding.
Comment 10 William A. Rowe Jr. 2018-11-07 21:09:32 UTC
Please help us to refine our list of open and current defects; this is a mass update of old and inactive Bugzilla reports which reflect user error, already resolved defects, and still-existing defects in httpd.

As repeatedly announced, the Apache HTTP Server Project has discontinued all development and patch review of the 2.2.x series of releases. The final release 2.2.34 was published in July 2017, and no further evaluation of bug reports or security risks will be considered or published for 2.2.x releases. All reports older than 2.4.x have been updated to status RESOLVED/LATER; no further action is expected unless the report still applies to a current version of httpd.

If your report represented a question or confusion about how to use an httpd feature, an unexpected server behavior, problems building or installing httpd, or working with an external component (a third party module, browser etc.) we ask you to start by bringing your question to the User Support and Discussion mailing list, see [https://httpd.apache.org/lists.html#http-users] for details. Include a link to this Bugzilla report for completeness with your question.

If your report was clearly a defect in httpd or a feature request, we ask that you retest using a modern httpd release (2.4.33 or later) released in the past year. If it can be reproduced, please reopen this bug and change the Version field above to the httpd version you have reconfirmed with.

Your help in identifying defects or enhancements still applicable to the current httpd server software release is greatly appreciated.
Comment 11 Anders Kaseorg 2018-11-07 23:52:47 UTC
Still affects 2.4.34.