Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jt/fix serialized values #1510

Merged
merged 10 commits into from Apr 2, 2024
Merged

Jt/fix serialized values #1510

merged 10 commits into from Apr 2, 2024

Conversation

jtsternberg
Copy link
Member

@jtsternberg jtsternberg commented Mar 29, 2024

Description

Update how we store/retrieve serialized values (the text_datetime_timestamp_timezone field).

Also… bumps our min. php support to 7.4 🥳

Motivation and Context

security.

Risk Level

Testing procedure

Before this PR

  1. Create fields (preferably in every core object type) with the text_datetime_timestamp_timezone field type

    • example:
    $cmb->add_field( array(
       'name' => __( 'Test Date/Time Picker/Time zone Combo (serialized DateTime object)', 'cmb2' ),
       'desc' => __( 'field description (optional)', 'cmb2' ),
       'id'   => '_yourprefix_demo_datetime_timestamp_timezone',
       'type' => 'text_datetime_timestamp_timezone',
       'time_format' => 'H:i',
       'date_format' => 'Y-m-d',
       // 'repeatable' => true,
       'before_field' => function ( $args, $field ) {
          // echo '<xmp>'. __LINE__ .') $field: '. print_r( $field, true ) .'</xmp>';
          $value = get_post_meta( $field->object_id, $field->id(), 1 );
          echo '<xmp>$value: '. print_r( $value, true ) .'</xmp>';
          $_utc_value = get_post_meta( $field->object_id, $field->id(). '_utc', 1 );
          echo '<xmp>$_utc_value: '. print_r( $_utc_value, true ) .'</xmp>';
       },
       'column' => true,
    ) );

    And you can test the options-page type with the following setup: https://gist.github.com/jtsternberg/d6ab21ca3a7de1a77d1adfefa0b9445f

  2. In each object type, udpate the value, save, see that it all works as expected.

  3. Check the DB values -- you should see a double-serialized DateTime object

  4. Try using get_post_meta to retrieve the value and see that it's a serialized DateTime object. (if you used the example above, you can see the value in the before_field callback).

Next

  1. Pull down this PR
  2. Review every field in each object type (refresh the page) and make sure field looks/acts correctly.
  3. See that the get_post_meta value still gives you a serialized DateTime object.
  4. Try storing a bad actor value to the DB: wp post meta update 1 _yourprefix_demo_datetime_timestamp_timezone 'O:4:"Evil":2:{s:4:"hack";N;s:2:"me";R:2;}'
  5. Reload the various pages and see that the field still looks/acts correctly, except the value is blank.

… values

Uses the allowed_classes option to unserialize (the options param only supported after 7.0+)
Further resolves security concerns with unserializing arbitrary data.
…fely, as well as helpers to convert json version to datetime object
…alized

Updates one use of unserialize to a safe version

Also cleans up the method and makes things a bit less "clever"
…alized DateTime value returned from meta calls

This ensures anyone using this meta value can continue to use as they were.

This callback can be overridden with a field arg, $field['field_hookup_instance'][ $object_type ]
- This allows disabling the shim if you already updated your use, and allows unhooking or overriding the callback

Also Moves the rest of the field-specfic hooks from CMB2::field_actions to the new CMB2_Hookup_Field class.
@jtsternberg jtsternberg self-assigned this Mar 29, 2024
@jtsternberg jtsternberg requested a review from tw2113 March 29, 2024 16:03
Copy link
Contributor

@tw2113 tw2113 left a comment

Choose a reason for hiding this comment

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

All looked good to me overall JT.

@jtsternberg jtsternberg marked this pull request as ready for review April 1, 2024 13:56
@jtsternberg jtsternberg merged commit 3a13dec into develop Apr 2, 2024
3 checks passed
@jtsternberg jtsternberg deleted the jt/fix-serialized-values branch April 2, 2024 17:32
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.

None yet

2 participants