Files
zoneminder/web/api/app/Lib/Error/ZmExceptionRenderer.php
T
Nic BoetandClaude Opus 5.5 66a1267b42 fix(api): keep exception text and credentials out of 5xx bodies
With debug 0, Cake replaces a 500's message with a generic one, but
Crud's exception renderer adds data.exception.message from the raw
exception. A PDOException (e.g. monitors/index/<unknown column>:1.json)
returned the SQL error and its fragment of the query to the client.
data.url also echoed the request URL with its token or password.

ZmExceptionRenderer extends Crud's renderer: with debug 0 a 5xx body
carries the generic message in data.exception.message (class and code
are kept), and data.url has credential values redacted.
AppController::beforeFilter() swaps it in for the renderer Crud's
ApiListener registers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 11:31:26 -05:00

31 lines
935 B
PHP

<?php
App::uses('CrudExceptionRenderer', 'Crud.Error');
App::uses('ZmErrorHandler', 'Error');
/**
* Crud's API exception renderer, without internals in 5xx bodies.
*
* Crud adds data.exception.message from the raw exception even when Cake has
* replaced the message with a generic one (debug 0), so a PDOException put the
* SQL error and its fragment of the query in the response. It also echoes the
* request URL, credentials included, in data.url.
*/
class ZmExceptionRenderer extends CrudExceptionRenderer {
/**
* {@inheritDoc}
*/
protected function _getErrorData() {
$data = parent::_getErrorData();
if (isset($data['url'])) {
$data['url'] = ZmErrorHandler::redact($data['url']);
}
if (!Configure::read('debug') && isset($data['exception'])
&& $this->controller->response->statusCode() >= 500) {
$data['exception']['message'] = __d('cake', 'An Internal Error Has Occurred.');
}
return $data;
}
}