Skip to content

Commit 1ffab32

Browse files
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: * [https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-Frame-Options MDN Web Docs: X-Frame-Options header] * [https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Security-Policy/frame-ancestors MDN Web Docs: Content-Security-Policy: frame-ancestors directive] Follow-up to [17826]. Props danielbachhuber, killerbishop, callumbw95, josephscott, nacin, chriscct7, iandunn, SergeyBiryukov. Fixes #29429. git-svn-id: https://develop.svn.wordpress.org/trunk@60657 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 69a9d29 commit 1ffab32

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/wp-includes/functions.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7139,10 +7139,14 @@ function wp_find_hierarchy_loop_tortoise_hare( $callback, $start, $override = ar
71397139
*
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
*/
71447145
function 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

71487152
/**

0 commit comments

Comments
 (0)