Skip to content

Commit e8dbfe3

Browse files
committed
move trusted host setting after validation of message
1 parent d482810 commit e8dbfe3

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

untrusted/run.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33

44
var localport = '8080'
55
var localhost = 'localhost:' + localport;
6-
var weblocs = [/^https:\/\/glowscript\.org$/, // put a couple of these explicitly in the list just in case.
6+
var weblocs = [
7+
/^https:\/\/glowscript\.org$/, // put a couple of these explicitly in the list just in case.
78
/^https:\/\/www\.glowscript\.org$/,
9+
/^https:\/\/devbasherwo\.org$/, // put a couple of these explicitly in the list just in case.
10+
/^https:\/\/www\.devbasherwo\.org$/,
811
new RegExp("^http:\/\/" + localhost + "$"),
912
/^https:\/\/HOST_NAME_TEMPLATE$/
1013
]
@@ -197,12 +200,12 @@ function ideRun() {
197200
send({ready:true})
198201
function receiveMessage(event) {
199202
event = event.originalEvent // originalEvent is a jquery entity
200-
let trimhost = event.origin.replace("sandbox.", "") // remove sandbox. if it's there
203+
// let trimhost = event.origin.replace("sandbox.", "") // remove sandbox. if it's there
201204
//trimhost = trimhost.replace("sandbox.", "") // remove www. if it's there
202-
trusted_origin = trimhost
205+
// trusted_origin = trimhost
203206
//console.log("in iFrame: receivedMessage from: " + event.origin)
204207
//console.log("Setting trusted_origin:" + trusted_origin)
205-
if (checkTrustedHosts(trusted_origin)) {
208+
if (checkTrustedHosts(event.origin)) {
206209
// ensure that message is from glowscript
207210
//console.log("rejecting origin!")
208211
return
@@ -213,6 +216,12 @@ function ideRun() {
213216
//console.log("in iFrame: receivedMessage: JSON parse error on " + event.data)
214217
return
215218
}
219+
220+
if ((trusted_origin === '*') && (event.origin.search('sandbox.') === -1)) {
221+
trusted_origin = event.origin
222+
//console.log("Setting trusted_origin:" + trusted_origin)
223+
}
224+
216225
if (message.program !== undefined) {
217226
// Determine the set of libraries to load
218227
var progver = message.version.substr(0,3) // 'unp' if unpackaged

0 commit comments

Comments
 (0)