Making WordPress.org

Changeset 15149


Ignore:
Timestamp:
09/04/2026 08:28:19 PM (2 weeks ago)
Author:
obenland
Message:

Trac oEmbed: Apply the iframe's sandbox flags to the embed response

Closes https://github.com/WordPress/wordpress.org/pull/876.

File:
1 edited

Legend:

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

    r15098 r15149  
    150150header( 'X-Content-Type-Options: nosniff' );
    151151
     152/*
     153 * The iframe's sandbox covers that element, not this response, which is reachable directly.
     154 * Re-serving third-party markup is the point of this endpoint, so the sandbox is the boundary
     155 * rather than the markup: the document cannot act as this origin, and it shows nothing the Trac
     156 * URL it mirrors does not already show to the same audience.
     157 */
     158header( 'Content-Security-Policy: sandbox allow-scripts allow-top-navigation-by-user-activation' );
     159
    152160$cache_key = sha1( $url );
    153161if ( $data = wp_cache_get( $cache_key, 'trac-oembed' ) ) {
     
    309317$js = <<<JS
    310318(function() {
     319        if ( window.parent === window ) {
     320                return;
     321        }
     322
    311323        var id = ( document.location.hash.match(/el=([0-9a-f]+)(&|$)/) || [ '', '' ] )[1];
    312324
     
    324336})();
    325337JS;
    326 $doc->getElementsByTagName( 'head' )[0]->appendChild( $doc->createElement( 'script', $js ) );
     338
     339$reporter = $doc->createElement( 'script' );
     340$reporter->appendChild( $doc->createTextNode( $js ) );
     341$doc->getElementsByTagName( 'head' )[0]->appendChild( $reporter );
    327342
    328343$css = <<<CSS
Note: See TracChangeset for help on using the changeset viewer.