Make WordPress Core

Changeset 60657


Ignore:
Timestamp:
08/23/2025 02:06:57 PM (4 months ago)
Author:
SergeyBiryukov
Message:

Security: Set the frame-ancestors directive in send_frame_options_header().

The X-Frame-Options HTTP response header is a way of controlling whether and how a document may be loaded inside of a child navigable. For sites using Content-Security-Policy, the frame-ancestors directive provides more granular control over the same situations.

Includes adding a headers_sent() check before sending the headers.

References:

Follow-up to [17826].

Props danielbachhuber, killerbishop, callumbw95, josephscott, nacin, chriscct7, iandunn, SergeyBiryukov.
Fixes #29429.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r60416 r60657  
    71407140 * @since 3.1.3
    71417141 *
    7142  * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options
     7142 * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-Frame-Options
     7143 * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Security-Policy/frame-ancestors
    71437144 */
    71447145function send_frame_options_header() {
    7145     header( 'X-Frame-Options: SAMEORIGIN' );
     7146    if ( ! headers_sent() ) {
     7147        header( 'X-Frame-Options: SAMEORIGIN' );
     7148        header( "Content-Security-Policy: frame-ancestors 'self';" );
     7149    }
    71467150}
    71477151
Note: See TracChangeset for help on using the changeset viewer.