I am trying to setup an API using Django. In my views.py, I have this endpoint:
@api_view()
def update_label(request):
user_id = request.query_params['user_id']
date = datetime.strptime(request.query_params['date'], '%Y-%m-%dT%H:%M:%S.%f')
label_name = request.query_params['label_name']
value = request.query_params['value']
value = eval(value)
db_user_ctrl.update_label(date, user_id, label_name, value)
return Response({'status': 'SUCCESS'})
It updates some label in the database for some user. Multiple labels can be updated from this endpoint, some associate value with an integer, some associate value with a small dictionary e.g. {'item1':1,'item2':-1}. On the javascript side I use JSON.stringify(value) to format the value before sending it via a GET request. On the Django part, I can see the proper parameters have been recieved through the debugging interface. However I have the following error:
invalid literal for int() with base 10: '{"item1":-1}'
Associated with this line in my code:
value = request.query_params['value']
What is happening here? Why is he trying to casting the string into an integer?
EDIT 1:
Some more info on the stack trace:
.../venv/lib/python3.4/site-packages/django/core/handlers/base.py in get_response
.../venv/lib/python3.4/site-packages/django/core/handlers/base.py in get_response
.../venv/lib/python3.4/site-packages/django/views/decorators/csrf.py in wrapped_view
.../venv/lib/python3.4/site-packages/django/views/generic/base.py in view
.../venv/lib/python3.4/site-packages/rest_framework/views.py in dispatch
.../venv/lib/python3.4/site-packages/rest_framework/views.py in dispatch
.../venv/lib/python3.4/site-packages/rest_framework/decorators.py in handler
.../webapp/api/views.py in update_label
value = request.query_params['value']
eval(value). Which you should not do, by the way, because you have a remote code execution problem right there.