This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch 2.2.X
in repository https://gitbox.apache.org/repos/asf/mina.git
The following commit(s) were added to refs/heads/2.2.X by this push:
new 3826e77a5 Don't expose all the attributes value in the Session MBean.
3826e77a5 is described below
commit 3826e77a51affe0619a32ab6d68e184d42260cf1
Author: emmanuel lecharny <[email protected]>
AuthorDate: Sat Nov 14 09:22:23 2026 +0100
Don't expose all the attributes value in the Session MBean.
---
.../mina/integration/jmx/IoSessionMBean.java | 21 ++++++-
.../mina/integration/jmx/IoSessionMBeanTest.java | 64 ++++++++++++++++++++++
2 files changed, 84 insertions(+), 1 deletion(-)
diff --git
a/mina-integration-jmx/src/main/java/org/apache/mina/integration/jmx/IoSessionMBean.java
b/mina-integration-jmx/src/main/java/org/apache/mina/integration/jmx/IoSessionMBean.java
index 76f57354a..f55062d3c 100644
---
a/mina-integration-jmx/src/main/java/org/apache/mina/integration/jmx/IoSessionMBean.java
+++
b/mina-integration-jmx/src/main/java/org/apache/mina/integration/jmx/IoSessionMBean.java
@@ -35,6 +35,23 @@ import org.apache.mina.core.session.IoSession;
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
public class IoSessionMBean extends ObjectMBean<IoSession> {
+ /**
+ * Name of the system property that re-enables exposing session attribute
<b>values</b>
+ * through the <code>attributes</code> MBean attribute. Session attributes
are where
+ * applications keep per-peer security state (authentication results,
tokens,
+ * principals), and the JMX attribute-read permission is granted to the
weakest
+ * monitoring role. By default only the attribute keys are exposed and
every value is
+ * redacted, consistent with {@link ObjectMBean} refusing to expose the
+ * <code>attachment</code> and <code>attributeKeys</code> properties. Set
+ *
<code>-Dorg.apache.mina.integration.jmx.exposeSessionAttributeValues=true</code>
to
+ * restore the previous behavior, and only after scoping JMX read access
accordingly.
+ */
+ public static final String EXPOSE_ATTRIBUTE_VALUES_PROPERTY =
+ "org.apache.mina.integration.jmx.exposeSessionAttributeValues";
+
+ /** The placeholder returned instead of a session attribute value by
default */
+ static final String REDACTED_VALUE = "<hidden>";
+
/**
* Creates a new IoSessionMBean instance
*
@@ -47,10 +64,12 @@ public class IoSessionMBean extends ObjectMBean<IoSession> {
@Override
protected Object getAttribute0(String fqan) throws Exception {
if (fqan.equals("attributes")) {
+ boolean exposeValues =
Boolean.getBoolean(EXPOSE_ATTRIBUTE_VALUES_PROPERTY);
+
Map<String, String> answer = new LinkedHashMap<>();
for (Object key : getSource().getAttributeKeys()) {
- answer.put(String.valueOf(key),
String.valueOf(getSource().getAttribute(key)));
+ answer.put(String.valueOf(key), exposeValues ?
String.valueOf(getSource().getAttribute(key)):REDACTED_VALUE);
}
return answer;
diff --git
a/mina-integration-jmx/src/test/java/org/apache/mina/integration/jmx/IoSessionMBeanTest.java
b/mina-integration-jmx/src/test/java/org/apache/mina/integration/jmx/IoSessionMBeanTest.java
new file mode 100644
index 000000000..bce681e54
--- /dev/null
+++
b/mina-integration-jmx/src/test/java/org/apache/mina/integration/jmx/IoSessionMBeanTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.mina.integration.jmx;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Map;
+
+import org.apache.mina.core.session.DummySession;
+import org.apache.mina.core.session.IoSession;
+import org.junit.Test;
+
+/**
+ * Tests that the {@link IoSessionMBean} <code>attributes</code> MBean
attribute does not
+ * expose session attribute values (per-peer security state) to read-only JMX
principals
+ * unless the embedder explicitly opts in.
+ */
+public class IoSessionMBeanTest {
+ @Test
+ public void testAttributeValuesAreRedactedByDefault() throws Exception {
+ IoSession session = new DummySession();
+ session.setAttribute("secretToken", "hunter2");
+ IoSessionMBean mbean = new IoSessionMBean(session);
+
+ Map<?, ?> attributes = (Map<?, ?>) mbean.getAttribute0("attributes");
+
+ assertTrue(attributes.containsKey("secretToken"));
+ assertEquals(IoSessionMBean.REDACTED_VALUE,
attributes.get("secretToken"));
+ assertFalse(attributes.containsValue("hunter2"));
+ }
+
+ @Test
+ public void testAttributeValuesCanBeReEnabled() throws Exception {
+ System.setProperty(IoSessionMBean.EXPOSE_ATTRIBUTE_VALUES_PROPERTY,
"true");
+
+ try {
+ IoSession session = new DummySession();
+ session.setAttribute("secretToken", "hunter2");
+ IoSessionMBean mbean = new IoSessionMBean(session);
+
+ Map<?, ?> attributes = (Map<?, ?>)
mbean.getAttribute0("attributes");
+
+ assertEquals("hunter2", attributes.get("secretToken"));
+ } finally {
+
System.clearProperty(IoSessionMBean.EXPOSE_ATTRIBUTE_VALUES_PROPERTY);
+ }
+ }
+}