You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "navinko (via GitHub)" <gi...@apache.org> on 2026/01/07 21:21:22 UTC

[PR] HDDS-14149. Fixed Prometheus servlet token parsing throws StringIndexOutOfBoundsException [ozone]

navinko opened a new pull request, #9603:
URL: https://github.com/apache/ozone/pull/9603

   ## What changes were proposed in this pull request?
   
   - Fixed Prometheus servlet token parsing throws StringIndexOutOfBoundsException 
   - Added new Test class for PrometheusServlet (Success + Failure cases)
   
   ## What is the link to the Apache JIRA
   https://issues.apache.org/jira/browse/HDDS-14149
   
   ## How was this patch tested?
   Did repro and validated the fix by hitting /prom.
   Before :
   > 2026-01-07 15:53:06,973 [qtp2086062353-90] WARN server.HttpChannel: /prom
   2026-01-07T15:53:06.977807589Z java.lang.StringIndexOutOfBoundsException: Range [7, 6) out of bounds for length 6
   2026-01-07T15:53:06.977817214Z     at java.base/jdk.internal.util.Preconditions$1.apply(Preconditions.java:55) 
   
   After: 
   > No error in om logs
   
   The exact message as mentioned in description "java.lang.StringIndexOutOfBoundsException: begin 7, end 6, length 6`" 
   is specific to substring logic for jdk17 . In jdk8 and 21 will have  Range [7, 6) out of bounds for length 6
   
   Tested with new junit test cases .
   CI:
    https://github.com/navinko/ozone/actions/runs/20793198532
   
   


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-14149. Fixed Prometheus servlet token parsing throws StringIndexOutOfBoundsException [ozone]

Posted by "navinko (via GitHub)" <gi...@apache.org>.
navinko commented on PR #9603:
URL: https://github.com/apache/ozone/pull/9603#issuecomment-3725222153

   Thanks @ptlrs for the review.  Suggestions incorporated in the patch .


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-14149. Fixed Prometheus servlet token parsing throws StringIndexOutOfBoundsException [ozone]

Posted by "navinko (via GitHub)" <gi...@apache.org>.
navinko commented on code in PR #9603:
URL: https://github.com/apache/ozone/pull/9603#discussion_r2672896582


##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/http/PrometheusServlet.java:
##########


Review Comment:
   Thanks @ptlrs for the review . yes it make sense .



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-14149. Fixed Prometheus servlet token parsing throws StringIndexOutOfBoundsException [ozone]

Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on PR #9603:
URL: https://github.com/apache/ozone/pull/9603#issuecomment-3729430375

   Thanks @navinko for the patch, @ptlrs for the review.


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-14149. Fixed Prometheus servlet token parsing throws StringIndexOutOfBoundsException [ozone]

Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai merged PR #9603:
URL: https://github.com/apache/ozone/pull/9603


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-14149. Fixed Prometheus servlet token parsing throws StringIndexOutOfBoundsException [ozone]

Posted by "navinko (via GitHub)" <gi...@apache.org>.
navinko commented on code in PR #9603:
URL: https://github.com/apache/ozone/pull/9603#discussion_r2672896582


##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/http/PrometheusServlet.java:
##########


Review Comment:
   Thanks @ptlrs for the review . yes it make sense , will make the changes .



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-14149. Fixed Prometheus servlet token parsing throws StringIndexOutOfBoundsException [ozone]

Posted by "navinko (via GitHub)" <gi...@apache.org>.
navinko commented on code in PR #9603:
URL: https://github.com/apache/ozone/pull/9603#discussion_r2673126575


##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/http/PrometheusServlet.java:
##########
@@ -49,6 +49,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
       String authorizationHeader = req.getHeader("Authorization");
       if (authorizationHeader == null
           || !authorizationHeader.startsWith(BEARER)
+          || authorizationHeader.length() <= BEARER.length()
           || !securityToken.equals(
               authorizationHeader.substring(BEARER.length() + 1))) {

Review Comment:
   I think trimming the substring further will make the authorization checks less strict incase some malformed/token with space is being passed . In current implementation CM side it do not accepts any token with leading/trailing spaces. So if one passes token with space it should fail ideally.



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-14149. Fixed Prometheus servlet token parsing throws StringIndexOutOfBoundsException [ozone]

Posted by "ptlrs (via GitHub)" <gi...@apache.org>.
ptlrs commented on code in PR #9603:
URL: https://github.com/apache/ozone/pull/9603#discussion_r2671126229


##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/http/PrometheusServlet.java:
##########
@@ -49,6 +49,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
       String authorizationHeader = req.getHeader("Authorization");
       if (authorizationHeader == null
           || !authorizationHeader.startsWith(BEARER)
+          || authorizationHeader.length() <= BEARER.length()
           || !securityToken.equals(
               authorizationHeader.substring(BEARER.length() + 1))) {

Review Comment:
   We are having an off-by-one error. 
   Instead of adding this new check we should instead set the Bearer string with the space and create a substring without the `+1`.
   I wonder if we also need to trim the newly obtained substring.
   
   ```java
   public static final String BEARER = "Bearer ";
   
   if (authorizationHeader == null
             || !authorizationHeader.startsWith(BEARER)
             || !securityToken.equals(
                 authorizationHeader.substring(BEARER.length()))) {}
   ```



##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/http/PrometheusServlet.java:
##########


Review Comment:
   There will never be a valid token without a single trailing space after Bearer. 
   The `BEARER` string should be set to `Bearer ` (with the trailing space) instead of `Bearer`.



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-14149. Fixed Prometheus servlet token parsing throws StringIndexOutOfBoundsException [ozone]

Posted by "navinko (via GitHub)" <gi...@apache.org>.
navinko commented on PR #9603:
URL: https://github.com/apache/ozone/pull/9603#issuecomment-3728788163

   > Thanks @navinko for the patch. The fix itself looks good, but can you please reduce duplication in the test?
   
   Thanks @adoroszlai for reviewing , updated the test cases to reduce code duplication.


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org