Skip to content

fix(skill): block path traversal in skill materialization and disambiguate skillId - #3787

Merged
jujn merged 1 commit into
agentscope-ai:mainfrom
xzxiaoshan:fix/skill-mirror-0a-name-guard
Oct 27, 2026
Merged

jujn merged 1 commit into
agentscope-ai:mainfrom
xzxiaoshan:fix/skill-mirror-0a-name-guard

Conversation

@xzxiaoshan

@xzxiaoshan xzxiaoshan commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

What

  • Enforce the Agent Skills standard naming rule at construction. A skill name must match ^[a-z0-9][a-z0-9-]*$ and be at most 64 characters; AgentSkill (and therefore SkillUtil.createFrom / createFromZip and every repository load path) rejects anything else with IllegalArgumentException.
  • Consolidate every validation and containment judgment into SkillUtil — the single source of truth: VALID_SKILL_NAME_PATTERN, MAX_SKILL_NAME_LENGTH, isValidSkillName, requireValidSkillName, and resolveContainedPath (resolve → normalize → startsWith). SkillBox.uploadSkillFiles runs both the skill directory (whose id's source part is free-form) and every resource path through resolveContainedPath, refusing to write anything that escapes the upload root. The upcoming skill-mirror writer reuses the same helpers instead of re-implementing them.
  • Align the harness authoring tool (skill_manage) with the shared core constants, so creation and construction reject exactly the same names.
  • Structurally eliminate the skillId separator ambiguity : with underscores banned from names, name + "_" + source always splits at the first underscore, so distinct (name, source) pairs can no longer collide and silently overwrite each other in SkillRegistry (a warning tripwire remains as a guard against future rule relaxations).
  • Document the naming rule in the EN/ZH skill pages, citing the industry naming standard for Agent Skills.

Why

Skill development is the developer's responsibility. Following the industry-standard naming convention — as with HTTP or any other protocol — is part of that responsibility, not something the framework should absorb. Carrying compatibility for non-standard names endlessly is the wrong direction for a framework: besides being unsafe as directory keys (path traversal via Path.resolve replacing the base with absolute segments, .. segments cancelling their way out, platform-illegal characters), free-form names leak into namespace-like concatenations inside the skill runtime — skillId = name + "_" + source becomes ambiguous the moment a name may contain the separator, and that ambiguity propagates into serialized session state (activated_groups tool-group names) and prompts.

Concretely, before this change a frontmatter name: /tmp/evil turned targetDir.resolve(skillId) into a path outside the skills root while the containment check still passed — files were written outside the sandbox.

Conformance note

Strictly validating skill names against the industry standard should not be treated as a breaking change of this framework — strictly speaking, it is a more rigorous implementation of that standard. The name field was never free-form in the Agent Skills ecosystem; the previous under-enforcement is exactly what allowed the path-traversal and skillId-ambiguity defects fixed here. For skills that already follow the standard, nothing changes.

Behavior change / migration

  • Names with uppercase letters, non-ASCII characters, underscores, dots, path shapes, or longer than 64 chars now fail construction with a descriptive error.
  • Repository enumeration isolates the failure per skill (FileSystem / Classpath / Git via SkillFileSystemHelper, Workspace per-skill catch): a non-conforming skill is skipped with a warning naming the rule — one bad skill never hides the whole repository.
  • The skillId format is unchanged; serialized session state and in-flight prompts for conforming skills are unaffected.
  • In-repo skill names (tests, javadoc examples) were migrated to the standard charset; SKILL.md fixtures were already conformant. EN/ZH docs now state the naming rule.

…guate skillId

Enforce the Agent Skills standard naming rule (^[a-z0-9][a-z0-9-]*$, max 64) at
AgentSkill construction, consolidating all validation and containment judgments
in SkillUtil (requireValidSkillName, resolveContainedPath). uploadSkillFiles
runs the skill directory and every resource path through resolveContainedPath,
refusing anything that escapes the upload root (absolute segments replace the
resolve base; '..' in the free-form source part can cancel its way out). The
harness skill_manage authoring tool now references the shared core constants.

Banning underscores from names makes the name_source skillId split
deterministic, structurally eliminating the registry's silent same-id
overwrite ambiguity; a warning tripwire remains against future rule
relaxations. Strict validation is a more rigorous implementation of the
industry standard, not a breaking redesign: for conforming skills nothing
changes, and repository enumeration isolates rejections per skill.
@mintlify

mintlify Bot commented Oct 27, 2026

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 9b47869.

Approve preview

@jujn
jujn merged commit 2f8f92a into agentscope-ai:main Oct 27, 2026
7 checks passed
xzxiaoshan added a commit that referenced this pull request Oct 27, 2026
…le lock map (#3795)

Two targeted fixes in the skill materialisation path:

- `DynamicSkillMiddleware.computeSignature` copied the whole resource
map on every key inside the hash loop (O(n²) per skill). It now
enumerates keys once via `getResourcePaths()` and reads values with
per-key `getResource()`; the hashed bytes — and therefore signature
values — are unchanged (pinned by a golden-value regression test).
- `SkillBox.FILE_LOCKS` was a static per-path lock map that accumulated
one lock object per materialised path and was never cleaned. It is
replaced by a fixed 256-stripe lock table (`floorMod(pathHash, N)`):
same-path mutual exclusion is preserved, unrelated paths colliding on a
stripe merely serialise, and lock memory no longer grows with path
count.

Also includes (kept as separate commits):
- Merge of upstream/main; while resolving it, the two
`DynamicSkillMiddlewareTest` fixtures added by #3792 still used
`my_skill`, which the skill-name validation from #3787 rejects — renamed
to `my-skill` following the convention #3787 itself applied to the older
fixtures.
- `test(channel)`: deflake
`BotLoopGuardTest.activePeersSurviveEvictionOfIdleOnes` — `allow()`
piggybacks a sweep on the same threshold idle eviction uses, so a ~100ms
runner stall (e.g. under `mvn -T1C`) let the sweep evict the idle peer
before the explicit `evictIdlePeers()` assertion. Rebalanced sleeps for
a 400ms stall margin; assertions unchanged.

Verified with `mvn -T1C -pl agentscope-core -am test` (2805 tests, 0
failures) and `spotless:check`.
Buktal added a commit that referenced this pull request Oct 28, 2026
## AgentScope-Java Version

2.1.0-SNAPSHOT

## Description

Refs #3794, review unit 3 of 3. Synthetic messages can be durable
conversation records or request-only projections. Treating both as
transient moves persisted notifications out of order and keeps them
outside compaction. Comparing copied/restored messages by Java
object/value types can also prevent a valid summary from being written
back.

## Summary

```text
canonical history (including persisted synthetic notifications)
  -> ordered conversation -> budget/compact -> guarded summary writeback
request-only projections
  -> current request only
overflow retry
  -> latest canonical history + surviving request projections
system sources
  -> one System message / one TextBlock, joined by blank lines
```

- Use canonical membership/IDs to distinguish persisted notifications
from transient projections, retaining ordinary history order, budgeting,
and compaction behavior.
- Require complete serialized-history equality before durable writeback.
Use the configured JSON codec and a precision-preserving JSON-tree
comparison so restored number types match while edited content,
metadata, and high-precision decimal values do not.
- Rebuild overflow retries from current history without reviving
compacted-away notifications. Preserve concurrent-history and
final-budget rejection guards.
- Clarify the synthetic marker's lifetime contract and update
English/Chinese context documentation.

## Evidence

- **Before:** with the old history comparison, JSON-restored
notification cases failed summary persistence: 3 failures in a 37-test
context/compaction regression run.
**After:** all 37 passed after the numeric-comparison fix, including
protection for distinct `1.0000000000000000001` and
`1.0000000000000000002` metadata. `ContextPipelineV2Test` also covers
copied/converted notifications, same-ID edits, single-block system text,
final-budget rejection, and concurrent changes;
`CompactionMiddlewareTest` covers overflow reconstruction.
- Independent branch: `mvn -B -T1C clean verify` passed across 99
modules: **11,317 tests**, 0 failures/errors, **242 skipped**. Spotless
ran without skip flags. Docs: `npm test` (13/13) and `npm run validate`
(432 pages, 584 redirects, Mintlify build) passed. `npm run
broken-links` reports 2,218 links across 326 files, the same counts
recorded before; individual links were not baseline-attributed.
- Includes the shared three-line `my_skill` -> `my-skill` test-fixture
correction needed after #3787/#3792. It is also in both sibling PRs so
these branches validate independently and can merge in any order.

## Merge Danger

**Door:** two-way

No serialized-state schema change. The existing synthetic marker
continues to identify origin; canonical membership determines whether a
message is durable.

**Blast Radius:** context

Changes request layout, compaction eligibility, summary writeback, and
overflow retries. Fake-model regressions verify these paths; provider
cache behavior and task quality were not benchmarked. #3780's older
streaming/backport and custom memory-flush-prompt concerns are separate.

## Checklist

- [x] Spotless formatting check passes as part of full verification
- [x] All executed tests pass; skipped-test count is reported above
- [x] Javadoc updated for changed contracts
- [x] Related English and Chinese documentation updated
- [x] Code ready for review
xzxiaoshan added a commit to xzxiaoshan/agentscope-java that referenced this pull request Nov 11, 2026
…_source semantics

Review feedback #2 (scope reduction): the skillId format, default source
and same-name merge changes were not required for the grant layer.

- separator: SKILL_ID_SEPARATOR moves to SkillUtil and reverts to "_";
  getSkillId() always composes name + "_" + source
- restore the "custom" default source and the strict name charset
  (^[a-z0-9][a-z0-9-]*$, no underscores — PR agentscope-ai#3787)
- catalogs merge by name again: same name keeps the higher-priority copy
- grant vocabulary is the skill name: convention groups resolve by backward
  derivation (group name -> name part), activateOnSkill bindings expand at
  the call entry via the new SkillUtil.parseSkillName
- allowedSkills additionally honours an exact full-skillId entry as a
  program-level compatibility (javadoc-documented; user docs stay name-only)

Unconfigured behavior is unchanged from main; the grant layer (gates,
filters, inheritance, ordering) is untouched.
juruoO-o added a commit to 25344xiaoning/agentscope-java that referenced this pull request Nov 11, 2026
Resolve docs conflicts by keeping main's per-call (PreCall) staging wording
and NONE-for-inline-only paragraph alongside this PR's <scope> cache layout
and grace-period orphan GC notes.

Adapt MarketplaceStagerPathTest to main's construction-time skill name
validation (agentscope-ai#3787): unsafe names now reach the stager only through custom
repositories, so tests supply them via mocks; the frontmatter test asserts
load-time rejection plus the stager's independent rejection.
chickenlj added a commit that referenced this pull request Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants