@@ -59,13 +59,23 @@ const SCRIPT_URL = "https://common.tools/static/sketch.js";
5959const STYLE_URL = "https://common.tools/static/main.css" ;
6060const IMG_URL = "https://common.tools/static/text.png" ;
6161const ORIGIN_URL = new URL ( globalThis . location . href ) . origin ;
62+ const BASE64_IMG_URL = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+ip1sAAAAASUVORK5CYII=" ;
6263
6364function openWindow ( target : any ) {
6465 return `<script>
6566 let win = window.open("${ HTML_URL } ", "${ target } ");
6667 if (win) throw new Error("Window Opened");</script>` ;
6768}
6869
70+ function clickAnchor ( target : string ) {
71+ return `
72+ <a id="anchor-test" href="${ HTML_URL } " target="${ target } ">
73+ <script>
74+ const anchor = document.querySelector("#anchor-test");
75+ anchor.click();
76+ </script>` ;
77+ }
78+
6979const cases = [ [
7080 "allows inline script" ,
7181 `<script>console.log("foo")</script><style>* { background-color: red; }</style><div>foo</div>` ,
@@ -78,6 +88,10 @@ const cases = [[
7888 "allows 1P img" ,
7989 `<img src="${ ORIGIN_URL } /foo.jpg" />` ,
8090 null ,
91+ ] , [
92+ "allows data: img" ,
93+ `<img src="${ BASE64_IMG_URL } " />` ,
94+ null ,
8195] , [
8296 "allows 1P CSS" ,
8397 `<link rel="stylesheet" href="${ ORIGIN_URL } /styles.css">` ,
@@ -98,6 +112,18 @@ const cases = [[
98112 "disallows opening windows (_top)" ,
99113 openWindow ( "_top" ) ,
100114 null ,
115+ ] , [
116+ "disallows anchor link target (_parent)" ,
117+ clickAnchor ( "_parent" ) ,
118+ null ,
119+ ] , [
120+ "disallows anchor link target (_self)" ,
121+ clickAnchor ( "_self" ) ,
122+ null ,
123+ ] , [
124+ "disallows anchor link target (_top)" ,
125+ clickAnchor ( "_top" ) ,
126+ null ,
101127] , [
102128 "disallows fetch" ,
103129 `<script>fetch("${ SCRIPT_URL } ");</script>` ,
@@ -161,6 +187,15 @@ const falseNegatives = [[
161187 "CSP:default-src" ,
162188] ] ;
163189
190+ // /!\ These tests do not report correctly.
191+ // /!\ Not sure why! But they appear to be allowed
192+ // /!\ but are not in practice.
193+ const falsePositives = [ [
194+ "Allows anchor link target (_blank)" ,
195+ clickAnchor ( "_blank" ) ,
196+ null ,
197+ ] ] ;
198+
164199const unknownStatuses = [
165200 [
166201 // `prerender` is a Chrome-only feature-flagged
@@ -178,6 +213,9 @@ for (const [name, html, expected] of cases) {
178213for ( const [ name , html , expected ] of falseNegatives ) {
179214 definePending ( name , html , expected ) ;
180215}
216+ for ( const [ name , html , expected ] of falsePositives ) {
217+ definePending ( name , html , expected ) ;
218+ }
181219for ( const [ name , html , expected ] of unknownStatuses ) {
182220 definePending ( name , html , expected ) ;
183221}
0 commit comments