Skip to content

Commit

Permalink
Fix SSTI vulnerability in ad and consent pages (#517)
Browse files Browse the repository at this point in the history
* 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/
  • Loading branch information
Blaise Ritchie authored and deargle committed Oct 1, 2021
1 parent 231d566 commit 47787e1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions psiturk/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,10 @@ def advertisement():
# even have accepted the HIT.
with open('templates/ad.html', 'r') as temp_file:
ad_string = temp_file.read()
ad_string = insert_mode(ad_string, mode)
ad_string = insert_mode(ad_string)
return render_template_string(
ad_string,
mode=mode,
hitid=hit_id,
assignmentid=assignment_id,
workerid=worker_id
Expand All @@ -406,9 +407,10 @@ def give_consent():
mode = request.args['mode']
with open('templates/consent.html', 'r') as temp_file:
consent_string = temp_file.read()
consent_string = insert_mode(consent_string, mode)
consent_string = insert_mode(consent_string)
return render_template_string(
consent_string,
mode=mode,
hitid=hit_id,
assignmentid=assignment_id,
workerid=worker_id
Expand Down Expand Up @@ -731,7 +733,7 @@ def ppid():
# to avoid breaking backwards compatibility with old templates.


def insert_mode(page_html, mode):
def insert_mode(page_html):
""" Insert mode """
page_html = page_html
match_found = False
Expand All @@ -740,7 +742,7 @@ def insert_mode(page_html, mode):
for match in matches:
match_found = True
if match_found:
new_html = page_html[:match.end()] + "&mode=" + mode +\
new_html = page_html[:match.end()] + '&mode={{ mode }}' +\
page_html[match.end():]
return new_html
else:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_psiturk.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def test_insert_mode(psiturk_test_client):
ad_string = temp_file.read()

from psiturk.experiment import insert_mode
insert_mode(ad_string, 'debug')
insert_mode(ad_string)


class PsiTurkStandardTests(PsiturkUnitTest):
Expand Down

0 comments on commit 47787e1

Please sign in to comment.