Repository navigation
feat(logging): add opt-in logging of WordPress REST API requests - #863
Open
josephfusco wants to merge 18 commits into
Open
josephfusco wants to merge 18 commits into
josephfusco wants to merge 18 commits into
Conversation
Log REST API requests through the existing logger pipeline when the new "Log REST API Requests" setting is enabled (off by default). Entries are written to the wpgraphql_logging_rest channel, reuse the enabled, IP restriction, sampling and log response settings, and support a new "Exclude REST Routes" prefix list.
Contributor
📦 Plugin Artifacts Ready!Download from GitHub Actions run Available plugins:
See the "Artifacts" section at the bottom of the Actions run page |
- Accept mixed hook arguments so a third-party apply_filters() call with unexpected values cannot fatal a REST response. - Guard with is_graphql_http_request() instead of is_graphql_request(), which is also true while a REST callback runs graphql() and would have dropped those REST entries. - Skip CORS preflight (OPTIONS) requests. - Do not store error bodies twice when Log Response is enabled. - Anonymize response.password in the recommended rules so a newly created application password is not logged in plain text.
Fill coverage gaps for the REST logger (rule filters, Log Points not applying, timer reset and nesting, undispatched requests) and add tests for the new settings fields. Writing these exposed that route exclusions matched raw string prefixes, so /wp/v2/users also excluded /wp/v2/users-extra, and were case-sensitive while WordPress matches routes case-insensitively. Exclusions now match the route and the routes below it, ignoring case.
…EST logging - Let the REST logger override a get_logging_rules() hook in LoggingHelper instead of copying the rule manager setup. - Log only the parameters the client sent, not every endpoint default, to keep REST entries small. - Document the REST settings, what is logged, route exclusions, sanitization, filtering by channel and the extension points.
The REST channel logger is a shared singleton behind a BufferHandler. test_serve_filter_value_is_returned_unchanged wrote two records without reading them, so they stayed buffered past tearDown's delete and were flushed into the next test, which then saw three entries instead of one. Flush the buffer in tearDown before deleting entries.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
REST logging exposes reusable credentials through unredacted authorization headers, cookies, server fields, and nested batch or enveloped payloads despite recommended sanitization.
2 open issues
What changed in this PR
Extends WPGraphQL Logging to support opt-in WordPress REST API request logging through the existing logging pipeline and admin screen, addressing #799.
Changes:
- Adds a dedicated REST channel, request timing, error logging and optional response capture.
- Adds REST enablement and route-exclusion settings, plus recommended sanitization rules for top-level REST fields.
- Adds tests and documentation covering configuration, logging behavior and customization.
| File | Description |
|---|---|
plugins/wpgraphql-logging/tests/wpunit/Logger/Rules/LogRestRequestsRuleTest.php |
Tests REST logging enablement. |
plugins/wpgraphql-logging/tests/wpunit/Logger/Rules/ExcludeRestRouteRuleTest.php |
Tests route exclusions and normalization. |
plugins/wpgraphql-logging/tests/wpunit/Logger/Processors/DataSanizationProcessorTest.php |
Tests top-level REST credential masking. |
plugins/wpgraphql-logging/tests/wpunit/Events/RestRequestLoggerTest.php |
Tests REST logging, filtering, timing and integration. |
plugins/wpgraphql-logging/tests/wpunit/Core/PluginTest.php |
Verifies REST logging defaults to disabled. |
plugins/wpgraphql-logging/tests/wpunit/Admin/Settings/Fields/Tab/BasicConfigurationTabTest.php |
Tests REST settings registration and sanitization. |
plugins/wpgraphql-logging/src/Plugin.php |
Initializes REST logging and its disabled default. |
plugins/wpgraphql-logging/src/Logger/Rules/LogRestRequestsRule.php |
Adds the REST enablement rule. |
plugins/wpgraphql-logging/src/Logger/Rules/ExcludeRestRouteRule.php |
Adds route-prefix exclusions. |
plugins/wpgraphql-logging/src/Logger/Processors/DataSanitizationProcessor.php |
Adds recommended rules for REST credentials. |
plugins/wpgraphql-logging/src/Logger/LoggingHelper.php |
Extracts rule selection for REST-specific overrides. |
plugins/wpgraphql-logging/src/Events/RestRequestLogger.php |
Captures served REST requests on a dedicated channel. |
plugins/wpgraphql-logging/src/Events/Events.php |
Defines the REST logging event. |
plugins/wpgraphql-logging/src/Admin/Settings/Fields/Tab/BasicConfigurationTab.php |
Adds REST logging and route-exclusion controls. |
llms.txt |
Links the REST logging guide. |
docs/plugins/wpgraphql-logging/index.md |
Documents REST support and settings. |
docs/plugins/wpgraphql-logging/how-to/log-rest-requests/index.md |
Explains setup, logged data and customization. |
Review effort: Balanced
…port # Conflicts: # docs/plugins/wpgraphql-logging/index.md
Co-authored-by: josephfusco <6676674+josephfusco@users.noreply.github.com>
Co-authored-by: josephfusco <6676674+josephfusco@users.noreply.github.com>
Copilot started work to fix failing Actions workflows on behalf of
josephfusco
November 3, 2026 17:22
Copilot started work to fix failing Actions workflows on behalf of
josephfusco
November 4, 2026 11:28
Co-authored-by: josephfusco <6676674+josephfusco@users.noreply.github.com>
Copilot started work to fix failing Actions workflows on behalf of
josephfusco
November 4, 2026 12:06
Co-authored-by: josephfusco <6676674+josephfusco@users.noreply.github.com>
Copilot started work to fix failing Actions workflows on behalf of
josephfusco
November 6, 2026 12:49
Co-authored-by: josephfusco <6676674+josephfusco@users.noreply.github.com>
Copilot started work to fix failing Actions workflows on behalf of
josephfusco
November 16, 2026 17:10
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Mask username and email in /batch/v1 sub-requests alongside password, redact the X-WP-Nonce header, simplify wildcard path handling so phpcs passes, and document the redaction and '*' support in custom rules.
Psalm lost the is_string() narrowing on $_SERVER values inside the combined continue condition; move the header check into is_request_header() with @psalm-assert-if-true, which also keeps get_headers() under the cognitive complexity limit. apply_sanitization_rule() receives lists through '*' path segments, so document its by-reference array as array<array-key, mixed>.
Copilot started work to fix failing Actions workflows on behalf of
josephfusco
November 16, 2026 17:56
Copilot started work to fix failing Actions workflows on behalf of
josephfusco
November 16, 2026 18:00
DashboardPage::get_dashboard_data() came in from main at complexity 8 (limit 7), which fails phpcs for every PR that touches wpgraphql-logging. Move the cached read into get_cached_dashboard_data(); behavior is unchanged.
Copilot started work to fix failing Actions workflows on behalf of
josephfusco
November 16, 2026 18:05
Plugin Check now fails with plugin_header_tested_up_to_not_allowed when the main plugin file also declares it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Adds an opt-in setting, off by default, that logs WordPress REST API requests through the existing logger on their own channel.
Credentials stay out of the logs. The
Authorization,Proxy-Authorization,CookieandX-WP-Nonceheaders are stored as***, and server fields likePHP_AUTH_PWare no longer collected. The recommended sanitization rules also cover/batch/v1sub-requests and responses, plus?_enveloperesponses. The header change applies to GraphQL entries too.Closes #799
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Assisting with adding REST API request logging and redacting credentials from it.