Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions src/deps/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@ $ = function (f) {

Handlebars.templates.signature = Handlebars.compile('{{sanitize signature}}');

var url = "../model/openapi/api.yaml";
if(window.location.search !="?url="+url) {
window.location.search = "?url="+url;
}
var url = new URL(window.location).searchParams.get('url')

if (!url) {
alert('Please specify the API to display using the "url" query parameter.\nE.g. ' + location.origin + location.pathname + '?url=/src/openapi/api.yaml');
return;
}

var fallbackUrl = "../model/openapi/api.yaml";
if(!isValidUrl(url)) {
window.location.search = "?url="+fallbackUrl;
}

if (!window.fetch) {
alert('Please use a Browser.\nIt should at least support "fetch".');
return;
Expand Down Expand Up @@ -112,6 +116,22 @@ $ = function (f) {
)
}

function isValidUrl(referencedUrl){
// must be relative url
if(!referencedUrl.startsWith('../')){
return false;
}
// only allow referencing max two parent directories
var matches = referencedUrl.match(/\.\.\//g);
if(matches && matches.length > 2){
return false;
}

// additional check
var referencedAbsoluteUrl = getAbsoluteUrl(referencedUrl)
return new URL(referencedAbsoluteUrl).origin == new URL(location.href).origin
}

function isLocalSchema(models, schema) {
return _.any(models, function (m) {
return normalize(schema.extra.filename) === normalize(m);
Expand Down
Loading