You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-dev@jackrabbit.apache.org by "ciechanowiec (via GitHub)" <gi...@apache.org> on 2026/06/14 15:28:23 UTC
[PR] OAK-12259: oak-http: fix HTTP Basic credential parsing in OakServlet [jackrabbit-oak]
ciechanowiec opened a new pull request, #2957:
URL: https://github.com/apache/jackrabbit-oak/pull/2957
Fixes [OAK-12259](https://issues.apache.org/jira/browse/OAK-12259).
--
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: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OAK-12259: oak-http: fix HTTP Basic credential parsing in OakServlet [jackrabbit-oak]
Posted by "reschke (via GitHub)" <gi...@apache.org>.
reschke commented on PR #2957:
URL: https://github.com/apache/jackrabbit-oak/pull/2957#issuecomment-4707582275
While at it, we should also handle the whitespace after "Basic" correctly (<https://www.greenbytes.de/tech/specs/rfc7235.html#challenge.and.response>).
--
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: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OAK-12259: oak-http: fix HTTP Basic credential parsing in OakServlet [jackrabbit-oak]
Posted by "rishabhdaim (via GitHub)" <gi...@apache.org>.
rishabhdaim commented on PR #2957:
URL: https://github.com/apache/jackrabbit-oak/pull/2957#issuecomment-4704835251
If we are indeed following https://www.rfc-editor.org/info/rfc7617/, we should document that.
@Amoratinos @anchela wdyt ?
--
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: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OAK-12259: oak-http: fix HTTP Basic credential parsing in OakServlet [jackrabbit-oak]
Posted by "rishabhdaim (via GitHub)" <gi...@apache.org>.
rishabhdaim commented on code in PR #2957:
URL: https://github.com/apache/jackrabbit-oak/pull/2957#discussion_r3411182170
##########
oak-http/src/test/java/org/apache/jackrabbit/oak/http/OakServletTest.java:
##########
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.http;
+
+import javax.jcr.Credentials;
+import javax.jcr.NoSuchWorkspaceException;
+import javax.jcr.SimpleCredentials;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.jackrabbit.oak.api.ContentRepository;
+import org.apache.jackrabbit.util.Base64;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.isNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class OakServletTest {
+
+ private static String basicHeader(String userId, String password) {
+ return "Basic " + Base64.encode(userId + ":" + password);
+ }
+
+ /**
+ * Drives {@link OakServlet#service} and captures the credentials it derives
+ * from the {@code Authorization} header. The repository is stubbed to throw
+ * {@link NoSuchWorkspaceException} so the request short-circuits (handled as
+ * a 404) right after the credentials are parsed.
+ */
+ private static SimpleCredentials parsedCredentials(String authorization)
+ throws Exception {
+ ContentRepository repository = mock(ContentRepository.class);
+ ArgumentCaptor<Credentials> captor =
+ ArgumentCaptor.forClass(Credentials.class);
+ when(repository.login(captor.capture(), isNull()))
+ .thenThrow(new NoSuchWorkspaceException());
+
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ when(request.getHeader("Authorization")).thenReturn(authorization);
+ HttpServletResponse response = mock(HttpServletResponse.class);
+
+ new OakServlet(repository).service(request, response);
+
+ verify(response).sendError(HttpServletResponse.SC_NOT_FOUND);
+ Credentials credentials = captor.getValue();
+ assertTrue(credentials instanceof SimpleCredentials);
+ return (SimpleCredentials) credentials;
+ }
+
+ /**
+ * Asserts that a malformed {@code Authorization} header is rejected with a
+ * 401 challenge and never reaches the repository login.
+ */
+ private static void assertUnauthorized(String authorization)
+ throws Exception {
+ ContentRepository repository = mock(ContentRepository.class);
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ when(request.getHeader("Authorization")).thenReturn(authorization);
+ HttpServletResponse response = mock(HttpServletResponse.class);
+
+ new OakServlet(repository).service(request, response);
+
+ verify(response).setHeader("WWW-Authenticate", "Basic realm=\"Oak\"");
+ verify(response).sendError(HttpServletResponse.SC_UNAUTHORIZED);
+ verify(repository, never()).login(any(), any());
+ }
Review Comment:
Nits : Move the helper method to the end of Test file.
##########
oak-http/src/main/java/org/apache/jackrabbit/oak/http/OakServlet.java:
##########
@@ -115,6 +107,30 @@ protected void service(
}
}
+ /**
+ * Parses the credentials from an HTTP {@code Authorization} header using the
+ * Basic authentication scheme (RFC 7617). The decoded value has the form
+ * {@code user-id ":" password}; the user-id must not contain a colon, but
+ * the password may, so only the first colon is treated as the separator.
+ * Splitting on every colon would silently truncate passwords that contain
+ * one (weakening authentication), and a missing colon would throw an
+ * {@link ArrayIndexOutOfBoundsException} instead of failing the login.
+ */
+ private Credentials parseBasicCredentials(String authorization)
+ throws LoginException {
+ if (authorization == null || !authorization.startsWith("Basic ")) {
+ throw new LoginException("Missing or unsupported Authorization header; expected Basic scheme");
+ }
+ String decoded = Base64.decode(authorization.substring("Basic ".length()));
+ int colon = decoded.indexOf(':');
+ if (colon < 0) {
+ throw new LoginException("Malformed Basic credentials: missing ':' separator");
+ }
+ String userId = decoded.substring(0, colon);
Review Comment:
Shouldn't we explicitly check for whether the username has a `:` or not, and throw an exception if it has ?
cc @anchela @Amoratinos @reschke
--
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: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OAK-12259: oak-http: fix HTTP Basic credential parsing in OakServlet [jackrabbit-oak]
Posted by "reschke (via GitHub)" <gi...@apache.org>.
reschke commented on PR #2957:
URL: https://github.com/apache/jackrabbit-oak/pull/2957#issuecomment-4801985428
@ciechanowiec - idea:
1. Refactor basic auth support into until class so it's easier to test
2. Write tests (as mentioned above), of which many will be failing right now
3. Fix bugs.
Do you want to give that a try, or should I take over (of course acking you)?
--
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: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OAK-12259: oak-http: fix HTTP Basic credential parsing in OakServlet [jackrabbit-oak]
Posted by "reschke (via GitHub)" <gi...@apache.org>.
reschke closed pull request #2957: OAK-12259: oak-http: fix HTTP Basic credential parsing in OakServlet
URL: https://github.com/apache/jackrabbit-oak/pull/2957
--
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: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OAK-12259: oak-http: fix HTTP Basic credential parsing in OakServlet [jackrabbit-oak]
Posted by "ciechanowiec (via GitHub)" <gi...@apache.org>.
ciechanowiec commented on PR #2957:
URL: https://github.com/apache/jackrabbit-oak/pull/2957#issuecomment-4802256462
@reschke , feel free to take over. I doubt I'll have the time/capacity to work on this issue in the foreseeable future.
--
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: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org