fix(rest-api): reject non-string secrets - #525
Open
sjinks wants to merge 1 commit into
Open
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
There was a problem hiding this comment.
Pull request overview
Updates the Cron Control REST API authentication check to safely reject non-string secrets before calling hash_equals(), preventing type-related errors and ensuring a consistent error response. Adds a unit test covering an array-valued secret in REST requests.
Changes:
- Reject non-string configured secrets and non-string request secrets before
hash_equals()in REST permission checks. - Add unit test verifying an array
secretis rejected with the existingno-secreterror.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| includes/class-rest-api.php | Adds is_string() guards before hash_equals() in check_secret() to reject non-string secrets safely. |
| tests/unit-tests/test-rest-api.php | Adds unit test ensuring an array secret yields the expected 400 no-secret response. |
Suppressed comments (1)
includes/class-rest-api.php:151
- The new validation rejects non-string secrets, but the returned message still implies the secret is merely missing. Updating the message to mention the expected type will make client-side debugging clearer while keeping the same error code.
if ( ! isset( $body['secret'] ) || ! is_string( \WP_CRON_CONTROL_SECRET ) || ! is_string( $body['secret'] ) || ! hash_equals( \WP_CRON_CONTROL_SECRET, $body['secret'] ) ) {
return new \WP_Error(
'no-secret',
__( 'Secret must be specified with all requests', 'automattic-cron-control' ),
array(
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Reject non-string configured and request secrets before hash_equals, returning the existing no-secret response. Adds array-secret REST coverage. PHP syntax, PHPCS, and git diff --check pass locally; PHPUnit requires the unavailable local WordPress/MariaDB harness. Fixes PLTFRM-2762.