Restrict deserialized classes for JMS ObjectMessage

Proprietary

Patches ActiveMQConnectionFactory instantiations to install a deserialization allowlist when the same compilation run contains a javax.jms.ObjectMessage#getObject (or jakarta.jms.ObjectMessage#getObject) call inside a MessageListener#onMessage override. Targets ActiveMQ Classic (org.apache.activemq.ActiveMQConnectionFactory.setTrustedPackages) and ActiveMQ Artemis (org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.setDeserializationAllowList). IBM MQ (com.ibm.mq.jms.MQConnectionFactory) is not yet supported. The recipe handles four factory instantiation shapes: a local variable declaration (ActiveMQConnectionFactory f = new ActiveMQConnectionFactory(...)), a direct return (return new ActiveMQConnectionFactory(...)) refactored into a declare-then-return, an assignment to an existing variable or field (this.factory = new ActiveMQConnectionFactory(...)), and a field initializer, guarded from an initializer block appended after the field. Skips factories that already configure a trusted-packages / allowlist call.

org.openrewrite.java.security.marshalling.FixInsecureJmsDeserialization

Optional

Comma-separated list of package prefixes whose classes are safe to deserialize. Defaults to a minimal safe baseline (java.util, java.lang) when unspecified.

mod run . --recipe=org.openrewrite.java.security.marshalling.FixInsecureJmsDeserialization

Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.