I am using Django remote user authentication in a project. What I am actually using is just django.contrib.auth.RemoteUserBackend
without the middleware, and manually calling authenticate
after having checked with the backend that the user is legitimate.
Reading the source of the middleware, it seems that it just takes the username from a header in the request and then authenticates the user against the backend passing this username. The remote user backend, in turn, just merrily logs the user in with whatever username was passed. The user has then access to every area that requires a valid login.
Isn't this just a huge security flaw? How is this meant to be used?
In my case I should be safe, since the only call to authenticate
comes after a successful remote identity verification, but I am wondering the reason why the middleware was introduced.
auth import authenticate, login def my_view(request): username = request. POST['username'] password = request. POST['password'] user = authenticate(username=username, password=password) if user is not None: if user. is_active: login(request, user) # Redirect to a success page.
Django Final Rating: 4.5/5 Django takes care of many common security issues and developers should feel pretty good using it.
The Django authentication system handles both authentication and authorization. Briefly, authentication verifies a user is who they claim to be, and authorization determines what an authenticated user is allowed to do. Here the term authentication is used to refer to both tasks.
By extending the User model you can add additional fields and/or functions to the User model (for example, you can add an image, description, age, relationship status, etc.). Having said that, I really recommend using Django's authentication backend. It's well-tested and secure.
Let me turn this around on you: if you think this is a security flaw, then try writing an exploit that sets the REMOTE_USER
header in a request to your app and see what happens.
REMOTE_USER
dates back to the early days of the web when CGI pages were executed locally as the user you were hitting the web page with. REMOTE_USER
is actually the name of a unix environment variable that denotes the active user. As security models for web servers changed, this scheme was preserved for compatibility. Now even IIS supports it to transparently handle Active Directory logins.
All user-passed headers begin with HTTP_
. Otherwise, you couldn't trust on any header information, like SERVER_NAME
, which would be an enormous mess.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With