Why this matters
Detailed error messages can reveal sensitive information (directory structures, SQL queries, keys) useful to attackers. Logging errors internally and hiding details from users improves security and UX.
Configure your application not to display detailed error messages (stack traces, PHP warnings) to end users in production. Instead, log errors for developers and show a generic message to users.
Detailed error messages can reveal sensitive information (directory structures, SQL queries, keys) useful to attackers. Logging errors internally and hiding details from users improves security and UX.
Side-by-side examples engineers can pattern-match during review.
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
// showing errors in production
?><?php
ini_set('display_errors', 0);
ini_set('log_errors', 1);
error_reporting(E_ALL);
// in production, errors are logged but not displayed
?><?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
// showing errors in production
?><?php
ini_set('display_errors', 0);
ini_set('log_errors', 1);
error_reporting(E_ALL);
// in production, errors are logged but not displayed
?>From the same buckets as this rule.
Check if loops use equality operators (== or !=) in termination conditions. These can lead to infinite loops if the condition is never met exactly. Instead, use relational operators like < or > for safer loop termination.