Make WordPress Core

Opened 3 weeks ago

Last modified 5 days ago

#61640 new defect (bug)

Issues in edit_link Function: Inconsistent Return Values, Insufficient Permission Error Handling, and Data Sanitization

Reported by: shyamavadukar's profile shyamavadukar Owned by:
Milestone: Awaiting Review Priority: normal
Severity: major Version: 6.5.5
Component: Security Keywords: has-patch
Focuses: coding-standards Cc:

Description

Hello Sir/Ma'am,

The edit_link function has several issues that need to be addressed to ensure proper functionality, security, and consistency:

1) Permission Error Handling: The function returns a WP_Error object for insufficient permissions, but this might not be user-friendly. It should use wp_die() to display a user-friendly error message.

if (!current_user_can('manage_links')) {

wp_die(('You need a higher level of permission.'));

}

2) Inconsistent Return Values: The function returns mixed types (0, WP_Error, integer) inconsistently. All failure cases should return a WP_Error object for consistency.

if (empty($link_url)
empty($link_name)) {

return new WP_Error('missing_data', ('Link URL and Name cannot be empty.'));

}

3) Sanitization of Data: The function uses $_POST values without sufficient validation. All incoming data should be sanitized thoroughly.

$link_url = isset($_POSTlink_url?) ? esc_url_raw($_POSTlink_url?) : ;

4)Data Integrity Check: No validation is performed to ensure the provided data is complete or correct before inserting/updating the link. Add validation checks to ensure data integrity.

if (empty($link_url)
empty($link_name)) {

return new WP_Error('missing_data', ('Link URL and Name cannot be empty.'));

}


5) Use of compact(): Using compact() for database operations might introduce vulnerabilities if variables are not sanitized correctly. Ensure all data passed to compact() is sanitized properly.

$link_data = compact('link_url', 'link_name', 'link_image', 'link_rss', 'link_visible');

Steps to Reproduce

  1. Attempt to add or edit a link without the required permissions.
  2. Submit form data with empty or invalid values for URL and Name fields.


Expected Behavior

  1. User-friendly error messages should be displayed for insufficient permissions.
  2. Consistent return types, with WP_Error objects for all error cases.
  3. All input data should be sanitized properly. 4.Validation checks should ensure data integrity before database operations.


Actual Behavior

  1. Insufficient permissions message is not user-friendly.
  2. Mixed return types causing inconsistency.
  3. Potential vulnerabilities due to improper data sanitization.
  4. Missing validation checks can lead to data integrity issues.


Additional Context

-- The issues were found while reviewing the edit_link function in the WordPress Bookmark Administration API.

Best Regards
-Shyama Vadukar

Attachments (1)

bookmark-php-bug.png (27.3 KB) - added by shyamavadukar 3 weeks ago.
File Path is : wp-admin-> includes->bookmark.php

Download all attachments as: .zip

Change History (5)

@shyamavadukar
3 weeks ago

File Path is : wp-admin-> includes->bookmark.php

This ticket was mentioned in PR #7022 on WordPress/wordpress-develop by vijay-creedally.


3 weeks ago
#1

  • Keywords has-patch added

Trac ticket:

This ticket was mentioned in Slack in #core-performance by mukeshpanchal27. View the logs.


3 weeks ago

This ticket was mentioned in Slack in #core-performance by mukeshpanchal27. View the logs.


5 days ago

#4 @mukesh27
5 days ago

  • Focuses performance removed

As discussed in Performance bug scrub it's not Performance focus issue. Removing keywork.

Note: See TracTickets for help on using tickets.