Skip to content

[Bug]: Avro 1.12.2 breaks AvroCoder with SecurityException (AVRO-4189) #41888

Todo

Description

@Abacn

What happened?

Apache Avro 1.12.2 (AVRO-4189
) adds ClassSecurityValidator.validate(c) to every ClassUtils.forName() call, trusting only a couple of core JDK classes by default.

This breaks Beam's AvroCoder and AvroDatumFactory for all non-GenericRecord types—both reflective POJOs (@defaultcoder(AvroCoder.class) / AvroCoder.of(MyPojo.class), failing on encode() and decode()) and SpecificRecords (failing on SpecificDatumReader construction)—including built-in Beam types (KafkaCheckpointMark, Spanner Change Streams models, and Beam examples like AutoComplete and TrafficMaxLaneFlow):

Caused by: java.lang.SecurityException: Forbidden org.apache.beam.examples.complete.TrafficMaxLaneFlow$LaneInfo! This class is not trusted to be included in Avro schemas.
    at org.apache.avro.util.ClassSecurityValidator.validate(ClassSecurityValidator.java:60)
    at org.apache.avro.util.ClassUtils.forName(ClassUtils.java:99)
    at org.apache.avro.specific.SpecificData.getClass(SpecificData.java:391)
    at org.apache.avro.reflect.ReflectData.populateEncoderCache(ReflectData.java:1069)
    at org.apache.avro.reflect.ReflectDatumWriter.write(ReflectDatumWriter.java:166)
    at org.apache.beam.sdk.extensions.avro.coders.AvroCoder.encode(AvroCoder.java:476)

SdkHarnessOptions#getAvroSerializableClasses (-Dorg.apache.avro.SERIALIZABLE_CLASSES) only defaults to 6 JDK types and cannot practically list every user POJO, nested/collection type (java.util.List), and internal Beam IO class.

Suggested Fix

  • Auto-allowlist declared AvroCoder / AvroDatumFactory type graphs (details pending. probably would need some mechanism of coder registry / JvmInitializer)

  • Add --avroSerializablePackages to SdkHarnessOptions / sdks/java/container/boot.go as an escape hatch for dynamic/polymorphic subtypes.

  • Add Avro 1.12.2 test coverage in sdks/java/extensions/avro.
    We already have avro compat test targets. Consider add this new version.

Issue Priority

Priority: 2 (default / most bugs should be filed as P2)

Issue Components

  • Component: Python SDK
  • Component: Java SDK
  • Component: Go SDK
  • Component: Typescript SDK
  • Component: IO connector
  • Component: Beam YAML
  • Component: Beam examples
  • Component: Beam playground
  • Component: Beam katas
  • Component: Website
  • Component: Infrastructure
  • Component: Spark Runner
  • Component: Flink Runner
  • Component: Prism Runner
  • Component: Hazelcast Jet Runner
  • Component: Google Cloud Dataflow Runner

Activity

  1. sakshammalik260-cse commented on Dec 3, 2026

    @sakshammalik260-cse
    Contributor

    .take-issue

  2. sakshammalik260-cse commented on Dec 3, 2026

    @sakshammalik260-cse
    Contributor

    Hi @Abacn, I've reproduced the issue with Avro 1.12.2, resulting in 32 test failures.

    I'm looking at automatic registration of declared types while preserving existing security policies and compatibility with older Avro versions.

    Should automatic registration be limited to Avro's default security policy, leaving custom predicates untouched?

    I'd appreciate your thoughts before proceeding with the implementation.

  3. sakshammalik260-cse commented on Dec 5, 2026

    @sakshammalik260-cse
    Contributor

    Hi @Abacn, a quick progress update:

    I've implemented the Avro 1.12.2 compatibility test target and the avroSerializablePackages option. All 199 tests pass on each existing Avro compatibility version, while 61 failures remain on 1.12.2.

    During automatic type-graph registration experiments, I found that Avro's global Boolean trust predicate cannot distinguish an explicit denial from an unregistered class. Predicate composition can therefore override custom restrictions, and conditional replacement introduces a potential race with concurrent policy updates.

    Would a default-only registration mechanism during controlled JVM initialization be an acceptable approach, or should we pursue a supported policy-extension API in Avro itself?

    I'd appreciate your guidance before proceeding with the remaining implementation.

  4. sakshammalik260-cse commented on Dec 5, 2026

    @sakshammalik260-cse
    Contributor

    .free-issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions