Skip to content

Commit c42ac12

Browse files
Naman Jagdish Galabalasankarc
authored andcommitted
Fix when namespace_in_path is enabled and host URL is duplicated in URL
In cases where namespace_in_path is enabled and the host URL is duplicated in the URL path, users were being redirected to a malformed URL. This fix ensures that only the namespace is selected without including the forward slash (/), preventing unwanted URL redirects. Related: https://gitlab.com/gitlab-org/gitlab/-/issues/440465+ Changelog: fixed
1 parent b5a37cf commit c42ac12

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

files/gitlab-cookbooks/gitlab-pages/libraries/gitlab_pages.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,15 @@ def parse_namespace_in_path
150150
if [80, 443].include?(pages_port)
151151
{
152152
"~^#{url_scheme}://(projects\\.#{Gitlab['pages_nginx']['fqdn_regex']})/(.*)$" => "#{url_scheme}://$1/$2",
153-
"~^#{url_scheme}://(.*)\\.(#{Gitlab['pages_nginx']['fqdn_regex']})/(.*)$" => "#{url_scheme}://$2/$1/$3",
154-
"~^//(.*)\\.(#{Gitlab['pages_nginx']['fqdn_regex']})/(.*)$" => "/$1/$3",
153+
"~^#{url_scheme}://([^/]*)\\.(#{Gitlab['pages_nginx']['fqdn_regex']})/(.*)$" => "#{url_scheme}://$2/$1/$3",
154+
"~^//([^/]*)\\.(#{Gitlab['pages_nginx']['fqdn_regex']})/(.*)$" => "/$1/$3",
155155
"~^/(.*)$" => "/$namespace/$1",
156156
}
157157
else
158158
{
159159
"~^#{url_scheme}://(projects\\.#{Gitlab['pages_nginx']['fqdn_regex']}:#{pages_port})/(.*)$" => "#{url_scheme}://$1/$2",
160-
"~^#{url_scheme}://(.*)\\.(#{Gitlab['pages_nginx']['fqdn_regex']}:#{pages_port})/(.*)$" => "#{url_scheme}://$2/$1/$3",
161-
"~^//(.*)\\.(#{Gitlab['pages_nginx']['fqdn_regex']}:#{pages_port})/(.*)$" => "/$1/$3",
160+
"~^#{url_scheme}://([^/]*)\\.(#{Gitlab['pages_nginx']['fqdn_regex']}:#{pages_port})/(.*)$" => "#{url_scheme}://$2/$1/$3",
161+
"~^//([^/]*)\\.(#{Gitlab['pages_nginx']['fqdn_regex']}:#{pages_port})/(.*)$" => "/$1/$3",
162162
"~^/(.*)$" => "/$namespace/$1",
163163
}
164164
end

spec/chef/cookbooks/gitlab/recipes/nginx_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -919,8 +919,8 @@
919919
expect(content).to include('proxy_set_header Host $1.$http_host;')
920920
expect(content).to include('proxy_set_header X-Gitlab-Namespace-In-Path $namespace;')
921921
expect(content).to include('proxy_redirect ~^https://(projects\.pages\.localhost)/(.*)$ https://$1/$2;')
922-
expect(content).to include('proxy_redirect ~^https://(.*)\.(pages\.localhost)/(.*)$ https://$2/$1/$3;')
923-
expect(content).to include('proxy_redirect ~^//(.*)\.(pages\.localhost)/(.*)$ /$1/$3;')
922+
expect(content).to include('proxy_redirect ~^https://([^/]*)\.(pages\.localhost)/(.*)$ https://$2/$1/$3;')
923+
expect(content).to include('proxy_redirect ~^//([^/]*)\.(pages\.localhost)/(.*)$ /$1/$3;')
924924
expect(content).to include('proxy_redirect ~^/(.*)$ /$namespace/$1;')
925925
expect(content).to include('proxy_hide_header X-Gitlab-Namespace-In-Path;')
926926
# Below checks are to verify proper render entries are made
@@ -952,8 +952,8 @@
952952
expect(content).to include('proxy_set_header Host $1.$http_host;')
953953
expect(content).to include('proxy_set_header X-Gitlab-Namespace-In-Path $namespace;')
954954
expect(content).to include('proxy_redirect ~^https://(projects\.pages\.localhost:25800)/(.*)$ https://$1/$2;')
955-
expect(content).to include('proxy_redirect ~^https://(.*)\.(pages\.localhost:25800)/(.*)$ https://$2/$1/$3;')
956-
expect(content).to include('proxy_redirect ~^//(.*)\.(pages\.localhost:25800)/(.*)$ /$1/$3;')
955+
expect(content).to include('proxy_redirect ~^https://([^/]*)\.(pages\.localhost:25800)/(.*)$ https://$2/$1/$3;')
956+
expect(content).to include('proxy_redirect ~^//([^/]*)\.(pages\.localhost:25800)/(.*)$ /$1/$3;')
957957
expect(content).to include('proxy_redirect ~^/(.*)$ /$namespace/$1;')
958958
expect(content).to include('proxy_hide_header X-Gitlab-Namespace-In-Path;')
959959
# Below checks are to verify proper render entries are made
@@ -983,8 +983,8 @@
983983
expect(content).not_to include('proxy_set_header Host $1.$http_host;')
984984
expect(content).not_to include('proxy_set_header X-Gitlab-Namespace-In-Path $namespace;')
985985
expect(content).not_to include('proxy_redirect ~^https://(projects\.pages\.localhost)/(.*)$ https://$1/$2;')
986-
expect(content).not_to include('proxy_redirect ~^https://(.*)\.(pages\.localhost)/(.*)$ https://$2/$1/$3;')
987-
expect(content).not_to include('proxy_redirect ~^//(.*)\.(pages\.localhost)/(.*)$ /$1/$3;')
986+
expect(content).not_to include('proxy_redirect ~^https://([^/]*)\.(pages\.localhost)/(.*)$ https://$2/$1/$3;')
987+
expect(content).not_to include('proxy_redirect ~^//([^/]*)\.(pages\.localhost)/(.*)$ /$1/$3;')
988988
expect(content).not_to include('proxy_redirect ~^/(.*)$ /$namespace/$1;')
989989
expect(content).to include('proxy_hide_header X-Gitlab-Namespace-In-Path;')
990990
# Below checks are to verify proper render entries are made

0 commit comments

Comments
 (0)