Hacker News new | ask | show | jobs
by Izkata 50 days ago
Sorry, httpd. It was so weird and I couldn't find it in the documentation (and a different server we used on dev didn't do it, which was how the bug made it live) that I pulled down the official source code and found where it was happening so I could explain it to my team.

I'm pretty sure it was all 5xx but can't remember for certain. This was back in 2019, with a much older project, and I'm pretty sure that part of the code was the same as of 2019.

1 comments

I would be interested to hear more, because even with you saying this I still find it genuinely unbelievable.
It really shouldn't be, this error page should be familiar looking: https://i.sstatic.net/FRlUG.png

It comes from ap_send_error_response(), near the bottom starting at https://github.com/apache/httpd/blob/b2dc966be4178ded1499d5d...

Scrolling up from there a bit you can see some of the handling for ErrorDocument, which is configurable ( https://httpd.apache.org/docs/current/custom-error.html ) but also loses the original response body.

ap_send_error_response() is only called from the last line of ap_die_r() ( https://github.com/apache/httpd/blob/b2dc966be4178ded1499d5d... ), as the fallback for errors when none of the other conditions pass. There's some other handling for redirects and custom ErrorDocument, but again, if it reaches those it's using the contents of "custom_response" instead of the original response body.

ap_die_r() is called unconditionally for completed requests ( https://github.com/apache/httpd/blob/b2dc966be4178ded1499d5d... ), which is why api_die_r() starts with an early return for an OK or DONE response. Its wrapper ap_die() is also used in plenty of other locations as a general error handler.

It's been a while so I had to go through it again, the code isn't exactly what I'm half remembering, but I do remember the "assbackwards" lines in ap_send_error_response() ( https://github.com/apache/httpd/blob/b2dc966be4178ded1499d5d... and https://github.com/apache/httpd/blob/b2dc966be4178ded1499d5d... ). If the particular check I think I remember did exist (explicit status codes in an "if", similar to your earlier link), it was probably in the even older version we were using. The early return I'm pretty sure wasn't there (blame puts it at 12 years old), so all responses would have gone through more of the error handling code back then.

Edit: Replacing "trunk" branch with most recent commit so line numbers continue to work in the future