Skip to content
  • Stan Hu's avatar
    Fix HTTP to HTTPS redirection not working for default domains · 7d8bfba8
    Stan Hu authored
    If a default domain is in use, the group domain will be passed into the
    IsHTTPSOnly() call, but this will always return false because the HTTPS-only
    flag can only be determined by looking at the HTTP request host rather than
    the URL.
    
    For example, for the project https://gitlab.com/tanukitalks/tanukitalks.gitlab.io,
    this is what happened previously:
    
    1. For a project in the default domain (e.g. `gitlab.io`), GitLab Pages loads
    `config.json` and sees the group is `tanukitalks` with the project name
    `tanuitalks.gitlab.io`. It stores the HTTPS-only flag inside the project
    config.
    
    2. Note that for projects in the default domain, the `domainConfig` is
    empty. This makes sense because there is no domain configuration specified
    since the default domain is being used, and we need to redirect on a
    project-by-project basis.
    
    3. User requests https://tanukitalks.gitlab.io.
    
    4. GitLab Pages looks up `tanukitalks.gitlab.io`, and it returns the domain
    `tanukitalks` with an empty `domainConfig` and project `tanukitalks.gitlab.io`.
    
    5. Since there is no `domainConfig`, `IsHTTPSOnly` attempts to resolve the
    project from the URL.
    
    6. However, since the URL is using the default domain, the path is `/`, which
    doesn't resolve to any project.
    
    In the new behavior, we check the hostname of the request to see if it matches
    any project before trying to parse the URL.
    
    Closes #162
    7d8bfba8
Loading