Skip to content

fix(server): confine ask_operator image_path to the task directory - #337

Merged
BaaRai merged 3 commits into
BaaRai:mainfrom
Coff0xc:fix/ask-operator-image-path
Nov 18, 2026
Merged

BaaRai merged 3 commits into
BaaRai:mainfrom
Coff0xc:fix/ask-operator-image-path

Conversation

@Coff0xc

@Coff0xc Coff0xc commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

ask_operator copied image_path with only an extension and size check. A worker could pass an absolute path (or a symlink) to any readable image on the host, including another task's uploads, and that file was staged into the operator transcript.

The path is now resolved from the task working directory (<data>/tasks/<id>, the worker CWD). .. segments, paths that EvalSymlinks outside that directory, and non-regular files are refused. Relative paths such as a screenshot next to the worker still work.

Tested: go test ./server -run TestStageAskOperatorImage pass. The symlink-out case is skipped on this Windows host (no symlink privilege); .. and absolute paths outside the task dir are refused.

Copilot AI balanced review requested due to automatic review settings November 18, 2026 11:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@BaaRai BaaRai left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The confinement logic is right: relative paths resolve from the task directory, absolute paths are accepted only after symlink resolution stays inside it, and .. plus non-regular files are refused. The tests cover the outside file, the other task, and the escaping symlink. A later hardening could open the final file with O_NOFOLLOW or os.Root to close the check-to-open race, but that is not required for the reported issue. Thanks.

offset+length > size wraps when length is near MaxInt64, so the cap is
skipped and make([]byte, length) can exhaust memory. Compare length
against size-offset instead.
insert_assets swallowed ListAssetInterceptRules and
TaskInterceptRulesSplit errors and evaluated an empty rule set, which
allowed every asset. A load failure now refuses the whole call. The
tool result is generic; the driver error stays in the process log.
image_path was opened as a raw filesystem path, so any readable
png/jpg/jpeg/webp/gif on the host could be copied into the operator
transcript. The path is now resolved from the task working directory
and refused when it contains .. or EvalSymlinks outside that tree.
@BaaRai
BaaRai force-pushed the fix/ask-operator-image-path branch from 98831d9 to 2031033 Compare November 18, 2026 16:22
@BaaRai
BaaRai merged commit d89cf78 into BaaRai:main Nov 18, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants