Skip to content

Commit

Permalink
Provide origin for stylesheet URLs which are absolute paths
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed May 15, 2021
1 parent c2a2f10 commit 027b325
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions includes/sanitizers/class-amp-style-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,22 @@ private function process_link_element( DOMElement $element ) {
* @return string|WP_Error Stylesheet string on success, or WP_Error on failure.
*/
private function get_stylesheet_from_url( $stylesheet_url ) {
// For absolute paths, provide the origin (host and port).
if ( '/' === substr( $stylesheet_url, 0, 1 ) && '//' !== substr( $stylesheet_url, 0, 2 ) ) {
$parsed_home_url = home_url();
if ( ! isset( $parsed_home_url['host'] ) ) {
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$parsed_home_url['host'] = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : 'localhost';
}

$stylesheet_origin = '//' . $parsed_home_url['host'];
if ( isset( $parsed_home_url['port'] ) ) {
$stylesheet_origin .= ':' . $parsed_home_url['port'];
}

$stylesheet_url = $stylesheet_origin . $stylesheet_url;
}

$stylesheet = false;
$css_file_path = $this->get_validated_url_file_path( $stylesheet_url, [ 'css', 'less', 'scss', 'sass' ] );
if ( ! is_wp_error( $css_file_path ) ) {
Expand Down

0 comments on commit 027b325

Please sign in to comment.