Code RoomTransfer CSRF unprotected
MediumPrep Room Coding #2177

Transfer CSRF unprotected

Code reviewSecurityMid–Senior~18 min

Review this Django view that transfers money between the logged-in user's accounts.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.

0:00 of about 18 min
Mark a line and say what kind of problem it is.0 findings
1from django.views.decorators.csrf import csrf_exempt
2from django.http import JsonResponse
3 
4@csrf_exempt
5def transfer(request):
6 if not request.user.is_authenticated:
7 return JsonResponse({'error': 'auth'}, status=401)
8 amount = request.POST['amount']
9 to_acct = request.POST['to']
10 request.user.wallet.send(to_acct, amount)
11 return JsonResponse({'ok': True})
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.