Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django remote user authentication and security

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.

like image 528
Andrea Avatar asked Mar 01 '12 11:03

Andrea


People also ask

How do I authenticate users in Django?

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.

How secure is Django authentication?

Django Final Rating: 4.5/5 Django takes care of many common security issues and developers should feel pretty good using it.

How does Django login authentication work?

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.

Should I use Django authentication?

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.


1 Answers

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.

like image 168
David Horn Avatar answered Sep 28 '22 23:09

David Horn