@@ -2,6 +2,9 @@ import { defaultSuites } from "./tests.mjs";
2
2
import { params } from "./shared/params.mjs" ;
3
3
4
4
const DEFAULT_TAGS = [ "all" , "default" , "experimental" ] ;
5
+ const ALLOWED_DOMAINS = {
6
+ "app.netlify.com" : "/sites/webkit-speedometer-preview/" ,
7
+ } ;
5
8
6
9
// http://localhost:8080/?config=http://localhost:8080/resources/config.json
7
10
@@ -17,6 +20,45 @@ export class DataProvider{
17
20
return this . _suites ;
18
21
}
19
22
23
+ _containsAllowedUrl ( suite ) {
24
+ // 1. Check for relative URL
25
+ if ( ! suite . url . startsWith ( "http://" ) && ! suite . url . startsWith ( "https://" ) && ! suite . url . startsWith ( "//" ) && ! suite . url . startsWith ( "./" ) ) {
26
+ const baseUrl = "http://www.example.com" ;
27
+ try {
28
+ const parsedUrl = new URL ( suite . url , baseUrl ) ;
29
+ if ( parsedUrl . origin === baseUrl )
30
+ return true ;
31
+ } catch ( error ) {
32
+ return false ;
33
+ }
34
+ }
35
+
36
+ // 2. Check for localhost URL
37
+ if ( suite . url . startsWith ( "http://localhost:" ) || suite . url . startsWith ( "https://localhost:" ) ) {
38
+ try {
39
+ const parsedUrl = new URL ( suite . url ) ;
40
+ if ( parsedUrl . hostname === "localhost" )
41
+ return true ;
42
+
43
+ } catch ( e ) {
44
+ // Invalid URL format for localhost
45
+ }
46
+ return false ;
47
+ }
48
+
49
+ // 3. Check for allowed domains
50
+ try {
51
+ const parsedUrl = new URL ( suite . url ) ;
52
+ if ( ALLOWED_DOMAINS [ parsedUrl . hostname ] && ALLOWED_DOMAINS [ parsedUrl . hostname ] . includes ( parsedUrl . pathname ) )
53
+ return true ;
54
+
55
+ } catch ( e ) {
56
+ // invalid URL
57
+ }
58
+
59
+ return false ;
60
+ }
61
+
20
62
_freezeSuites ( ) {
21
63
Object . freeze ( this . _suites ) ;
22
64
this . _suites . forEach ( ( suite ) => {
@@ -43,7 +85,10 @@ export class DataProvider{
43
85
const config = await response . json ( ) ;
44
86
45
87
config . suites . flatMap ( ( suite ) => suite . tags ) . forEach ( tag => this . _tags . add ( tag ) ) ;
46
- config . suites . forEach ( suite => this . _suites . push ( suite ) ) ;
88
+ config . suites . forEach ( suite => {
89
+ if ( this . _containsAllowedUrl ( suite ) )
90
+ this . _suites . push ( suite ) ;
91
+ } ) ;
47
92
} else {
48
93
defaultSuites . flatMap ( ( suite ) => suite . tags ) . forEach ( tag => this . _tags . add ( tag ) ) ;
49
94
defaultSuites . forEach ( suite => this . _suites . push ( suite ) ) ;
0 commit comments