fix: protect video transcript handler from scraper (#34017)
Web scrapers do annoying stuff like visit urls they shouldn't know about and cause xblock handlers to break. I tested this by: Making sure video transcripts worked as normal while logged in making sure that I got no 500s in my logs while attempting to view it logged out.
This commit is contained in:
@@ -315,6 +315,12 @@ class VideoStudentViewHandlers:
|
||||
if dispatch.startswith('translation'):
|
||||
language = dispatch.replace('translation', '').strip('/')
|
||||
|
||||
# Because scrapers hit video blocks, verify that a user exists.
|
||||
# use the _request attr to get the django request object.
|
||||
if not request._request.user: # pylint: disable=protected-access
|
||||
log.info("Transcript: user must be logged or public view enabled to get transcript")
|
||||
return Response(status=403)
|
||||
|
||||
if not language:
|
||||
log.info("Invalid /translation request: no language.")
|
||||
return Response(status=400)
|
||||
@@ -324,6 +330,7 @@ class VideoStudentViewHandlers:
|
||||
return Response(status=404)
|
||||
|
||||
if language != self.transcript_language:
|
||||
|
||||
self.transcript_language = language
|
||||
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user