Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions tests/phpunit/tests/kses/wpKsesAllowPdfObjects.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/**
* Tests for _wp_kses_allow_pdf_objects().
*
* @group kses
*
* @covers ::_wp_kses_allow_pdf_objects
*/
class Tests_Kses_wpKsesAllowPdfObjects extends WP_UnitTestCase {

/**
* @ticket 65819
*/
public function test_rejects_urls_with_query_string() {
$uploads = wp_upload_dir( null, false );

$this->assertFalse( _wp_kses_allow_pdf_objects( $uploads['url'] . '/file.pdf?download=.pdf' ) );
}

/**
* @ticket 65819
*/
public function test_rejects_urls_with_fragment() {
$uploads = wp_upload_dir( null, false );

$this->assertFalse( _wp_kses_allow_pdf_objects( $uploads['url'] . '/file.pdf#page=.pdf' ) );
}

/**
* @ticket 65819
*/
public function test_rejects_non_pdf_extension() {
$uploads = wp_upload_dir( null, false );

$this->assertFalse( _wp_kses_allow_pdf_objects( $uploads['url'] . '/file.txt' ) );
}

/**
* @ticket 65819
*/
public function test_rejects_pdf_from_other_host() {
$this->assertFalse( _wp_kses_allow_pdf_objects( 'https://evil.example/file.pdf' ) );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Optional: a host-prefix case would lock in the trailing / in the str_starts_with() check. A URL such as https://<uploads host>.evil.example/file.pdf should return false:

$host = wp_parse_url( wp_upload_dir( null, false )['url'], PHP_URL_HOST );

$this->assertFalse( _wp_kses_allow_pdf_objects( 'https://' . $host . '.evil.example/file.pdf' ) );

Also, the PR title says wp_kses_allow_pdf_objects(), but the function is _wp_kses_allow_pdf_objects().

}

/**
* @ticket 65819
*/
public function test_allows_pdf_from_uploads_host() {
$uploads = wp_upload_dir( null, false );
$url = trailingslashit( $uploads['url'] ) . 'document.pdf';

$this->assertTrue( _wp_kses_allow_pdf_objects( $url ) );
}
}
Loading