Skip to content

[Bug]: MarketplaceStager allows skill names to escape the staging cache #3313

Closed

Description

@25344xiaoning

Describe the bug

MarketplaceStager uses an unvalidated skill name to construct its staging directory:

scopeRoot.resolve(ns).resolve(name)

In agentscope-harness/src/main/java/io/agentscope/harness/agent/skill/runtime/MarketplaceStager.java, this directory is subsequently used for resource writes and stale-file cleanup.

The resource-path checks do not fully protect these operations because the staging directory itself may already point outside the cache.

Verified behavior:

  • An absolute-path skill name can create or overwrite resource files outside the workspace.
  • Stale-file cleanup can delete existing files in that destination.
  • A relative traversal name can cause cleanup outside the cache, even when the resource-path check blocks writing.
  • The absolute-path case also reproduces when the name is loaded from SKILL.md frontmatter inside an otherwise ordinary repository directory.
  • Source namespaces participate in the same unchecked path construction.

The affected operations run with the permissions of the JVM process. This finding concerns the Harness skill-staging path; it does not establish unconditional remote code execution or exposure in every agent configuration.

To Reproduce

Use an isolated temporary directory containing two sibling directories, workspace and outside.

  1. Create outside/keep.txt containing a harmless marker.
  2. Construct an AgentSkill whose name is the absolute path to outside, with a resource map containing marker.txt.
  3. Associate it with a non-WorkspaceSkillRepository repository using new MarketplaceStager.RepoBound(skill, repository).
  4. Call new MarketplaceStager(workspace).stage(...) with that entry and a normal source namespace.
  5. Inspect the temporary outside directory.

Actual result:

  • outside/marker.txt is written.
  • outside/keep.txt is deleted by stale-resource cleanup.
  • The staging result reports StageResult.Cached.

The same behavior can be reproduced by loading the absolute name from SKILL.md through FileSystemSkillRepository.

All verification used harmless files under a temporary test directory.

Expected behavior

Skill names and source namespaces must not redirect staging or cleanup outside their intended cache directories.

Invalid path components should be rejected before any filesystem mutation. The affected entry should receive StageResult.NONE, while valid skills continue staging normally.

Existing supported names that are safe directory components should remain compatible.

Error messages

The absolute-path case does not necessarily throw an exception. The failure is an unexpected filesystem mutation:

outside_write=true
outside_sentinel_removed=true
accepted_as_cached=true

For relative traversal, the observed result was:

outside_write=false
outside_sentinel_removed=true
accepted_as_cached=true

Environment (please complete the following information):

  • AgentScope-Java Version: 2.0.4-SNAPSHOT
  • Inspected revision: 857e3e6
  • Java Version: OpenJDK 21
  • OS: Windows 11

Additional context

I have prepared a focused local fix that:

  • Normalizes the cache root.
  • Validates both skill names and source namespaces as single directory components before materialization or cleanup.
  • Handles invalid paths through the existing per-skill failure handling.
  • Preserves normal staging, binary resources, and stale-resource cleanup.
  • Adds regression tests and updates the English and Chinese skill documentation.

Validation: 31 new regression cases passed; the focused suite completed with 79 tests, zero failures or errors, and one POSIX-only test skipped on Windows. Spotless, Javadoc generation, and documentation validation passed.

Happy to submit a PR for review.

Activity

  1. added
    bug
    on Sep 26, 2026
  2. 25344xiaoning commented on Sep 26, 2026

    @25344xiaoning
    ContributorAuthor

    Submitted PR #3314 to address this issue.

    The fix validates skill names and source namespaces before staging or cleanup, with regression tests and updated English/Chinese documentation. Local verification completed with 79 tests, zero failures or errors, and one platform-specific skip.

    Ready for review.

  3. oss-maintainer commented on Sep 26, 2026

    @oss-maintainer
    Collaborator

    Issue Evaluation (automated verification against main @ 857e3e6)

    Category: bug | Status: Confirmed | Severity: critical (host-side file write + recursive delete outside the workspace via untrusted skill metadata)

    All claims were reproduced against the unmodified MarketplaceStager from this tree:

    # Claim Verdict Evidence
    1 Staging dir is built from unchecked path components TRUE MarketplaceStager.java:236 — Path stagedDir = scopeRoot.resolve(ns).resolve(name);. name is skill.getName() and ns falls back to bound.repo().getSource() (:228-234); neither is validated, and stagedDir is never normalised or re-checked against scopeRoot
    2 The resource-path guard does not cover this TRUE :290-294 — target.startsWith(stagedDir) only constrains writes relative to stagedDir. When stagedDir itself is already outside <workspaceRoot>/.skills-cache/<scope>, the guard is satisfied by construction; for .. traversal it does block the write, but nothing bounds stagedDir itself
    3 Absolute-path name escapes and writes TRUE Path.resolve returns an absolute argument verbatim, so Files.createDirectories(stagedDir) (:274) and writeIfChanged (:305-317) act on the attacker-named directory; maybeMarkExecutable (:320) additionally sets +x on shebang/script-suffix files. Result is reported as StageResult.Cached (:243)
    4 Stale-file cleanup deletes outside the cache TRUE removeUnexpected(stagedDir, expected) (:301, body :372-403) walks stagedDir and deletes every regular file not in expected — with an escaped stagedDir that is an arbitrary outside directory; relative traversal reproduces the deletion even with writes blocked. touch(stagedDir) (:241) likewise escapes
    5 Reproducible from SKILL.md frontmatter TRUE FileSystemSkillRepository.getAllSkills() returns the frontmatter name verbatim; the git/MySQL/Nacos paths reach the same field. Upstream validation exists but not on this path — SkillManageTool.validateName and MysqlSkillRepository.validateSkillName (rejects /, \, ..) guard only the authoring/DB paths
    6 Source namespaces participate TRUE same :236 expression, ns from sourceNs/repo.getSource()

    Notable asymmetry: scope is sanitised — scopeSegment() (:189-206) flattens to [A-Za-z0-9._-], checks losslessness and length. The same treatment was simply never applied to ns/name, so this is a missing-check regression in one expression, not a design dispute.

    Blast radius. HarnessSkillMiddleware.stage() → stageAll() runs host-side before sandbox projection (HarnessAgent.java:2874-2878), so this bypasses the sandbox confinement that skill staging is supposed to provide. ShellPathPolicy.joinCache() then advertises the escaped path as <files-root> to the model. Threat model: a user or CI-added marketplace/git skill repository with crafted SKILL.md — untrusted data, executed with JVM process permissions. The report's caveat ("does not establish unconditional remote code execution in every configuration") is accurate.

    Existing tests (MarketplaceStagerOrphanGcTest, MarketplaceStagerExecBitTest, SharedWorkspaceSkillStagingE2ETest) have no absolute-name or traversal coverage, so nothing pins the contract.

    Agreed fix shape (matches the report): validate name and ns as single safe path components before any filesystem mutation — reject absolute paths, ./.. segments, separators and NUL, and assert scopeRoot.normalize().resolve(ns).resolve(name).normalize().startsWith(scopeRoot.normalize()). Throw inside the existing try at :237-248 so the entry falls into the per-skill StageResult.NONE handling, keeping valid skills staging as before. Add regression cases for absolute name, relative traversal name, absolute/traversal namespace, and frontmatter-sourced names, plus the same guard for sourceNs.

    Since you have already prepared a fix with regression tests and doc updates, we will not open a competing PR — please submit yours and we will review it against the checks above. If you would rather have us generate one, reply /approve.


    Automated evaluation by github-manager (oss-maintainer). Reply /approve to have us generate the PR, /revise <notes> to adjust the approach, or /reject to drop it.

  4. added
    area/harness
    on Sep 26, 2026
  5. oss-maintainer commented on Sep 29, 2026

    @oss-maintainer
    Collaborator

    Proposal window closed — no competing PR will be filed from this proposal window

    The 72 h feedback window opened by the evaluation above (5848613552, posted 2026-09-26T18:09:43Z) reached its bound on 2026-09-29T18:09:43Z. The thread carries no /approve, /revise or /reject directive from a maintainer or the reporter since that evaluation, so no automated PR will be generated from this window and PR generation is skipped here.

    The thread did answer the underlying question in another way. Community PR #3314 (fix(harness): prevent skill staging path traversal, authored by @25344xiaoning, who also reported this issue) targets exactly the seam the evaluation described — MarketplaceStager accepting a skill name that escapes the staging cache. As of this read #3314 is OPEN, not a draft, unmerged, head 65f6b32be6, and its review decision is already APPROVED.

    So the implementation path here is owned by a community PR that is waiting on a maintainer to land it. Filing a second PR against the same issue is precisely the collision this window policy exists to prevent, which is why the proposal is stood down rather than escalated.

    Nothing in this notice disputes the evaluation: unvalidated skill names reaching the staging path is a real path-traversal defect, and the reported finding stands. The productive thread now is #3314 — merge it, request changes, or close it. If #3314 is closed unmerged and this fix is still wanted, reply on this issue and the question will be re-evaluated against whatever main looks like at that point.

    Automated feedback-window maintenance by github-manager-bot

  6. added a commit that references this issue on Nov 11, 2026
    9cdaa81
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/harnessbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions