Skip to content

fix: sanitize GET params and add null checks in REST API association endpoints#1317

Open
thisismyurl wants to merge 1 commit into
htmlburger:developmentfrom
thisismyurl:issue-1314-sanitize-rest-api
Open

fix: sanitize GET params and add null checks in REST API association endpoints#1317
thisismyurl wants to merge 1 commit into
htmlburger:developmentfrom
thisismyurl:issue-1314-sanitize-rest-api

Conversation

@thisismyurl

Copy link
Copy Markdown

Summary

Adds missing input sanitization and null checks to REST API association endpoints, preventing unsanitized user input from reaching database operations.

Problem

The REST API endpoints for get_association_data() and get_association_options() in core/REST_API/Router.php were directly accessing $_GET['container_id'], $_GET['field_id'], and $_GET['options'] without sanitization or null checks. While the rest of the codebase properly sanitizes these parameters (see lines 367–368), these two methods were overlooked.

This creates a potential security issue where unsanitized user input could reach database queries if not sanitized at the query layer.

Solution

Added proper input validation to both methods:

// Before (lines 324–325)
$container_id = $_GET['container_id'];
$field_id     = $_GET['field_id'];

// After
$container_id = isset( $_GET['container_id'] ) ? sanitize_text_field( $_GET['container_id'] ) : '';
$field_id     = isset( $_GET['field_id'] ) ? sanitize_text_field( $_GET['field_id'] ) : '';

if ( ! $container_id || ! $field_id ) {
    return $return_value;
}

Same pattern applied to get_association_options() and the options parameter before it's used in explode(). This matches the existing sanitization pattern already in use elsewhere in the same file.

Changes

  • Added isset() checks to prevent undefined index notices
  • Applied sanitize_text_field() to string inputs
  • Added early returns when required parameters are empty
  • Follows the existing sanitization pattern in the Router class (lines 367–368)

All changes are backwards compatible and defensive in nature.

…endpoints

- Sanitize container_id and field_id parameters using sanitize_text_field()
- Add isset() checks before accessing $_GET values
- Add null-check guards: return empty array if required params are missing
- Sanitize options parameter to prevent injection through explode()
- Matches existing sanitization pattern in get_attachment_data()

Fixes htmlburger#1314: Unsanitized $_GET params and missing null checks in REST API

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 10, 2026 18:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Hardens REST router endpoints by sanitizing query parameters and avoiding undefined index notices when required params are missing.

Changes:

  • Sanitize container_id, field_id, and options inputs read from $_GET
  • Add early returns when required parameters are missing (returning empty arrays)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread core/REST_API/Router.php
Comment on lines +324 to +326
$container_id = isset( $_GET['container_id'] ) ? sanitize_text_field( $_GET['container_id'] ) : '';
$field_id = isset( $_GET['field_id'] ) ? sanitize_text_field( $_GET['field_id'] ) : '';
$options = isset( $_GET['options'] ) ? explode( ';', sanitize_text_field( $_GET['options'] ) ) : array();
Comment thread core/REST_API/Router.php
Comment on lines +329 to +331
if ( ! $container_id || ! $field_id ) {
return $return_value;
}
Comment thread core/REST_API/Router.php
Comment on lines +377 to +379
if ( ! $container_id || ! $field_id ) {
return array();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants