Summary
Apache Airflow's scheduler-side deadline-reference decoder (SerializedCustomReference.deserialize_reference) unsafely imported and instantiated arbitrary classes based on DAG-author-controlled serialized state, without an allowlist or registry check.
In deployments where DAG authors are less trusted than the scheduler process, a malicious DAG could embed a crafted DeadlineReference that causes the scheduler to import attacker-controlled code and instantiate it with a live SQLAlchemy session, enabling privileged actions within the scheduler context.
Affected context
This vulnerability occurs in Apache Airflow environments where:
- The scheduler process can import DAG bundles directly (typical single-host or shared-code deployments).
SerializedCustomReference.deserialize_referenceis used to handle serializedDeadlineReferenceobjects.- DAG authors are not fully trusted to run arbitrary code with the same privileges as the scheduler.
Under these conditions, the scheduler trusts class paths embedded in serialized references and treats them as loadable, instantiable components, effectively extending the scheduler's trusted code surface to any module path reachable from the scheduler's Python environment.
Exploit preconditions
- Attack surface: Airflow scheduler process handling serialized DAG state and
DeadlineReferenceobjects. - Required access: Ability to author or modify DAGs whose code and serialized forms are processed by the scheduler (e.g., DAG author permissions, write access to the DAG repository or deployment pipeline).
- Trigger point: Evaluation of a crafted
DeadlineReferenceduringSerializedCustomReference.deserialize_reference, which reads the serialized class path and callsimport_string(...)to load and instantiate it. - Why exploitation is possible: The decoder:
- Accepts class paths from serialized DAG state controlled by DAG authors.
- Performs dynamic imports (
import_string) directly from those paths. - Instantiates the resulting class with powerful objects (e.g., a live SQLAlchemy session) without an allowlist, plugin registry gate, or trust boundary enforcement.
Why this happens
The core issue is an unsafe deserialization pattern where serialized metadata from a partially untrusted source (DAG-author-controlled state) is treated as executable configuration.
SerializedCustomReference.deserialize_reference interprets serialized DeadlineReference data as a fully trusted specification of what Python class to import and instantiate. Instead of restricting deserialization to a bounded set of known-safe types, it dynamically imports arbitrary module paths and constructs the referenced classes, mapping directly to CWE-502: Deserialization of Untrusted Data.
In abstract terms, the insecure pattern is:
- Take untrusted or semi-trusted serialized input.
- Derive a code identifier (module/class path) from that input.
- Dynamically import and instantiate the referenced type, often with sensitive capabilities (e.g., database sessions, scheduler internals).
This collapses the distinction between data and code, allowing serialized content to influence what code executes inside a high-privilege component (the scheduler).
Potential impact
- DAG authors may be able to execute arbitrary Python code inside the scheduler process.
- Attackers could abuse the attached SQLAlchemy session to:
- Read or modify workflow metadata and state.
- Alter DAG run history, task status, or scheduling information.
- Tamper with connections or variables stored in the metadata database.
- Privilege escalation from "DAG author" role to "scheduler-level" capabilities within the Airflow environment.
- Potential pivot to other systems via stored credentials or downstream actions initiated by modified scheduling logic.
- Integrity violations such as schedule manipulation, job suppression, or backdoor insertion into orchestrated workflows.
General mitigation guidance
Effective mitigations focus on constraining deserialization behavior and tightening trust boundaries between DAG authors and the scheduler:
- Type allowlisting and registries:
- Restrict dynamic imports to a curated list of approved
DeadlineReferenceimplementations. - Use a plugin or registry mechanism where only explicitly registered classes can be instantiated.
- Data–code separation:
- Treat serialized DAG state as data only and avoid allowing it to specify arbitrary code locations (module/class paths).
- Encode references using stable identifiers or enum-like keys, resolving them to concrete classes via static mappings in scheduler code.
- Least-privilege object construction:
- Limit what sensitive objects (e.g., full SQLAlchemy sessions) are passed into deserialized instances, favoring narrower interfaces or service abstractions.
- Avoid injecting high-privilege handles into any object whose type is not strongly constrained.
- Trust boundary enforcement:
- Design Airflow deployments so that less-trusted DAG author code does not implicitly get the same execution privileges as the scheduler.
- Use separate environments or review processes for DAG code in multi-tenant deployments.
- Secure-by-default serialization:
- Prefer simple, schema-validated data formats for serialized state (primitive types and structured objects) rather than flexible mechanisms that can encode arbitrary types.
How teams detect issues like this
Detection can focus on both code-level patterns and runtime behavior:
- Static analysis and code scanning:
- Flag uses of dynamic import functions (
import_string,__import__,importlib.import_module, etc.) that are parameterized by serialized or user-controlled input. - Identify deserialization paths (
deserialize_reference, similar helpers) that: - Accept untrusted or semi-trusted data.
- Directly resolve class/module names from that data.
- Look for constructors that receive high-privilege objects (like database sessions) from deserialization contexts.
- Code review signals:
- Pay special attention to components where:
- Scheduler or orchestration services instantiate user- or DAG-provided types.
- Serialized DAG state is interpreted as configuration for dynamic imports.
- Require explicit review for any new plugin/extension mechanism that uses import paths from data.
- Policy and tooling:
- Introduce internal policies banning unchecked dynamic imports from serialized structures.
- Integrate automated SAST or custom linters into CI pipelines to enforce these policies.
- Use runtime logging and monitoring to detect unexpected module loads or class instantiations in scheduler processes, particularly from uncommon module namespaces.

