smengcl commented on code in PR #10809:
URL: https://github.com/apache/ozone/pull/10809#discussion_r3644399437


##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/VirtualHostStyleFilter.java:
##########
@@ -143,11 +144,21 @@ private String getDomainName(String host) {
     return match;
   }
 
-  private String checkHostWithoutPort(String host) {
-    int portIndex = host.lastIndexOf(':');
-    if (portIndex >= 0) {
-      return host.substring(0, portIndex);
-    } else {
+  /**
+   * Strips a trailing port from the Host header, if present. Uses 
bracket-aware
+   * parsing so IPv6 literals are handled correctly: {@code [::1]:9878} and
+   * {@code [::1]} both yield {@code ::1}, and a bare {@code 2001:db8::1} 
(whose
+   * colons are part of the address, not a port) is returned unchanged. A plain
+   * {@code lastIndexOf(':')} would mistake an address segment for the port.
+   */
+  @VisibleForTesting
+  String checkHostWithoutPort(String host) {
+    try {
+      return HostAndPort.fromString(host).getHost();

Review Comment:
   getHost() normalizes [::1]:9878 to ::1, but getDomainName() compares this 
with the raw values from `ozone.s3g.domain.name`. Consequently, a configuration 
of [::1] that the parent accepts with Host: [::1]:9878 no longer matches.
   
   Please normalize configured IPv6 values to the same unbracketed form, 
ideally accepting both bracketed and unbracketed configuration inputs, and add 
filter-level tests covering both forms.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to