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:

  1. The channel is ignored. post() returns $data['channel'] as dblog_channel, but always logs through the restfullogger logger injected in create(). Clients are told the entry went to their channel when it did not.
  2. Message and path are escaped twice. validateAndParseMessage() and validateAndParsePath() call Html::escape(). The @message and @path placeholders in logger->log() and t() then escape the values again.
  3. Severity fails on non-English sites. validateAndParseSeverity() compares against RfcLogLevel::getLevels(), which returns translated labels. On a site where "Error" is translated, valid severities fall back to notice without 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.

  1. Channel: send {"message": "Test", "path": "/", "channel": "my_app"}. The response says "dblog_channel": "my_app", but /admin/reports/dblog shows type restfullogger.
  2. Escaping: send {"message": "a < b & c", "path": "/"}. The response and dblog show a < b & c.
  3. 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 as notice.

Proposed resolution

Fixes

  • Channel: either inject logger.factory and log to the requested channel (with validation or an allowlist), or drop channel support and always return restfullogger. 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 LogLevel constants with a strict comparison instead of the translated labels.

Tests

  • Enable dblog in the functional test and assert the stored message, channel and severity in the watchdog table.
  • 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 message is missing
    • 400 when path is missing
    • Each of the 8 severities, mixed-case input, and the fallback to notice for invalid values
    • A message containing HTML special characters
    • A custom channel
    • A non-English default language
  • Add a test for the help page at /admin/help/restfullogger.
  • Remove the leftover _format=hal_json query 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_message in the response is no longer double-escaped.
  • Valid severities are honored regardless of site language.
  • Depending on the decision, channel either takes effect or is ignored.

Data model changes

None. Watchdog variables will be stored unescaped, which is standard Drupal practice.

Command icon 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

rymcveigh created an issue. See original summary.

rymcveigh’s picture

Status: Active » Needs review
rymcveigh’s picture

Status: Needs review » Reviewed & tested by the community
rymcveigh’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • rymcveigh committed 4f5bf1ad on 2.0.x
    fix: #3633954 Fix channel, escaping and severity handling, and expand...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.