Skip to content

Commit 47787e1

Browse files
Blaise Ritchiedeargle
authored andcommitted
Fix SSTI vulnerability in ad and consent pages (#517)
* Fix SSTI vulnerability in ad and consent pages Fixed an issue where users could pass arbitrary Python code to be executed on the server to the mode HTTP arg More information about this type of vulnerability: https://secure-cookie.io/attacks/ssti/
1 parent 231d566 commit 47787e1

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

psiturk/experiment.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,10 @@ def advertisement():
380380
# even have accepted the HIT.
381381
with open('templates/ad.html', 'r') as temp_file:
382382
ad_string = temp_file.read()
383-
ad_string = insert_mode(ad_string, mode)
383+
ad_string = insert_mode(ad_string)
384384
return render_template_string(
385385
ad_string,
386+
mode=mode,
386387
hitid=hit_id,
387388
assignmentid=assignment_id,
388389
workerid=worker_id
@@ -406,9 +407,10 @@ def give_consent():
406407
mode = request.args['mode']
407408
with open('templates/consent.html', 'r') as temp_file:
408409
consent_string = temp_file.read()
409-
consent_string = insert_mode(consent_string, mode)
410+
consent_string = insert_mode(consent_string)
410411
return render_template_string(
411412
consent_string,
413+
mode=mode,
412414
hitid=hit_id,
413415
assignmentid=assignment_id,
414416
workerid=worker_id
@@ -731,7 +733,7 @@ def ppid():
731733
# to avoid breaking backwards compatibility with old templates.
732734

733735

734-
def insert_mode(page_html, mode):
736+
def insert_mode(page_html):
735737
""" Insert mode """
736738
page_html = page_html
737739
match_found = False
@@ -740,7 +742,7 @@ def insert_mode(page_html, mode):
740742
for match in matches:
741743
match_found = True
742744
if match_found:
743-
new_html = page_html[:match.end()] + "&mode=" + mode +\
745+
new_html = page_html[:match.end()] + '&mode={{ mode }}' +\
744746
page_html[match.end():]
745747
return new_html
746748
else:

tests/test_psiturk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def test_insert_mode(psiturk_test_client):
141141
ad_string = temp_file.read()
142142

143143
from psiturk.experiment import insert_mode
144-
insert_mode(ad_string, 'debug')
144+
insert_mode(ad_string)
145145

146146

147147
class PsiTurkStandardTests(PsiturkUnitTest):

0 commit comments

Comments
 (0)