qvest-digital / loginsrv

JWT login microservice with plugable backends such as OAuth2, Google, Github, htpasswd, osiam, ..
MIT License
1.92k stars 150 forks source link

Redirect is not working #181

Closed averri closed 3 years ago

averri commented 3 years ago

I have the following configuration as part of my docker-compose.yml:

  auth:
    image: tarent/loginsrv
    container_name: auth
    volumes:
      - ./config/users.yml:/config/users.yml
    environment:
      - COOKIE_SECURE=true
      - LOGINSRV_COOKIE_DOMAIN=mydomain.com
      - LOGINSRV_JWT_SECRET=${LOGINSRV_JWT_SECRET}
      - LOGINSRV_GOOGLE=client_id=${GOOGLE_CLIENT_ID},client_secret=${GOOGLE_CLIENT_SECRET}
      - LOGINSRV_USER_FILE=/config/users.yml
      - LOGINSRV_REDIRECT=true
      - LOGINSRV_REDIRECT_QUERY_PARAMETER=redirect_url
      - LOGINSRV_SUCCESS_URL=https://home.mydomain.com
      - LOGINSRV_REDIRECT_CHECK_REFERER=false
    restart: unless-stopped
    network_mode: service:gluetun
    depends_on:
      - gluetun

This is the sequence of operations:

  1. When accessing the protected subdomain board.mydomain.com, the webserver redirects to the login page with the query parameter redirect_url in order to go back to the original page. The login page is correctly presented from the URL https://auth.mydomain.com/login?redirect_url=https%3A%2F%2Fboard.mydomain.com%2F.
  2. After authenticating with Google, the browser goes back to https://home.mydomain.com instead of the https://board.mydomain.com.

The following URIs are authorized in Google developer console:

averri commented 3 years ago

I have noticed that the environment variable LOGINSRV_REDIRECT_HOST_FILE is mandatory for the dynamic redirect to work, and this is a great security feature.

After changing to the following configuration, the dynamic redirects are working fine.

  auth:
    image: tarent/loginsrv
    container_name: auth
    volumes:
      - ./config/auth/:/config/
    environment:
      - COOKIE_SECURE=true
      - LOGINSRV_COOKIE_DOMAIN=${DOMAIN}
      - LOGINSRV_JWT_SECRET=${LOGINSRV_JWT_SECRET}
      - LOGINSRV_GOOGLE=client_id=${GOOGLE_CLIENT_ID},client_secret=${GOOGLE_CLIENT_SECRET}
      - LOGINSRV_USER_FILE=/config/users.yml
      - LOGINSRV_REDIRECT=true
      - LOGINSRV_REDIRECT_QUERY_PARAMETER=redirect_url
      - LOGINSRV_REDIRECT_HOST_FILE=/config/allowed_redirects.txt
      - LOGINSRV_SUCCESS_URL=${LOGINSRV_SUCCESS_URL}
      - LOGINSRV_REDIRECT_CHECK_REFERER=false
    restart: unless-stopped
    network_mode: service:gluetun
    depends_on:
      - gluetun