Problem/Motivation
The module has a single functional test, LoadTest::testPost(), which sends one valid request and checks the JSON response. The response values (dblog_message, dblog_channel, dblog_severity) are built from the request data rather than read back from the log, and dblog is not enabled in the test. The test would still pass if nothing were logged at all.
That gap hides three bugs in RestfulLogger:
- The channel is ignored.
post()returns$data['channel']asdblog_channel, but always logs through therestfulloggerlogger injected increate(). Clients are told the entry went to their channel when it did not. - Message and path are escaped twice.
validateAndParseMessage()andvalidateAndParsePath()callHtml::escape(). The@messageand@pathplaceholders inlogger->log()andt()then escape the values again. - Severity fails on non-English sites.
validateAndParseSeverity()compares againstRfcLogLevel::getLevels(), which returns translated labels. On a site where "Error" is translated, valid severities fall back tonoticewithout any warning.
The access checks, validation errors and the new hook_help() implementation from #3602529 are also untested.
Steps to reproduce
Each step POSTs to /dblog/logger?_format=json as a user with the required permissions.
- Channel: send
{"message": "Test", "path": "/", "channel": "my_app"}. The response says"dblog_channel": "my_app", but/admin/reports/dblogshows typerestfullogger. - Escaping: send
{"message": "a < b & c", "path": "/"}. The response and dblog showa &lt; b &amp; c. - Severity: on a site with French as the default language and its interface translations imported, send
{"message": "Test", "path": "/", "severity": "error"}. The entry is logged asnotice.
Proposed resolution
Fixes
- Channel: either inject
logger.factoryand log to the requested channel (with validation or an allowlist), or dropchannelsupport and always returnrestfullogger. This needs a maintainer decision; see Remaining tasks. - Escaping: remove the
Html::escape()calls and rely on the@placeholders, which escape at render time. - Severity: validate against the PSR-3
LogLevelconstants with a strict comparison instead of the translated labels.
Tests
- Enable
dblogin the functional test and assert the stored message, channel and severity in thewatchdogtable. - Cover the following:
- 403 without
post log messages - 403 without
restful post restfullogger - 403 for an anonymous user
- 403 for a missing or invalid CSRF token
- 400 when
messageis missing - 400 when
pathis missing - Each of the 8 severities, mixed-case input, and the fallback to
noticefor invalid values - A message containing HTML special characters
- A custom channel
- A non-English default language
- 403 without
- Add a test for the help page at
/admin/help/restfullogger. - Remove the leftover
_format=hal_jsonquery from the CSRF token request. HAL was removed from core in Drupal 10.
Remaining tasks
- Decide whether to support or remove custom channels.
- Write the tests. They should fail against the current code.
- Implement the fixes.
- Update the README if channel behavior changes.
- Review.
User interface changes
Log messages containing special characters display correctly in the dblog UI.
API changes
dblog_messagein the response is no longer double-escaped.- Valid severities are honored regardless of site language.
- Depending on the decision,
channeleither takes effect or is ignored.
Data model changes
None. Watchdog variables will be stored unescaped, which is standard Drupal practice.
Issue fork restfullogger-3633954
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
rymcveighComment #4
rymcveighComment #5
rymcveigh