Repository navigation
feat(logging): add opt-in logging of WordPress REST API requests - #863
Draft
josephfusco wants to merge 6 commits into
Draft
josephfusco wants to merge 6 commits into
josephfusco wants to merge 6 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.
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. Request headers, including
AuthorizationandCookie, are stored unsanitized today, so that should be fixed before this ships.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.