Summary
DSPy 3.3.0b1 contains a file exfiltration vulnerability in Image and Audio output field adapters. When an attacker can influence language model output and that output is parsed as a typed media value, a filesystem path may cause a local file to be read, encoded, and sent to the model endpoint.
Affected context
The vulnerability occurs in DSPy workflows that parse untrusted language model completions through the JSONAdapter or ChatAdapter and validate Image or Audio output fields. Risk is present when the parsed media value permits a URL-like field to reference a local filesystem path and the runtime process can read that path. The resulting file data may be embedded in outgoing prompt messages sent to a model endpoint.
Exploit preconditions
- Attack surface: Language model output parsing and media field adaptation
- Required access: Ability to influence, directly or indirectly, the completion returned to the DSPy application
- Trigger point: Parsing and type validation of an Image or Audio output value
- Required runtime condition: The application process must have read access to the referenced local file
- Why exploitation is possible: Media encoding treats a user-influenced path as a candidate local file, reads matching files, and includes their encoded contents in a subsequent outbound request
Why this happens
The underlying bug is insufficient separation between externally controlled media references and local filesystem paths. During output parsing, validation reaches image or audio encoding logic that checks whether the supplied path exists as a local file and then reads and base64-encodes it. This behavior maps to CWE-73: External Control of File Name or Path, because data influenced by an external source determines which local filesystem object is accessed without an adequate trust boundary or path restriction.
Potential impact
- Sensitive application files may be disclosed to an attacker-controlled or attacker-influenced model endpoint
- Credentials, configuration data, source code, or other readable secrets could be exposed
- Outbound prompts may contain base64-encoded contents from unintended local files
- Model-provider logs, traces, or downstream integrations may retain the exfiltrated data
- The application process could experience resource or privacy impacts from repeated file reads
General mitigation guidance
Mitigation generally focuses on preventing untrusted model output from selecting local filesystem resources.
Common defensive patterns include:
- Treating model-generated paths and media URLs as untrusted data rather than local file references
- Allowing only explicitly supported remote media schemes or validated application-managed identifiers
- Applying canonicalization, allowlisting, and containment checks when local media access is an intentional feature
- Separating media fetching from model-output parsing and requiring an explicit authorization decision
- Limiting process permissions and restricting access to sensitive directories
- Redacting or blocking local file contents from outbound prompt construction
- Enforcing outbound network and model-endpoint policies that reduce unintended data transfer
How teams detect issues like this
Detection approaches can include:
- Static analysis for model-output fields flowing into filesystem APIs such as file existence checks, open operations, or media encoders
- Code review searches for path or URL values reaching image and audio conversion routines without scheme, origin, or containment validation
- Tests using controlled model completions that reference canary files and verifying that no local contents appear in outbound requests
- Runtime telemetry for unexpected local file reads during response parsing and for unusually large or high-entropy prompt fields
- Policy enforcement that restricts media inputs to approved schemes, directories, or application-managed object references
- Automated security review tools configured to flag external data reaching filesystem access functions

