Skip to content

Instantly share code, notes, and snippets.

@jwlin
Last active April 25, 2020 08:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwlin/c03ecc1fe90509fb1eafd814630ed422 to your computer and use it in GitHub Desktop.
Save jwlin/c03ecc1fe90509fb1eafd814630ed422 to your computer and use it in GitHub Desktop.
from django.http import HttpResponse
from django.shortcuts import get_object_or_404, render
from .models import Account, Client
def show(request):
uname = request.POST["uname"]
if "injection" in request.POST:
# Use raw SQL and string concatenation, resulting in SQL injection
accounts = Account.objects.raw(f'SELECT * FROM atm_account as a, atm_client as c WHERE a.client_id=c.id and c.username="{uname}"')
else:
# Use built-in ORM in Django
accounts = Account.objects.filter(client__username=uname)
return render(request, "atm/show.html", {"accounts": accounts})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment