Skip to content

CodeWhale: image_analyze follows workspace symlinks, leaking external file bytes

High severity GitHub Reviewed Published Jul 16, 2026 in codewhale-hq/Codewhale

Package

npm codewhale (npm)

Affected versions

>= 0.8.41, < 0.8.64

Patched versions

0.8.64
cargo codewhale-tui (Rust)
>= 0.8.41, < 0.8.64
0.8.64
cargo deepseek-tui (Rust)
>= 0.8.32, <= 0.8.41
None
npm deepseek-tui (npm)
>= 0.8.32, < 0.8.41
0.8.41

Description

Maintainer resolution

The CodeWhale maintainers validated this report. The affected package ranges are recorded in the advisory metadata. Version 0.8.64 contains the fix in commit 26de44a8bd5051f8f944ea60b2c37ae1d2b7d25e. Users should upgrade to 0.8.64 or later. The original reporter analysis is preserved below.

Summary

image_analyze follows workspace symlinks and leaks outside-workspace file bytes to the vision endpoint

The image_analyze tool resolves its image_path with a bare context.workspace.join instead of routing through ToolContext::resolve_path. The pre-join lexical check rejects absolute paths, Windows prefixes, and parent-dir components but never canonicalizes, so a symlink inside the workspace whose name ends in an image extension and whose target sits outside the workspace is read transparently. The tool has ReadOnly capability and the trait default makes it auto-approved, so the bypass executes with no user prompt.

Details

In crates/tui/src/vision/tools.rs (v0.8.37, lines 104-123):

async fn execute(&self, input: Value, context: &ToolContext) -> Result<ToolResult, ToolError> {
    let image_path = required_str(&input, "image_path")?;
    let prompt = input
        .get("prompt")
        .and_then(|v| v.as_str())
        .unwrap_or("Describe this image in detail.");

    let image_path_buf = Path::new(image_path);
    if image_path_buf.components().any(|c| {
        matches!(
            c,
            Component::Prefix(_) | Component::RootDir | Component::ParentDir
        )
    }) {
        return Err(ToolError::execution_failed(
            "image_path must be a relative path within the workspace and cannot escape it.",
        ));
    }
    let resolved_path = context.workspace.join(image_path_buf);
    let (image_data, mime_type) = Self::read_image_file(&resolved_path).await?;

read_image_file (lines 31-39) is a tokio::fs::read(path) call which follows symlinks. The bytes are then base64-encoded and embedded as data:<mime>;base64,<bytes> in the chat-completion payload that is POSTed to ${base_url}/chat/completions with the user's Authorization header.

The lexical guard rejects ../etc/passwd, /etc/passwd, and C:\Windows\..., but a symlink such as workspace/screenshot.png -> /etc/passwd produces components [Normal("screenshot.png")]. None of Prefix, RootDir, or ParentDir match, so the check passes and the symlink is followed at read time.

The peer file-reading tools all use the central resolver instead. For example, crates/tui/src/tools/image_ocr.rs:60-65:

let path_str = required_str(&input, "path")?;
let image_path = context.resolve_path(path_str)?;

resolve_path in crates/tui/src/tools/spec.rs:342-449 canonicalizes the candidate and rejects results whose canonical form does not start with the canonical workspace path:

if candidate.exists() {
    let canonical = candidate.canonicalize().map_err(...)?;
    if !canonical.starts_with(&workspace_canonical)
        && !self.is_trusted_external_path(&canonical)
    {
        return Err(ToolError::PathEscape { path: canonical });
    }
    ...
}

In the same symlink scenario, image_ocr, pandoc_convert, read_file, apply_patch, rlm_open, and fim all return ToolError::PathEscape because the canonical target falls outside the workspace. image_analyze is the lone caller that skips this check.

The tool declares ToolCapability::ReadOnly and does not override approval_requirement(). The trait default (crates/tui/src/tools/spec.rs:612-620) resolves ReadOnly to ApprovalRequirement::Auto. The engine then sets approval_required = spec.approval_requirement() != ApprovalRequirement::Auto, which is false for this tool (crates/tui/src/core/engine/turn_loop.rs:1159-1184). The model can invoke image_analyze on any turn without a user prompt.

The recent commit 2326220 fix(vision): reject rooted image paths on windows (2026-05-12) tightened the lexical guard to catch Windows drive prefixes, but the original review missed that the underlying problem is that this site never used resolve_path in the first place.

PoC

A standalone Cargo test reproduces the read-through. Save as crates/tui/tests/image_analyze_symlink_escape.rs:

use deepseek_tui::config::VisionModelConfig;
use deepseek_tui::tools::spec::{ToolContext, ToolSpec};
use deepseek_tui::vision::tools::ImageAnalyzeTool;
use serde_json::json;
use std::fs;
use tempfile::tempdir;

#[tokio::test]
#[cfg(unix)]
async fn image_analyze_follows_workspace_symlink_outside_workspace() {
    let outer = tempdir().unwrap();
    let workspace = outer.path().join("workspace");
    let outside = outer.path().join("outside");
    fs::create_dir_all(&workspace).unwrap();
    fs::create_dir_all(&outside).unwrap();

    // A file that the workspace boundary should keep the tool from reading.
    let secret = outside.join("secret.txt");
    fs::write(&secret, b"OUTSIDE-WORKSPACE-SECRET-MARKER").unwrap();

    // Pre-existing symlink in the workspace with an image extension.
    std::os::unix::fs::symlink(&secret, workspace.join("screenshot.png")).unwrap();

    let ctx = ToolContext::new(workspace);
    let tool = ImageAnalyzeTool::new(VisionModelConfig {
        model: "test".into(),
        api_key: Some("test".into()),
        base_url: Some("http://127.0.0.1:1/v1".into()),
    });

    // The execute call will fail at the HTTP layer because the mock endpoint
    // is unreachable, but read_image_file has already been called. Reach the
    // file-read step by asserting that the failure is the HTTP error, not a
    // PathEscape error from the resolver.
    let err = tool
        .execute(json!({"image_path": "screenshot.png"}), &ctx)
        .await
        .expect_err("expected HTTP failure after symlink read");
    let msg = format!("{err:?}");
    assert!(
        !msg.contains("PathEscape"),
        "symlink should have been refused before read; got {msg}"
    );
    // To prove the bytes actually left the process, point base_url at a
    // capturing wiremock instance and assert that the OUTSIDE-WORKSPACE-SECRET-MARKER
    // substring appears in the captured base64-decoded request body.
}

For comparison, the same workspace exercised via read_file returns ToolError::PathEscape:

#[tokio::test]
#[cfg(unix)]
async fn read_file_refuses_workspace_symlink_outside_workspace() {
    use deepseek_tui::tools::file::ReadFileTool;
    let outer = tempdir().unwrap();
    let workspace = outer.path().join("workspace");
    let outside = outer.path().join("outside");
    fs::create_dir_all(&workspace).unwrap();
    fs::create_dir_all(&outside).unwrap();
    fs::write(outside.join("secret.txt"), b"X").unwrap();
    std::os::unix::fs::symlink(outside.join("secret.txt"), workspace.join("link.txt")).unwrap();

    let ctx = ToolContext::new(workspace);
    let err = ReadFileTool
        .execute(json!({"path": "link.txt"}), &ctx)
        .await
        .expect_err("expected PathEscape");
    assert!(format!("{err:?}").contains("PathEscape"));
}

The fix is one line on crates/tui/src/vision/tools.rs:122:

- let resolved_path = context.workspace.join(image_path_buf);
+ let resolved_path = context.resolve_path(image_path)?;

resolve_path already handles the pre-join lexical checks (so the existing Path::new(image_path).components().any(...) block can also be removed), canonicalizes through symlinks, and re-checks workspace containment. The behavior the lexical guard already promises (path stays inside the workspace) is then actually delivered.

Impact

A workspace symlink whose name ends in .png, .jpg, .jpeg, .gif, .webp, or .bmp and whose target sits outside the workspace becomes a read primitive that the model can invoke without an approval prompt. The file bytes are base64-encoded into the image_url.url field of the chat-completion payload and POSTed to the configured vision endpoint along with the user's bearer token. Three exposure channels follow from a single invocation: the vision provider receives every byte of the target file in plaintext (most providers retain request bodies for abuse review or model training), any TLS-terminating corporate proxy on the egress path captures the same bytes, and any transparent middlebox with MITM visibility logs the payload. The preconditions are everyday workspace shapes: cloned repositories that ship symlinks to shared media (CI artifact bundles, photo libraries, design assets), a developer who staged an external file via ln -s, or a git clone with core.symlinks=true against a repository that includes such a link. Because the tool is auto-approved, a prompt-injection delivered through a poisoned README, fetched web page, or MCP server output can issue {"image_path": "screenshot.png"} and the bytes leave the machine on the same turn without any visible UI cue. The fix is identical to the pattern used by every other file-reading tool in this codebase, so the gap is a missed resolve_path call rather than a design tradeoff.

References

@Hmbown Hmbown published to codewhale-hq/Codewhale Jul 16, 2026
Published by the National Vulnerability Database Aug 18, 2026
Published to the GitHub Advisory Database Sep 4, 2026
Reviewed Sep 4, 2026

Severity

High

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v4 base metrics

Exploitability Metrics
Attack Vector Network
Attack Complexity Low
Attack Requirements None
Privileges Required None
User interaction None
Vulnerable System Impact Metrics
Confidentiality High
Integrity None
Availability None
Subsequent System Impact Metrics
Confidentiality None
Integrity None
Availability None

CVSS v4 base metrics

Exploitability Metrics
Attack Vector: This metric reflects the context by which vulnerability exploitation is possible. This metric value (and consequently the resulting severity) will be larger the more remote (logically, and physically) an attacker can be in order to exploit the vulnerable system. The assumption is that the number of potential attackers for a vulnerability that could be exploited from across a network is larger than the number of potential attackers that could exploit a vulnerability requiring physical access to a device, and therefore warrants a greater severity.
Attack Complexity: This metric captures measurable actions that must be taken by the attacker to actively evade or circumvent existing built-in security-enhancing conditions in order to obtain a working exploit. These are conditions whose primary purpose is to increase security and/or increase exploit engineering complexity. A vulnerability exploitable without a target-specific variable has a lower complexity than a vulnerability that would require non-trivial customization. This metric is meant to capture security mechanisms utilized by the vulnerable system.
Attack Requirements: This metric captures the prerequisite deployment and execution conditions or variables of the vulnerable system that enable the attack. These differ from security-enhancing techniques/technologies (ref Attack Complexity) as the primary purpose of these conditions is not to explicitly mitigate attacks, but rather, emerge naturally as a consequence of the deployment and execution of the vulnerable system.
Privileges Required: This metric describes the level of privileges an attacker must possess prior to successfully exploiting the vulnerability. The method by which the attacker obtains privileged credentials prior to the attack (e.g., free trial accounts), is outside the scope of this metric. Generally, self-service provisioned accounts do not constitute a privilege requirement if the attacker can grant themselves privileges as part of the attack.
User interaction: This metric captures the requirement for a human user, other than the attacker, to participate in the successful compromise of the vulnerable system. This metric determines whether the vulnerability can be exploited solely at the will of the attacker, or whether a separate user (or user-initiated process) must participate in some manner.
Vulnerable System Impact Metrics
Confidentiality: This metric measures the impact to the confidentiality of the information managed by the VULNERABLE SYSTEM due to a successfully exploited vulnerability. Confidentiality refers to limiting information access and disclosure to only authorized users, as well as preventing access by, or disclosure to, unauthorized ones.
Integrity: This metric measures the impact to integrity of a successfully exploited vulnerability. Integrity refers to the trustworthiness and veracity of information. Integrity of the VULNERABLE SYSTEM is impacted when an attacker makes unauthorized modification of system data. Integrity is also impacted when a system user can repudiate critical actions taken in the context of the system (e.g. due to insufficient logging).
Availability: This metric measures the impact to the availability of the VULNERABLE SYSTEM resulting from a successfully exploited vulnerability. While the Confidentiality and Integrity impact metrics apply to the loss of confidentiality or integrity of data (e.g., information, files) used by the system, this metric refers to the loss of availability of the impacted system itself, such as a networked service (e.g., web, database, email). Since availability refers to the accessibility of information resources, attacks that consume network bandwidth, processor cycles, or disk space all impact the availability of a system.
Subsequent System Impact Metrics
Confidentiality: This metric measures the impact to the confidentiality of the information managed by the SUBSEQUENT SYSTEM due to a successfully exploited vulnerability. Confidentiality refers to limiting information access and disclosure to only authorized users, as well as preventing access by, or disclosure to, unauthorized ones.
Integrity: This metric measures the impact to integrity of a successfully exploited vulnerability. Integrity refers to the trustworthiness and veracity of information. Integrity of the SUBSEQUENT SYSTEM is impacted when an attacker makes unauthorized modification of system data. Integrity is also impacted when a system user can repudiate critical actions taken in the context of the system (e.g. due to insufficient logging).
Availability: This metric measures the impact to the availability of the SUBSEQUENT SYSTEM resulting from a successfully exploited vulnerability. While the Confidentiality and Integrity impact metrics apply to the loss of confidentiality or integrity of data (e.g., information, files) used by the system, this metric refers to the loss of availability of the impacted system itself, such as a networked service (e.g., web, database, email). Since availability refers to the accessibility of information resources, attacks that consume network bandwidth, processor cycles, or disk space all impact the availability of a system.
CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:N/VA:N/SC:N/SI:N/SA:N

EPSS score

Exploit Prediction Scoring System (EPSS)

This score estimates the probability of this vulnerability being exploited within the next 30 days. Data provided by FIRST.
(43rd percentile)

Weaknesses

Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')

The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory. Learn more on MITRE.

Improper Link Resolution Before File Access ('Link Following')

The product attempts to access a file based on the filename, but it does not properly prevent that filename from identifying a link or shortcut that resolves to an unintended resource. Learn more on MITRE.

CVE ID

CVE-2026-75914

GHSA ID

GHSA-w7wx-5q49-r59w

Source code

Credits

Loading Checking history
See something to contribute? Suggest improvements for this vulnerability.