Skip to content

Commit

Permalink
Add validations to prevent 500s with malformed URLs (#529)
Browse files Browse the repository at this point in the history
* Add validations to prevent 500s with malformed URLs.

* Use built-in Flask type validators.J
  • Loading branch information
fpereiro authored Jun 24, 2021
1 parent a4594ab commit 214e3e4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 4 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,8 @@ def index(level, step):
adventure_name=adventure_name)

@app.route('/onlinemasters', methods=['GET'], defaults={'level': 1, 'step': 1})
@app.route('/onlinemasters/<level>', methods=['GET'], defaults={'step': 1})
@app.route('/onlinemasters/<level>/<step>', methods=['GET'])
@app.route('/onlinemasters/<int:level>', methods=['GET'], defaults={'step': 1})
@app.route('/onlinemasters/<int:level>/<int:step>', methods=['GET'])
def onlinemasters(level, step):
g.level = level = int(level)
g.lang = lang = requested_lang()
Expand All @@ -547,8 +547,8 @@ def onlinemasters(level, step):
adventure_name='')

@app.route('/space_eu', methods=['GET'], defaults={'level': 1, 'step': 1})
@app.route('/space_eu/<level>', methods=['GET'], defaults={'step': 1})
@app.route('/space_eu/<level>/<step>', methods=['GET'])
@app.route('/space_eu/<int:level>', methods=['GET'], defaults={'step': 1})
@app.route('/space_eu/<int:level>/<int:step>', methods=['GET'])
def space_eu(level, step):
g.level = level = int(level)
g.lang = requested_lang()
Expand Down
4 changes: 3 additions & 1 deletion website/querylog.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ def finish_global_log_record(exc=None):

def log_value(**kwargs):
"""Log values into the currently globally active Log Record."""
THREAD_LOCAL.current_log_record.set(**kwargs)
if hasattr(THREAD_LOCAL, 'current_log_record'):
# For some malformed URLs, the records are not initialized, so we check whether there's a current_log_record
THREAD_LOCAL.current_log_record.set(**kwargs)


def log_time(name):
Expand Down

0 comments on commit 214e3e4

Please sign in to comment.