Stop forcing display_errors in production and leaking DB errors - #90
Open
santichausis wants to merge 1 commit into
Open
Stop forcing display_errors in production and leaking DB errors#90santichausis wants to merge 1 commit into
santichausis wants to merge 1 commit into
Conversation
Removes hardcoded ini_set('display_errors', 1) / error_reporting(E_ALL)
overrides from ~29 files. These forced PHP to show stack traces and
internal paths to any visitor regardless of the server's own
production php.ini settings.
Also replaces every place that echoed a raw $conn->error / $stmt->error
/ connect_error string back to the browser (public API endpoints, the
public project-submission forms, and the /scripts/ admin tools) with a
generic message plus a server-side error_log() call, so operators can
still diagnose failures without exposing DB schema/host details to
whoever is looking at the response.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two related information-disclosure issues, fixed together since they're both about errors leaking to end users:
1. Hardcoded
display_errorsin ~29 files. Files like404-handler.php,en/project.php,es/add-project.php,scripts/get-training.php,api/fetch_cash_trans.php, etc. had:This forces PHP to print stack traces and internal file paths to any visitor, overriding whatever the production server's own
php.inisays. Removed these overrides everywhere so the server's own production settings (which should havedisplay_errorsoff) actually take effect. Where the line closed the PHP tag inline (ini_set(...);?>), preserved the?>and only removed the ini_set/error_reporting calls, verified withphp -lon every changed file.2. Raw DB errors echoed straight to responses. E.g.
api/fetch_cash_trans.phpdid:Anyone hitting the endpoint with a malformed request got the actual MySQL error string back. Replaced every occurrence (public
/api/endpoints, the publicadd-project/add-project-imagesforms in es/fr/id, and the/scripts/admin migration tools) with a generic message +error_log(...)so the real error is still available to whoever has server log access, just not to the requester.Testing
No test suite/CI in this repo, and no DB credentials available locally (
ecobricks_env.php/gobrikconn_env.phpintentionally not committed). Verified with:php -lon all 35 changed files — no new syntax errors (pre-existing unrelated(double)cast deprecation notices in a fewadd-project.phpfiles are untouched, confirmed present before this change too).$errors[]/$error_messageare still populated soif (!empty($error_message))branches still fire correctly, just with generic text instead of the raw driver error).Recommend a quick smoke test on staging/
beta.ecobricks.org: submit theadd-projectform and the/api/fetch_cash_trans.phpendpoint with an invalid ID and confirm you get a clean generic error instead of a PHP warning or raw SQL error text.