Skip to content

[Security] Arbitrary file write via path traversal in output_directory parameter #96

Description

@Correctover

Summary

The build_output_path() function in utils.py accepts a user-controlled output_directory parameter without validating that the resulting path stays within the intended base directory. An attacker can write arbitrary files to any writable location on the filesystem.

Details

File: minimax_mcp/utils.py, function build_output_path()

if output_directory is None:
    output_path = Path(os.path.expanduser(base_path))
elif not os.path.isabs(os.path.expanduser(output_directory)):
    output_path = Path(os.path.expanduser(base_path)) / Path(output_directory)
else:
    output_path = Path(os.path.expanduser(output_directory))  # No confinement!

Impact

An attacker can write arbitrary files to any writable location (overwrite cron jobs, plant backdoors, write SSH keys).

Suggested Fix

output_path = Path(os.path.expanduser(output_directory)).resolve()
base_resolved = Path(os.path.expanduser(base_path)).resolve()
if not str(output_path).startswith(str(base_resolved)):
    raise MinimaxMcpError("Output path escapes base directory")

Reported by Correctover Security Research (https://correctover.com)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions