Skip to content

Enable HSTS for GitLab Pages - #3295

Open
loglapa wants to merge 1 commit into
sameersbn:masterfrom
loglapa:agent/enable-hsts-for-pages
Open

Enable HSTS for GitLab Pages#3295
loglapa wants to merge 1 commit into
sameersbn:masterfrom
loglapa:agent/enable-hsts-for-pages

Conversation

@loglapa

@loglapa loglapa commented Aug 20, 2026

Copy link
Copy Markdown

What changed

  • Add the existing HSTS header template to both GitLab Pages nginx configurations.
  • Render the configured NGINX_HSTS_MAXAGE when Pages HTTPS is enabled.
  • Remove the header when Pages HTTPS or NGINX_HSTS_ENABLED is disabled.
  • Clarify in the README that the existing HSTS options also apply to GitLab Pages.

Why

The main GitLab nginx virtual host honors NGINX_HSTS_ENABLED and NGINX_HSTS_MAXAGE, but the Pages virtual hosts do not contain or configure the header. Changing those options therefore has no effect on Pages responses.

The non-TLS Pages template also needs the placeholder for deployments where TLS terminates at a load balancer while GITLAB_PAGES_HTTPS=true, matching the existing main GitLab virtual host behavior.

Impact

GitLab Pages responses now use the same HSTS settings as the main GitLab virtual host, without adding new environment variables or changing the defaults.

Validation

  • bash -n assets/runtime/functions
  • git diff --check
  • Rendered and checked four cases: native Pages HTTPS, HSTS disabled, plain HTTP, and HTTPS terminated by a proxy

Fixes #2710

@loglapa
loglapa marked this pull request as ready for review August 20, 2026 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The NGINX_HSTS_ENABLED setting is not valid for Pages

1 participant