From 4bdff9b50d198fc37998ecd017751ed0e03a49bf Mon Sep 17 00:00:00 2001 From: Sai Asish Y Date: Wed, 18 Nov 2026 20:46:52 -0800 Subject: [PATCH] [#2659] Send web console security headers from the server handler chain Signed-off-by: Sai Asish Y --- .../src/main/webapp/browse.jsp | 6 +- .../src/main/webapp/js/browse.js | 30 +++++++++ .../src/main/webapp/js/message.js | 7 +++ .../src/main/webapp/message.jsp | 3 +- .../spring/jetty/JettyServerBeanTest.java | 61 +++++++++++++------ .../src/test/resources/groups.properties | 18 ++++++ .../test/resources/jetty/jetty-webapps.xml | 4 +- .../src/test/resources/login.config | 21 +++++++ .../src/test/resources/users.properties | 18 ++++++ .../src/release/conf/jetty-spring.properties | 4 +- .../src/release/conf/jetty/jetty-webapps.xml | 4 +- 11 files changed, 149 insertions(+), 27 deletions(-) create mode 100644 activemq-web-console/src/main/webapp/js/browse.js create mode 100644 activemq-web-console/src/test/resources/groups.properties create mode 100644 activemq-web-console/src/test/resources/login.config create mode 100644 activemq-web-console/src/test/resources/users.properties diff --git a/activemq-web-console/src/main/webapp/browse.jsp b/activemq-web-console/src/main/webapp/browse.jsp index 316a61cfe8b..4b03cf9ea13 100644 --- a/activemq-web-console/src/main/webapp/browse.jsp +++ b/activemq-web-console/src/main/webapp/browse.jsp @@ -61,7 +61,7 @@ " - onclick="return confirm('Are you sure you want to delete this message?')" + class="actionDelete" >Delete @@ -82,7 +82,7 @@ " - onclick="return confirm('Are you sure you want to retry this message on queue://?')" + class="actionRetry" data-queue="" title="Move to to attempt reprocessing" >Retry @@ -96,6 +96,8 @@ ">View Consumers + + <%@include file="decorators/footer.jsp" %> diff --git a/activemq-web-console/src/main/webapp/js/browse.js b/activemq-web-console/src/main/webapp/js/browse.js new file mode 100644 index 00000000000..295226cb59f --- /dev/null +++ b/activemq-web-console/src/main/webapp/js/browse.js @@ -0,0 +1,30 @@ +/** + * 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. + */ + +addEvent(window, 'load', (_event) => { + for (const link of document.querySelectorAll('a.actionDelete')) { + link.onclick = function(e) { + return confirm('Are you sure you want to delete this message?'); + } + } + + for (const link of document.querySelectorAll('a.actionRetry')) { + link.onclick = function(e) { + return confirm('Are you sure you want to retry this message on queue://' + link.dataset.queue + '?'); + } + } +}); diff --git a/activemq-web-console/src/main/webapp/js/message.js b/activemq-web-console/src/main/webapp/js/message.js index d45b70a4cb7..2cf9984028e 100644 --- a/activemq-web-console/src/main/webapp/js/message.js +++ b/activemq-web-console/src/main/webapp/js/message.js @@ -75,4 +75,11 @@ window.onload=function() { document.getElementById('actionDelete').onclick = function(e) { return confirm('Are you sure you want to delete the message?'); } + + const actionRetry = document.getElementById('actionRetry'); + if (actionRetry) { + actionRetry.onclick = function(e) { + return confirm('Are you sure you want to retry this message?'); + } + } } \ No newline at end of file diff --git a/activemq-web-console/src/main/webapp/message.jsp b/activemq-web-console/src/main/webapp/message.jsp index 382452d76bb..c5a9f5dc139 100644 --- a/activemq-web-console/src/main/webapp/message.jsp +++ b/activemq-web-console/src/main/webapp/message.jsp @@ -145,13 +145,12 @@ No message could be found for ID - + " - onclick="return confirm('Are you sure you want to retry this message?')" title="Retry - attempt reprocessing on original destination">Retry diff --git a/activemq-web-console/src/test/java/org/apache/activemq/spring/jetty/JettyServerBeanTest.java b/activemq-web-console/src/test/java/org/apache/activemq/spring/jetty/JettyServerBeanTest.java index ad5855bff1a..a8323d4939f 100644 --- a/activemq-web-console/src/test/java/org/apache/activemq/spring/jetty/JettyServerBeanTest.java +++ b/activemq-web-console/src/test/java/org/apache/activemq/spring/jetty/JettyServerBeanTest.java @@ -24,6 +24,8 @@ import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; +import java.nio.charset.StandardCharsets; +import java.util.Base64; import org.apache.xbean.spring.context.ClassPathXmlApplicationContext; import org.eclipse.jetty.server.Server; @@ -32,33 +34,54 @@ public class JettyServerBeanTest { + static { + if (System.getProperty("java.security.auth.login.config") == null) { + var resource = JettyServerBeanTest.class.getClassLoader().getResource("login.config"); + if (resource != null) { + System.setProperty("java.security.auth.login.config", resource.getFile()); + } + } + } + @Test public void testJettyServerBean() throws Exception { var context = new ClassPathXmlApplicationContext("conf/jetty-spring.xml"); context.start(); + try { + var jettyServer = (JettyServerBean) context.getBean("jettyServer"); + assertNotNull(jettyServer); - var jettyServer = (JettyServerBean) context.getBean("jettyServer"); - assertNotNull(jettyServer); - - Server server = jettyServer.getServer(); - assertNotNull("Embedded Jetty Server should be created", server); - assertTrue("Embedded Jetty Server should be running", server.isRunning()); + Server server = jettyServer.getServer(); + assertNotNull("Embedded Jetty Server should be created", server); + assertTrue("Embedded Jetty Server should be running", server.isRunning()); - // The console is protected by the JAAS SecurityHandler wired in - // jetty-security.xml: an unauthenticated request must be challenged - // (HTTP 401) rather than served. A request from loopback also confirms - // the InetAccessHandler allows local clients. - int port = ((ServerConnector) server.getConnectors()[0]).getLocalPort(); - HttpClient client = HttpClient.newHttpClient(); - HttpResponse response = client.send( - HttpRequest.newBuilder(URI.create("http://127.0.0.1:" + port + "/admin/")).GET().build(), - HttpResponse.BodyHandlers.ofString()); - assertEquals("Web console must require authentication", 401, response.statusCode()); + // The console is protected by the JAAS SecurityHandler wired in + // jetty-security.xml: an unauthenticated request must be challenged + // (HTTP 401) rather than served. A request from loopback also confirms + // the InetAccessHandler allows local clients. + int port = ((ServerConnector) server.getConnectors()[0]).getLocalPort(); + HttpClient client = HttpClient.newHttpClient(); + HttpResponse response = client.send( + HttpRequest.newBuilder(URI.create("http://127.0.0.1:" + port + "/admin/")).GET().build(), + HttpResponse.BodyHandlers.ofString()); + assertEquals("Web console must require authentication", 401, response.statusCode()); - // jetty.http.host from jetty-spring.properties: without it Jetty binds every interface - assertEquals("127.0.0.1", ((ServerConnector) server.getConnectors()[0]).getHost()); + // The security headers from jetty-webapps.xml must also be sent on + // the pages served to an authenticated user. + HttpResponse authenticatedResponse = client.send( + HttpRequest.newBuilder(URI.create("http://127.0.0.1:" + port + "/admin/")) + .header("Authorization", "Basic " + Base64.getEncoder().encodeToString( + "admin:admin".getBytes(StandardCharsets.ISO_8859_1))) + .GET().build(), + HttpResponse.BodyHandlers.ofString()); + assertEquals(200, authenticatedResponse.statusCode()); + assertEquals("SAMEORIGIN", authenticatedResponse.headers().firstValue("X-Frame-Options").orElse(null)); - context.stop(); + // jetty.http.host from jetty-spring.properties: without it Jetty binds every interface + assertEquals("127.0.0.1", ((ServerConnector) server.getConnectors()[0]).getHost()); + } finally { + context.close(); + } } @Test diff --git a/activemq-web-console/src/test/resources/groups.properties b/activemq-web-console/src/test/resources/groups.properties new file mode 100644 index 00000000000..c7d5e690901 --- /dev/null +++ b/activemq-web-console/src/test/resources/groups.properties @@ -0,0 +1,18 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +admins=admin diff --git a/activemq-web-console/src/test/resources/jetty/jetty-webapps.xml b/activemq-web-console/src/test/resources/jetty/jetty-webapps.xml index 03b9f292418..b460be11854 100644 --- a/activemq-web-console/src/test/resources/jetty/jetty-webapps.xml +++ b/activemq-web-console/src/test/resources/jetty/jetty-webapps.xml @@ -21,7 +21,8 @@ - + + @@ -82,6 +83,7 @@ + diff --git a/activemq-web-console/src/test/resources/login.config b/activemq-web-console/src/test/resources/login.config new file mode 100644 index 00000000000..ff9189346e1 --- /dev/null +++ b/activemq-web-console/src/test/resources/login.config @@ -0,0 +1,21 @@ +/* + * 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. + */ +activemq { + org.apache.activemq.jaas.PropertiesLoginModule required + org.apache.activemq.jaas.properties.user="users.properties" + org.apache.activemq.jaas.properties.group="groups.properties"; +}; diff --git a/activemq-web-console/src/test/resources/users.properties b/activemq-web-console/src/test/resources/users.properties new file mode 100644 index 00000000000..24168f30523 --- /dev/null +++ b/activemq-web-console/src/test/resources/users.properties @@ -0,0 +1,18 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +admin=admin diff --git a/assembly/src/release/conf/jetty-spring.properties b/assembly/src/release/conf/jetty-spring.properties index 26962252b50..8abf240fefc 100644 --- a/assembly/src/release/conf/jetty-spring.properties +++ b/assembly/src/release/conf/jetty-spring.properties @@ -19,8 +19,8 @@ # Jetty 12 server for the web console. Each file uses Server.insertHandler (which # prepends), so the LAST handler loaded is the outermost. The connection limits are # accept-time Server beans. The resulting request path (outermost -> innermost) is: -# DoS(rate limit) -> SizeLimit -> ThreadLimit -> MinDataRate -> InetAccess(IP allow) -# -> Security(JAAS auth) -> Contexts(webapps) +# Rewrite(security headers) -> DoS(rate limit) -> SizeLimit -> ThreadLimit -> MinDataRate +# -> InetAccess(IP allow) -> Security(JAAS auth) -> Contexts(webapps) # so cheap rejections (rate/size/thread/slow-loris/IP) happen before the expensive # JAAS authentication. jetty-webapps.xml (webAppsContext) is applied last. # The DoS/limit handlers ship with permissive defaults; tune via jetty.dos.*, diff --git a/assembly/src/release/conf/jetty/jetty-webapps.xml b/assembly/src/release/conf/jetty/jetty-webapps.xml index f4bd9603d3b..c3aeb435b27 100644 --- a/assembly/src/release/conf/jetty/jetty-webapps.xml +++ b/assembly/src/release/conf/jetty/jetty-webapps.xml @@ -21,7 +21,8 @@ - + + @@ -130,6 +131,7 @@ +