@@ -177,28 +177,60 @@ RewriteRule ^.* - [F,L]
177177LoadModule authnz_pam_module modules/mod_authnz_pam.so
178178LoadModule intercept_form_submit_module modules/mod_intercept_form_submit.so
179179
180- <Location /mod_intercept_form_submit/>
181- ProxyPass https://backend.example.com/
180+ LoadModule session_crypto_module modules/mod_session_crypto.so
181+
182+ # Enable sessions
183+ Session On
184+ SessionMaxAge 300
185+ # Specify a passphrase to encrypt the session with
186+ SessionCryptoPassphrase replace-me-with-a-unique-secret
187+ # Enable cookie sessions
188+ SessionCookieName httpd_session path=/;httponly;secure;
189+ # Prevent cookies from reaching the backend
190+ SessionCookieRemove On
191+
192+ <Location /logout>
193+ # Allow the backend to adjust the session by setting headers
194+ SessionHeader HTTPDSession
195+ </Location>
196+
197+ <Location /login>
198+ # Allow the backend to adjust the session by setting headers
199+ SessionHeader HTTPDSession
182200
183201 # Defined in /etc/pam.d/httpd-pam
184202 InterceptFormPAMService httpd-pam
185-
186203 # Use the httpd_username/httpd_password fields from the login POST
187204 InterceptFormLogin httpd_username
188205 InterceptFormPassword httpd_password
189-
190206 # Automatically append the correct realm
191- InterceptFormLoginRealms EXAMPLE.COM
192-
193- # Show the login page for GET requests
194- RewriteCond %{REQUEST_METHOD} GET
195- RewriteRule ^.*$ /login.html [L]
196-
197- # Set the request header from the envvar if it exists
198- RequestHeader set Remote-User %{REMOTE_USER}s env=REMOTE_USER
207+ InterceptFormLoginRealms AUTH.EXAMPLE.COM
199208</Location>
200209
201-
210+ <Location /mod_intercept_form_submit/>
211+ # Surface the session as an apache envvar
212+ SessionEnv On
213+
214+ # extract the encoded username (via a URL-based lookahead, since HTTP_SESSION is populated later in the request handling)
215+ RewriteCond %{LA-U:ENV:HTTP_SESSION} ^(.*&)?httpd_user=([^&]+)(&.*)?$
216+ # and store it an an envvar
217+ RewriteRule .* - [E=ENCODED_SESSION_USER:%2]
218+
219+ # if we don't have a session user
220+ RewriteCond %{ENV:ENCODED_SESSION_USER} ^$
221+ # capture the raw request URL path and query
222+ RewriteCond %{THE_REQUEST} ^[^\s]+\ ([^\s]+)
223+ # and redirect to the login path with a back link to our current URL
224+ # NE = don't double-encode
225+ # B = encode the backreference
226+ # R = redirect with 302 code
227+ # L = stop processing
228+ RewriteRule .* /login/?then=%1 [NE,B,R=302,L]
229+
230+ # Set the session user into a request header and proxy
231+ RequestHeader set Remote-User "expr=%{unescape:%{env:ENCODED_SESSION_USER}}" env=ENCODED_SESSION_USER
232+ ProxyPass https://backend.example.com/
233+ </Location>
202234
203235RequestHeader unset Remote-User
204236RequestHeader unset X-Remote-User
0 commit comments