4 ms·
> Are there any arguments to not do this in production? When the way the code is run is also the vehicle for returning output, you necessarily end up in a situ
by bastawhiz 4y ago
> Are there any arguments to not do this in production?
When the way the code is run is also the vehicle for returning output, you necessarily end up in a situation where you expose bad output to the user. This is an insanely common problem with PHP: warnings, errors, and stack traces are regularly returned in HTTP responses by default.
Consider PHP: the output of the code (echo, closing the PHP tag, etc) gets dumped to the HTTP response, unless you configure it otherwise. Error? To the HTTP response. This exposes internal state and may be a security issue (it often is) or reveals your source code.
By contrast, the only way to return data to a HTTP response in Python is to construct a response object and return it. All the built in methods for printing or generating output write to stdout/stderr or the built in python logging framework. You can get PHP-style errors, but only deliberately by having your framework catch exceptions and convert them to responses.
As much as this seems like a non-issue, it's actually really dangerous when files map to URLs, because you don't want all your files being URLs. Some files are supposed to be shared, or only loaded in certain circumstances. If you can access arbitrary chunks of code directly, and then read any error output from them (or even regular-but-unintended output), you could be leaking data. Without lots of explicit manual boilerplate to block this direct access, you're running a huge risk.
And this isn't just speculation. I've worked at a large PHP shop, and this was a frequent source of frustration and pain. Nobody is immune from this.
- 9dev 4y agoI would argue this is mostly a thing of the past. Properly configuring your production environment is a thing for all languages, and stuff like that simply doesn’t happen with a modern framework, ie. Anything written after 2010.
- withinboredom 4y agoPhp’s default production configuration doesn’t output any errors. Perhaps you were running the default dev configuration in production?
- bastawhiz 4y agoI publish a WordPress plugin and have worked with PHP for twenty years, and given the number of sites I've investigated that output notices and errors, what you've said seems false. Even if the stock version that is officially distributed doesn't output this by default, a wild number of hosts do.
- withinboredom 4y agoBelief isn’t required: https://github.com/php/php-src/blob/master/php.ini-production#L97 https://github.com/php/php-src/blob/master/php.ini-productio... I suspect many people don’t RTFM or have any idea what they are doing with php (or js) because they are historically “entry-level” languages.