-
-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cgitb sends a bogus HTTP header if the app crashes before finishing headers #52950
Comments
If the CGI script crashes before finishing the headers, cgitb will emit invalid HTTP headers before showing the error message. Below are HTTP headers I received, captured with a packet sniffer. Note the "<--: spam". HTTP/1.1 200 OK That string it emitted by cgitb.reset(), which is trying to reset the browser to a sane state so the error message will be shown. The problem can be easily fixed by having cgitb.reset() emit two CRLF pairs first, to ensure that we're done with the headers and emitting content:
|
Yes, I saw the "<!--: spam" string in headers, but it seems that this string doesn't make problems. The displaying page is correct. But after I apply the changes you mentioned:
I got text/plain output, and the response headers are like this:
And the content is like this: <!--: spam <body bgcolor="#f0f0f8"><font color="#f0f0f8" size="-5"> --> ...... So the hole page is not displayed correctly! Is there any problem with me? |
It displays correctly in some browsers, yes, but not everything that speaks HTTP is a browser. For example, the invalid header makes C#'s WebRequest throw an exception. I hadn't noticed the 'Content-Type' on the next line of the string output by reset(). That does make things more complicated. We could put the "Content-Type: text/html" first, but the downside is that it will be output as visible content if a script crashes after the headers have been emitted. I'm not sure if that's better or worse than emitting an invalid header. |
I get similar results if my CGI script sends a Content-Type header of anything besides "text/html", e.g. print('Content-Type: text/json'). |
Apache started strict check of headers ch
The workaround is to put: |
#Maybe not a good solution
Then it works very well, and it has good view.Anyone know what is the situation in ngix? |
As mentioned above standard Apache does not accept the extra characters anymore and produces '500 internal error'. So the normal behaviour of this module makes things worse in most cases instead of being helpful. |
Ran into this also, got: AH02429: Response header name '<!--' contains invalid characters, aborting request |
|
Yep, deprecated in 3.11 and removed in 3.13: see PEP 594 – Removing dead batteries from the standard library, #91217 and #32410. @cthart Some good news: a fork has been made by @jackrosenthal:
Because there's no maintainer for this module in CPython, perhaps it would be better to close this issue and instead put energy into the fork? |
I think so. I'm going to close this issue for now, but I'm happy to reopen if somebody wants to persuasively argue for why this issue should be fixed in CPython despite the deprecation. Cc. @cthart |
Good call. A fork available via GitHub / PyPi is a perfect solution for this library. My interest is only in the |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: