File tree 2 files changed +36
-0
lines changed 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -77,6 +77,7 @@ export class JSONHandler {
77
77
78
78
response . setStatusLine ( request . httpVersion , 200 , "OK" ) ;
79
79
response . setHeader ( "Content-Type" , "application/json" ) ;
80
+ response . setHeader ( "Content-Security-Policy" , "frame-ancestors 'none'" ) ;
80
81
response . write ( payload ) ;
81
82
} catch ( e ) {
82
83
new lazy . RemoteAgentError ( e ) . notify ( ) ;
Original file line number Diff line number Diff line change @@ -95,6 +95,41 @@ add_task(async function json_list({ client }) {
95
95
}
96
96
} ) ;
97
97
98
+ add_task ( async function json_prevent_load_in_iframe ( { client } ) {
99
+ const { Page } = client ;
100
+
101
+ const PAGE = `https://example.com/document-builder.sjs?html=${ encodeURIComponent (
102
+ '<iframe src="http://localhost:9222/json/version"></iframe>`'
103
+ ) } `;
104
+
105
+ await Page . enable ( ) ;
106
+
107
+ const NAVIGATED = "Page.frameNavigated" ;
108
+
109
+ const history = new RecordEvents ( 2 ) ;
110
+ history . addRecorder ( {
111
+ event : Page . frameNavigated ,
112
+ eventName : NAVIGATED ,
113
+ messageFn : payload => {
114
+ return `Received ${ NAVIGATED } for frame id ${ payload . frame . id } ` ;
115
+ } ,
116
+ } ) ;
117
+
118
+ await loadURL ( PAGE ) ;
119
+
120
+ const frameNavigatedEvents = await history . record ( ) ;
121
+
122
+ const frames = frameNavigatedEvents
123
+ . map ( ( { payload } ) => payload . frame )
124
+ . filter ( frame => frame . parentId !== undefined ) ;
125
+
126
+ const windowGlobal = BrowsingContext . get ( frames [ 0 ] . id ) . currentWindowGlobal ;
127
+ ok (
128
+ windowGlobal . documentURI . spec . startsWith ( "about:neterror?e=cspBlocked" ) ,
129
+ "Expected page not be loaded within an iframe"
130
+ ) ;
131
+ } ) ;
132
+
98
133
async function requestJSON ( path ) {
99
134
const response = await fetch ( `http://${ RemoteAgent . debuggerAddress } ${ path } ` ) ;
100
135
is ( response . status , 200 , "JSON response is 200" ) ;
You can’t perform that action at this time.
0 commit comments