Make WordPress Core

Opened 14 months ago

Last modified 10 months ago

#63943 reopened defect (bug)

Post Passwords over 255 are not controlled in Quick Edit, nor reported Server Level.

Reported by: SirLouen Owned by: rishabhwp
Priority: normal Milestone: Future Release
Component: Quick/Bulk Edit Version: 4.7
Severity: normal Keywords: has-patch has-unit-tests report-upstream
Cc: Focuses:

Description

In [38590] max length was increased from 20 to 255 for post_password
The problem is that, if a post is over 255, there is no server side validation, and this is not enforced in the Quick Edit panel either with a maxlenght

In the database, obviously the 255+ character password will be truncated, but the user will never know this.

Change History (11)

#1 @rishabhwp
14 months ago

Hey @SirLouen,
I am able to reproduce the issue. I’ll be happy to work on it and raise a PR.

This ticket was mentioned in ​PR #9776 on ​WordPress/wordpress-develop by ​@rishabhwp.


14 months ago
#2

  • Keywords has-patch has-unit-tests added

#3 follow-up: @SirLouen
14 months ago

  • Keywords changes-requested report-upstream added
  • Milestone Awaiting Review → Future Release
  • Owner set to rishabhwp
  • Status new → assigned

From the testing side, it looks good.

I had to open the maxlength to check this

https://i.imgur.com/cq26m2L.png

Also in Gutenberg, as expected, the error

https://i.imgur.com/Iu9SG7o.png
Maybe this could follow up with a patch for API/Gutenberg to show the right message.

And the error in the Post Editor as expected also

https://i.imgur.com/rByZJss.png

For the code review part: For the error section, I would set something like invalid_post_password_length to be more explicit. Also, you don't need to add the Error: in front of the sentence.

For the test, try to keep it simpler and remove all the assertions that are not really straight to the point. We all know that when you use an AI to assist you in building the unit tests, it adds too much fluff, but you have to try to walk the extra mile and clean them up to go straight to the point with the minimal and best possible selection of asserts.

And even more importantly, check (I have not checked) if you are not repeating tests. For example, we can be 100% sure that there is no check for the WP_Error because we are creating it in this patch. But are you completely sure there are no other tests already checking the validity of a post_password?

#4 in reply to: ↑ 3 ; follow-up: @rishabhwp
14 months ago

Thanks for reviewing the PR!

For the code review part: For the error section, I would set something like invalid_post_password_length to be more explicit. Also, you don't need to add the Error: in front of the sentence.

I've updated the error code to invalid_post_password_length and removed the "Error:" prefix to make it more explicit.

For the test, try to keep it simpler and remove all the assertions that are not really straight to the point.

I simplified the test. Now it only checks that passwords longer than 255 characters return the right error. When you say ‘remove all the assertions that are not really straight to the point,’ do you mean the extra ​asserts in the PR?

But are you completely sure there are no other tests already checking the validity of a post_password?

I did check and found there's a test_post_password() function in ​results.php, but it only tests password-protected post queries, not the validation logic itself. The _wp_translate_postdata() function didn't have any existing password length validation tests, so this new test is covering a gap in the test suite.

#5 in reply to: ↑ 4 ; follow-up: @SirLouen
14 months ago

Replying to rishabhwp:

I did check and found there's a test_post_password() function in ​results.php, but it only tests password-protected post queries, not the validation logic itself. The _wp_translate_postdata() function didn't have any existing password length validation tests, so this new test is covering a gap in the test suite.

In this case, you can perfectly add the other test.

You could also be adding some extra tests like for example having a user without publish_post cap calling to this function with a post_password and checking if the resulting array from this function has the password unset (just to add more coverage to this function)

#6 in reply to: ↑ 5 @rishabhwp
14 months ago

Replying to SirLouen:

You could also be adding some extra tests like for example having a user without publish_post cap calling to this function with a post_password and checking if the resulting array from this function has the password unset (just to add more coverage to this function)

I’ve added the test case for additional coverage and addressed all the review comments on the PR. Thanks for the feedback!

#7 @rishabhwp
14 months ago

  • Keywords changes-requested removed

#8 @SirLouen
14 months ago

  • Keywords needs-testing added

Ready for testing.

#9 @r1k0
10 months ago

Also to add on to the description of the bug, when you add 255+ password through post editor in site editor. The password gets silently truncated to 255 characters and stored as such in the database. But when you enter 255+ password through quick edit option under the post in admin dashboard. The password doesn't get truncated and is not stored in the the database.

Last edited 10 months ago by r1k0 (previous) (diff)

#10 @r1k0
10 months ago

  • Keywords needs-testing removed
  • Resolution → worksforme
  • Status assigned → closed

Combined Bug Reproduction & Patch Test Report

Patch tested: ​https://github.com/WordPress/wordpress-develop/pull/9776

Steps to Reproduce or Test

  1. In the admin dashboard, head over to Posts > All posts.
  2. Select the Quick edit option for any post.
  3. Enter a 255+ password in the password input box. In my case, I used a 300-character password.
  4. Click the Update button and observe the page.

Expected Results

  • ✅ A validation error should pop up when you try to save a 255+ password, and locking post should fail.

Actual Results

  • ❌ No validation error pops up; warning the user to use =< 255 password. The password is not saved, and the user is not informed that locking the post fails.

Attachment

Saving password in quick edit before patch:

https://imgur.com/a/t91Jtcv

Environment

  • WordPress: 7.0-alpha-61215-src
  • PHP: 8.2.29
  • Server: nginx/1.29.4
  • Database: mysqli (Server: 8.4.7 / Client: mysqlnd 8.2.29)
  • Browser: Chrome 143.0.0.0
  • OS: Linux
  • Theme: Twenty Twenty-Five 1.4
  • MU Plugins: None activated
  • Plugins:
    • Test Reports 1.2.1

Actual Results

  • ✅ Issue resolved with patch.
  • An error warns users that Post password cannot be longer than 255.

Attachment

Saving password in quick edit after patch:
Screencast:
​https://imgur.com/a/UcGBrrE

Additional Notes

  • While in post edit page, the password gets truncated to 255 (as I mentioned earlier) without informing user, this happens before and after patch.
  • I believe this should be fixedin Gutenberg.

Attachment

Post password in post edit page (before and after):
Screencast:
​https://imgur.com/a/TKNqXQh

Last edited 10 months ago by r1k0 (previous) (diff)

#11 @r1k0
10 months ago

  • Resolution worksforme
  • Status closed → reopened
Note: See TracTickets for help on using tickets.