@@ -176,6 +176,78 @@ public function test_update_comment_from_unprivileged_user_by_privileged_user()
176176 );
177177 }
178178
179+ /**
180+ * @ticket 57979
181+ *
182+ * @covers ::wp_update_comment
183+ */
184+ public function test_update_comment_allows_images_in_admin_by_privileged_user () {
185+ wp_set_current_user ( self ::$ user_id );
186+
187+ $ comment_id = wp_new_comment (
188+ array (
189+ 'comment_post_ID ' => self ::$ post_id ,
190+ 'comment_author ' => 'Author ' ,
191+ 'comment_author_url ' => 'http://example.localhost/ ' ,
192+ 'comment_author_email ' => 'author@example.com ' ,
193+ 'user_id ' => self ::$ user_id ,
194+ 'comment_content ' => '<a href="http://example.localhost/something.html">click</a> ' ,
195+ )
196+ );
197+
198+ wp_set_current_user ( 0 );
199+
200+ $ admin_id = self ::factory ()->user ->create (
201+ array (
202+ 'role ' => 'administrator ' ,
203+ 'user_login ' => 'test_wp_admin_get ' ,
204+ 'user_pass ' => 'password ' ,
205+ 'user_email ' => 'testadmin@example.com ' ,
206+ )
207+ );
208+
209+ wp_set_current_user ( $ admin_id );
210+
211+ // Simulate admin context.
212+ set_current_screen ( 'edit-comments ' );
213+
214+ wp_update_comment (
215+ array (
216+ 'comment_ID ' => $ comment_id ,
217+ 'comment_content ' => '<img src="http://example.localhost/image.jpg" alt="Test image" width="100" height="50"> ' ,
218+ )
219+ );
220+
221+ // Reset current screen.
222+ set_current_screen ( 'front ' );
223+
224+ wp_set_current_user ( 0 );
225+
226+ $ comment = get_comment ( $ comment_id );
227+ $ this ->assertStringContainsString ( '<img ' , $ comment ->comment_content );
228+ $ this ->assertStringContainsString ( 'src="http://example.localhost/image.jpg" ' , $ comment ->comment_content );
229+ $ this ->assertStringContainsString ( 'alt="Test image" ' , $ comment ->comment_content );
230+
231+ // Verify that malicious attributes are still stripped by KSES.
232+ wp_set_current_user ( $ admin_id );
233+ set_current_screen ( 'edit-comments ' );
234+
235+ wp_update_comment (
236+ array (
237+ 'comment_ID ' => $ comment_id ,
238+ 'comment_content ' => '<img src="x.jpg" onerror="alert(1)"> ' ,
239+ )
240+ );
241+
242+ set_current_screen ( 'front ' );
243+ wp_set_current_user ( 0 );
244+
245+ $ comment = get_comment ( $ comment_id );
246+ $ this ->assertStringContainsString ( '<img ' , $ comment ->comment_content );
247+ $ this ->assertStringNotContainsString ( 'onerror ' , $ comment ->comment_content );
248+ $ this ->assertStringNotContainsString ( 'alert ' , $ comment ->comment_content );
249+ }
250+
179251 /**
180252 * @ticket 30627
181253 *
0 commit comments