@@ -1147,6 +1147,20 @@ func TestNormalizeHost(t *testing.T) {
11471147 // Upper-case + trailing dot.
11481148 {"API.GITHUB.COM." , "api.github.com" },
11491149 {"" , "" },
1150+ // Default port 443 should be stripped.
1151+ {"api.github.com:443" , "api.github.com" },
1152+ // Default port 80 should be stripped.
1153+ {"api.github.com:80" , "api.github.com" },
1154+ // Non-default port should be preserved.
1155+ {"api.github.com:8443" , "api.github.com:8443" },
1156+ // Port 443 + upper-case: both normalised.
1157+ {"API.GITHUB.COM:443" , "api.github.com" },
1158+ // Port 443 + trailing dot: trailing dot stripped then port stripped.
1159+ {"api.github.com.:443" , "api.github.com" },
1160+ // IPv6 with default port: brackets are stripped by net.SplitHostPort.
1161+ {"[::1]:443" , "::1" },
1162+ // IPv6 with non-default port: preserved (with brackets stripped by SplitHostPort).
1163+ {"[::1]:8080" , "[::1]:8080" },
11501164 }
11511165
11521166 for _ , tt := range tests {
@@ -1167,6 +1181,11 @@ func TestIsGitHubHost_CaseAndTrailingDot(t *testing.T) {
11671181 "API.GITHUB.COM." ,
11681182 "Raw.GitHubUserContent.com" ,
11691183 "UPLOADS.GITHUB.COM" ,
1184+ // Port variants: default port should be stripped before matching.
1185+ "api.github.com:443" ,
1186+ "API.GITHUB.COM:443" ,
1187+ "uploads.github.com:443" ,
1188+ "raw.githubusercontent.com:80" ,
11701189 }
11711190 for _ , h := range positives {
11721191 assert .True (t , isGitHubHost (h ), "expected %q to be allowed" , h )
@@ -1176,6 +1195,9 @@ func TestIsGitHubHost_CaseAndTrailingDot(t *testing.T) {
11761195 "GITHUB.EXAMPLE.COM" ,
11771196 "EXAMPLE.GITHUB.COM" ,
11781197 "github.com" ,
1198+ // Port variants on disallowed hosts should still be denied.
1199+ "github.example.com:443" ,
1200+ "example.github.com:443" ,
11791201 }
11801202 for _ , h := range negatives {
11811203 assert .False (t , isGitHubHost (h ), "expected %q to be denied" , h )
0 commit comments