Skip to content

Commit c50371f

Browse files
committed
Provide origin for stylesheet URLs which are absolute paths
1 parent c2a2f10 commit c50371f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

includes/sanitizers/class-amp-style-sanitizer.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,6 +1469,22 @@ private function process_link_element( DOMElement $element ) {
14691469
* @return string|WP_Error Stylesheet string on success, or WP_Error on failure.
14701470
*/
14711471
private function get_stylesheet_from_url( $stylesheet_url ) {
1472+
// For absolute paths, provide the origin (host and port).
1473+
if ( '/' === substr( $stylesheet_url, 0, 1 ) && '//' !== substr( $stylesheet_url, 0, 2 ) ) {
1474+
$parsed_home_url = wp_parse_url( home_url() );
1475+
if ( ! isset( $parsed_home_url['host'] ) ) {
1476+
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1477+
$parsed_home_url['host'] = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : 'localhost';
1478+
}
1479+
1480+
$stylesheet_origin = '//' . $parsed_home_url['host'];
1481+
if ( isset( $parsed_home_url['port'] ) ) {
1482+
$stylesheet_origin .= ':' . $parsed_home_url['port'];
1483+
}
1484+
1485+
$stylesheet_url = $stylesheet_origin . $stylesheet_url;
1486+
}
1487+
14721488
$stylesheet = false;
14731489
$css_file_path = $this->get_validated_url_file_path( $stylesheet_url, [ 'css', 'less', 'scss', 'sass' ] );
14741490
if ( ! is_wp_error( $css_file_path ) ) {

0 commit comments

Comments
 (0)