phusion / passenger_library

Phusion Passenger documentation

Home Page:https://www.phusionpassenger.com/docs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Passenger doesn't handle ErrorDocument 401 with form_method

CodeGuro opened this issue · comments

I came across this issue when I was playing with phusion for a bit...

Consider the following configuration in apache...

		<Location "/secure">
			Require valid-user
			AuthName "top secret"
			AuthFormProvider wsgi
			AuthType form
			WSGIAuthUserScript /path/to/authenticator.py
			ErrorDocument 401 "/index"
			AuthFormMethod form_method
			AuthFormBody form_body
			AuthFormMimetype form_mimetype
			AuthFormUsername form_username
			AuthFormPassword form_passwd
			WSGIPassAuthorization On
		</Location>

The idea here being, I'm coupling apache-phusion form authentication from some custom script (authenticator.py) for an inline login, so that mod_auth_form handles authentication cookies for login sessions. When someone tries to access a sub-url www.example.com/secure/some_file, mod_auth_form would kick in and insert the 401 document for some other location (/index) served by passenger for an inline-login. The intent being that the authenticator script is run and, if successful, the previous request is forwarded to whatever secure sub location the client originally tried to access earlier.

Logging in with the correct credentials works fine - passenger forwards the request as expected. The issue happens with incorrect credentials. Namely, the POST request never returns and the browser/client just hangs on an eternal loading page (until phusion-passenger or apache is restarted). It's as if passenger connects to the socket but doesn't ever forward it to the WSGI application and instead hangs on to it forever. This behaviour does not happen when the ErrorDocument isn't served by passenger. This makes it quite annoying to work with because it'd mean I'd need to make at least 2 application groups... one served by passenger for general views and one served by plain WSGI for the inline login which serves the ErrorDocument views without going through passenger.

For reference (here are the docs), my authenticator script:

def check_password(environ, user, password):
    if user == 'tester':
        if password == 'tester':
            return True
        return False
    return None

...and the HTML served by the web-application, minimal example:

<html>
<body>
<form method="POST" action="" name="form_body">
User Name: <input name="form_username"><br>
Password: <input name="form_passwd" type="password"></br>
<input type="hidden" name="form_mimetype" value="application/x-www-form-urlencoded">
<input type="hidden" name="form_method" value="POST">
<input type="hidden" name="form_body" value="name1=value1&name2=value2">
<input type="submit" value="submit">
</form>
</body>
</html>

Also, this seems to be an issue exclusive to form authentication. The basic authenticator (and others) don't seem to hang.

I realized this was the wrong place to post this issue. Closing this issue, re-opening in the appropriate repository at phusion/passenger#2231