petrov-mg commented on code in PR #11642: URL: https://github.com/apache/ignite/pull/11642#discussion_r1838106461
########## modules/core/src/test/java/org/apache/ignite/marshaller/ObjectInputStreamFilteringTest.java: ########## @@ -0,0 +1,125 @@ +/* + * 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.ignite.marshaller; + +import java.util.HashMap; +import javax.management.BadAttributeValueExpException; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.Ignition; +import org.apache.ignite.client.ClientConnectionException; +import org.apache.ignite.client.IgniteClient; +import org.apache.ignite.configuration.ClientConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.management.tx.TxVerboseInfo; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.ListeningTestLogger; +import org.apache.ignite.testframework.LogListener; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.junit.Test; + +import static org.apache.ignite.IgniteSystemProperties.IGNITE_MARSHALLER_BLACKLIST; + +/** */ +public class ObjectInputStreamFilteringTest extends GridCommonAbstractTest { + /** */ + private final ListeningTestLogger listeningLog = new ListeningTestLogger(log); + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + return super.getConfiguration(igniteInstanceName) + .setGridLogger(listeningLog); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + stopAllGrids(); + } + + /** */ + @Test + public void testJdkMarshaller() throws Exception { + startGrid(0); + + try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses("127.0.0.1:10800"))) { + LogListener logLsnr = LogListener + .matches("Deserialization of class javax.management.BadAttributeValueExpException is disallowed") + .build(); + + listeningLog.registerListener(logLsnr); + + GridTestUtils.assertThrowsWithCause( + () -> client.cache("missing-cache").put("0", new BadAttributeValueExpException("val")), + ClientConnectionException.class + ); + + assertTrue(logLsnr.check()); + } + } + + /** */ + @Test public void testJavaDeserialization() throws Exception { Review Comment: Fixed. ########## modules/core/src/main/java/org/apache/ignite/marshaller/MarshallerUtils.java: ########## @@ -172,12 +190,11 @@ private static ClassSet classWhiteList(ClassLoader clsLdr) throws IgniteCheckedE * @return Black list of classes. */ private static ClassSet classBlackList(ClassLoader clsLdr) throws IgniteCheckedException { - ClassSet clsSet = null; + ClassSet clsSet = new ClassSet(); - String blackListFileName = IgniteSystemProperties.getString(IgniteSystemProperties.IGNITE_MARSHALLER_BLACKLIST); + String blackListFileName = IgniteSystemProperties.getString(IGNITE_MARSHALLER_BLACKLIST, DEFAULT_BLACKLIST_CLS_NAMES_FILE); Review Comment: Fixed. ########## modules/core/src/main/java/org/apache/ignite/marshaller/MarshallerUtils.java: ########## @@ -128,23 +126,42 @@ public static IgniteProductVersion jobReceiverVersion() { * @param clsLdr Class loader. * @return Class name filter for marshaller. */ - public static IgnitePredicate<String> classNameFilter(ClassLoader clsLdr) throws IgniteCheckedException { - ClassSet whiteList = classWhiteList(clsLdr); - ClassSet blackList = classBlackList(clsLdr); - - return new IgnitePredicate<String>() { - @Override public boolean apply(String s) { - // Allows all primitive arrays and checks arrays' type. - if ((blackList != null || whiteList != null) && s.charAt(0) == '[') { - if (s.charAt(1) == 'L' && s.length() > 2) - s = s.substring(2, s.length() - 1); - else - return true; - } + public static IgniteMarshallerClassFilter classNameFilter(ClassLoader clsLdr) throws IgniteCheckedException { + return new IgniteMarshallerClassFilter(classWhiteList(clsLdr), classBlackList(clsLdr)); + } + + /** + * @param clsFilter Ignite marshaller class filter to which class validation will be delegated. + * @throws IgniteCheckedException if autoconfiguration failed. + */ + public static void autoconfigureObjectInputFilter(IgniteMarshallerClassFilter clsFilter) throws IgniteCheckedException { + if (!IgniteSystemProperties.getBoolean(IGNITE_ENABLE_OBJECT_INPUT_FILTER_AUTOCONFIGURATION, true)) + return; + + synchronized (MUX) { + ObjectInputFilter objFilter = ObjectInputFilter.Config.getSerialFilter(); - return (blackList == null || !blackList.contains(s)) && (whiteList == null || whiteList.contains(s)); + if (objFilter == null) { Review Comment: Fixed. -- 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: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org