File tree Expand file tree Collapse file tree 1 file changed +24
-4
lines changed Expand file tree Collapse file tree 1 file changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -29,14 +29,18 @@ $ = function (f) {
29
29
30
30
Handlebars . templates . signature = Handlebars . compile ( '{{sanitize signature}}' ) ;
31
31
32
- var url = "../model/openapi/api.yaml" ;
33
- if ( window . location . search != "?url=" + url ) {
34
- window . location . search = "?url=" + url ;
35
- }
32
+ var url = new URL ( window . location ) . searchParams . get ( 'url' )
33
+
36
34
if ( ! url ) {
37
35
alert ( 'Please specify the API to display using the "url" query parameter.\nE.g. ' + location . origin + location . pathname + '?url=/src/openapi/api.yaml' ) ;
38
36
return ;
39
37
}
38
+
39
+ var fallbackUrl = "../model/openapi/api.yaml" ;
40
+ if ( ! isValidUrl ( url ) ) {
41
+ window . location . search = "?url=" + fallbackUrl ;
42
+ }
43
+
40
44
if ( ! window . fetch ) {
41
45
alert ( 'Please use a Browser.\nIt should at least support "fetch".' ) ;
42
46
return ;
@@ -112,6 +116,22 @@ $ = function (f) {
112
116
)
113
117
}
114
118
119
+ function isValidUrl ( referencedUrl ) {
120
+ // must be relative url
121
+ if ( ! referencedUrl . startsWith ( '../' ) ) {
122
+ return false ;
123
+ }
124
+ // only allow referencing max two parent directories
125
+ var matches = referencedUrl . match ( / \. \. \/ / g) ;
126
+ if ( matches && matches . length > 2 ) {
127
+ return false ;
128
+ }
129
+
130
+ // additional check
131
+ var referencedAbsoluteUrl = getAbsoluteUrl ( referencedUrl )
132
+ return new URL ( referencedAbsoluteUrl ) . origin == new URL ( location . href ) . origin
133
+ }
134
+
115
135
function isLocalSchema ( models , schema ) {
116
136
return _ . any ( models , function ( m ) {
117
137
return normalize ( schema . extra . filename ) === normalize ( m ) ;
You can’t perform that action at this time.
0 commit comments