Skip to content

Commit d482810

Browse files
committed
strip out sandbox in domain if present
1 parent 56ec11f commit d482810

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

ide/routes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def idejs_static():
176176
ide_js = ide_js.replace('WEBSERVER_NAME_TEMPLATE',host_name)
177177
ide_js = ide_js.replace('SANDBOX_PREFIX_TEMPLATE','https://sandbox.')
178178

179-
return ide_js,200
179+
return flask.Response(ide_js, mimetype='text/javascript')
180180

181181
@app.route('/lib/<path:filename>')
182182
def lib_static(filename):
@@ -209,7 +209,7 @@ def untrusted_static(filename):
209209
if host_name.startswith('sandbox.'):
210210
host_name = '.'.join(host_name.split('.')[1:]) # take off the sandbox.
211211
run_js = run_js.replace('HOST_NAME_TEMPLATE',host_name)
212-
return run_js, 200, {'content_type':'text/plain'}
212+
return flask.Response(run_js, mimetype='text/javascript')
213213

214214
return flask.send_from_directory('../untrusted', filename)
215215

untrusted/run.js

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ var weblocs = [/^https:\/\/glowscript\.org$/, // put a couple of these explicitl
99
/^https:\/\/HOST_NAME_TEMPLATE$/
1010
]
1111

12-
function checkTrustedHosts(aHost) { // go through the known trusted hosts
13-
let found = false;
14-
let trimhost = aHost.replace('www.','') // remove www. if it's there
15-
//console.log("checking trusted hosts:" + aHost);
16-
for (let i = 0; i < weblocs.length; i++) {
17-
found = trimhost.match(weblocs[i]);
18-
if (found) {
19-
break;
20-
}
12+
function checkTrustedHosts(aHost) {
13+
// go through the known trusted hosts
14+
let found = false
15+
//console.log("checking trusted hosts as:", aHost)
16+
for (let i = 0; i < weblocs.length; i++) {
17+
found = aHost.match(weblocs[i])
18+
if (found) {
19+
break
2120
}
22-
//console.log("Found =" + found);
23-
return !found; // return true to bail out.
21+
}
22+
//console.log("Found =" + found)
23+
return !found // return true to bail out.
2424
}
2525

2626
window.glowscript_libraries = { // used for unpackaged (X.Ydev) version
@@ -197,12 +197,22 @@ function ideRun() {
197197
send({ready:true})
198198
function receiveMessage(event) {
199199
event = event.originalEvent // originalEvent is a jquery entity
200-
trusted_origin = event.origin
200+
let trimhost = event.origin.replace("sandbox.", "") // remove sandbox. if it's there
201+
//trimhost = trimhost.replace("sandbox.", "") // remove www. if it's there
202+
trusted_origin = trimhost
203+
//console.log("in iFrame: receivedMessage from: " + event.origin)
201204
//console.log("Setting trusted_origin:" + trusted_origin)
202-
if (checkTrustedHosts(trusted_origin)) { // ensure that message is from glowscript
203-
return;
205+
if (checkTrustedHosts(trusted_origin)) {
206+
// ensure that message is from glowscript
207+
//console.log("rejecting origin!")
208+
return
209+
}
210+
try {
211+
var message = JSON.parse(event.data)
212+
} catch (err) {
213+
//console.log("in iFrame: receivedMessage: JSON parse error on " + event.data)
214+
return
204215
}
205-
var message = JSON.parse(event.data)
206216
if (message.program !== undefined) {
207217
// Determine the set of libraries to load
208218
var progver = message.version.substr(0,3) // 'unp' if unpackaged
@@ -312,6 +322,9 @@ function ideRun() {
312322

313323
function screenshot(isAuto) {
314324
var scene
325+
if (!canvas.activated) {
326+
return
327+
}
315328
for (var c = 0; c < canvas.activated.length; c++) {
316329
var ca = canvas.activated[c]
317330
if (ca !== null) {

0 commit comments

Comments
 (0)