Making WordPress.org


Ignore:
Timestamp:
07/29/2026 06:33:11 PM (4 months ago)
Author:
obenland
Message:

Trac oEmbed: Match the Core and Meta Trac hosts exactly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/api.wordpress.org/public_html/dotorg/trac/oembed/index.php

    r14530 r15019  
    1111 *
    1212 * Can be enabled on a site by adding:
    13  *  - wp_oembed_add_provider( '#https://(meta|core)\.trac\.wordpress.org/.*#', 'https://api.wordpress.org/dotorg/trac/oembed/?api_key=...' );
     13 *  - wp_oembed_add_provider( '#https://(meta|core)\.trac\.wordpress\.org/.*#', 'https://api.wordpress.org/dotorg/trac/oembed/?api_key=...', true );
    1414 *
    1515 * oEmbed Discovery is not enabled, as although adding the tag to trac is possible, it requires inline Javascript.
    … …  
    2525header( 'X-WP-Embed: true' );
    2626
    27 $url = $_REQUEST['url'] ?? '';
     27$url = $_GET['url'] ?? '';
    2828$url = is_string( $url ) ? wp_unslash( $url ) : '';
    2929
    3030header( 'Allow: GET' );
    3131header( 'Expires: ' . gmdate( 'D, d M Y H:i:s \G\M\T', time() + HOUR_IN_SECONDS ), true );
     32
     33// meta|core are the only tracs embedable.
     34$allowed_hosts = [
     35        'core.trac.wordpress.org',
     36        'meta.trac.wordpress.org',
     37];
    3238
    3339if (
    3440        ! $url ||
    3541        'GET' !== $_SERVER['REQUEST_METHOD'] ||
    36         // meta|core are the only tracs embedable.
    37         // milestone|ticketgraph|ticket|changeset are the only endpoints allowable.
    38         ! (
    39                 preg_match( '!^(?P<baseurl>https://(?P<trac>meta|core).trac.wordpress.org/)(?P<type>ticket|changeset)/\d+$!i', $url, $m ) ||
    40                 preg_match( '!^(?P<baseurl>https://(?P<trac>meta|core).trac.wordpress.org/)(?P<type>query)[?].+$!i', $url, $m ) ||
    41                 preg_match( '!^(?P<baseurl>https://(?P<trac>meta|core).trac.wordpress.org/)(?P<type>milestone)/[a-z0-9.]+[ ]?[a-z0-9.]*$!i', $url, $m ) ||
    42                 preg_match( '!^(?P<baseurl>https://(?P<trac>meta|core).trac.wordpress.org/)(?P<type>ticketgraph)([?]component=[^&]+)?$!i', $url, $m )
    43         )
     42        ! in_array( strtolower( (string) wp_parse_url( $url, PHP_URL_HOST ) ), $allowed_hosts, true )
    4443) {
     44        header( 'HTTP/1.1 404 Not Found', true, 404 );
     45        die();
     46}
     47
     48// milestone|ticketgraph|ticket|changeset are the only endpoints allowable.
     49$trac_baseurl = '^(?P<baseurl>https://(?P<trac>meta|core)\.trac\.wordpress\.org/)';
     50$allowed_urls = [
     51        '!' . $trac_baseurl . '(?P<type>ticket|changeset)/\d+$!iD',
     52        '!' . $trac_baseurl . '(?P<type>query)[?].+$!iD',
     53        '!' . $trac_baseurl . '(?P<type>milestone)/[a-z0-9.]+[ ]?[a-z0-9.]*$!iD',
     54        '!' . $trac_baseurl . '(?P<type>ticketgraph)([?]component=[^&]+)?$!iD',
     55];
     56
     57$m = [];
     58foreach ( $allowed_urls as $allowed_url ) {
     59        if ( preg_match( $allowed_url, $url, $m ) ) {
     60                break;
     61        }
     62}
     63
     64if ( ! $m ) {
    4565        header( 'HTTP/1.1 404 Not Found', true, 404 );
    4666        die();
    … …  
    117137        die();
    118138}
     139
     140// The remainder of this request outputs the HTML document displayed within the iframe.
     141header( 'Content-Type: text/html; charset=UTF-8' );
     142header( 'X-Content-Type-Options: nosniff' );
    119143
    120144$cache_key = sha1( $url );
Note: See TracChangeset for help on using the changeset viewer.