Skip to content

Stop leaking SQL / $wpdb->last_error in exception messages#37

Merged
alexstandiford merged 1 commit into
mainfrom
fix/non-leaking-exception-messages
Jun 12, 2026
Merged

Stop leaking SQL / $wpdb->last_error in exception messages#37
alexstandiford merged 1 commit into
mainfrom
fix/non-leaking-exception-messages

Conversation

@alexstandiford

Copy link
Copy Markdown
Contributor

Stable exception messages; diagnostic detail recorded via error_log at the failure point through a shared LogsDatabaseErrors trait. RecordNotFound sites stripped but deliberately not logged (control flow). Updated the test that pinned the old leaking contract to pin the new one (stable message + detail present in the error log). 59 tests green. Fixes #32.

Database failure exceptions interpolated MySQL error text and assembled
queries into their messages, which can surface in REST error payloads or
rendered fatals — information disclosure. Messages are now stable; the
diagnostic detail is recorded server-side at the point of failure via a
shared LogsDatabaseErrors trait (error_log → wp-content/debug.log when
WP_DEBUG_LOG is on, the server log otherwise).

RecordNotFoundException sites lose the query text but are NOT logged —
they are routine control flow (every datastore miss), and logging them
would flood operator logs. Invalid-query wrapper exceptions keep their
$previous chain, so full detail remains available to structured loggers.

Fixes #32
@alexstandiford alexstandiford merged commit 02400d7 into main Jun 12, 2026
1 check passed
@alexstandiford alexstandiford deleted the fix/non-leaking-exception-messages branch June 12, 2026 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exception messages leak SQL / $wpdb->last_error to callers (information disclosure)

1 participant