|
| 1 | +/* |
| 2 | + * Copyright 2025 Code Intelligence GmbH |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.example; |
| 18 | + |
| 19 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 20 | +import java.util.Arrays; |
| 21 | +import java.util.logging.Level; |
| 22 | +import java.util.logging.LogManager; |
| 23 | +import org.springframework.cloud.function.context.FunctionProperties; |
| 24 | +import org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry; |
| 25 | +import org.springframework.cloud.function.context.config.RoutingFunction; |
| 26 | +import org.springframework.cloud.function.json.JacksonMapper; |
| 27 | +import org.springframework.messaging.Message; |
| 28 | +import org.springframework.messaging.converter.CompositeMessageConverter; |
| 29 | +import org.springframework.messaging.converter.StringMessageConverter; |
| 30 | +import org.springframework.messaging.support.MessageBuilder; |
| 31 | + |
| 32 | +/** |
| 33 | + * Reproduce <a href="https://spring.io/security/cve-2022-22963">CVE-2022-22963</a> by fuzzing the |
| 34 | + * routing-expression header in Spring Cloud Function. |
| 35 | + */ |
| 36 | +public class SpringCloudFunctionRoutingFuzzer { |
| 37 | + private static RoutingFunction router; |
| 38 | + |
| 39 | + public static void fuzzerInitialize() { |
| 40 | + LogManager.getLogManager().getLogger("").setLevel(Level.SEVERE); |
| 41 | + // Empty function registry |
| 42 | + SimpleFunctionRegistry registry = |
| 43 | + new SimpleFunctionRegistry( |
| 44 | + null, |
| 45 | + new CompositeMessageConverter(Arrays.asList(new StringMessageConverter())), |
| 46 | + new JacksonMapper(new ObjectMapper())); |
| 47 | + router = new RoutingFunction(registry, new FunctionProperties()); |
| 48 | + } |
| 49 | + |
| 50 | + public static void fuzzerTestOneInput(String payload, String expr) { |
| 51 | + try { |
| 52 | + Message<String> message = |
| 53 | + MessageBuilder.withPayload(payload) |
| 54 | + .setHeader("spring.cloud.function.routing-expression", expr) |
| 55 | + .build(); |
| 56 | + router.apply(message); |
| 57 | + } catch (Throwable ignored) { |
| 58 | + // Most inputs will cause parsing or routing errors; that is fine. |
| 59 | + } |
| 60 | + } |
| 61 | +} |
0 commit comments