Skip to content

Commit 83fba35

Browse files
sahrizviclaude
andcommitted
fix(workspace): refuse a filesystem root as the boundary on its resolved path
The refusal was judged on the lexical root while the containment comparison below it used the real path — so a root that is a symbolic link to `/` passed the first and became `/` for the second. The root is resolved once, refused on that value, and the same value bounds the skill. Verified: 668 pass, typecheck clean; judging the root lexically fails the new link-to-`/` case. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012Q51zFUmPg1WwtS5CrGJE6
1 parent eec91fd commit 83fba35

2 files changed

Lines changed: 20 additions & 11 deletions

File tree

‎packages/opencode/src/altimate/workspace/skill-publish.ts‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -793,11 +793,20 @@ function updateConflict(err: ConflictError, skillName: string): Error {
793793
* the boundary rule has to hold for every caller, and a root of `/` — the
794794
* sentinel a project with no git carries — is not a boundary at all. */
795795
export function assertProjectSkill(projectRoot: string, skillDirectory: string): string {
796-
// A filesystem root would contain everything. Both callers substitute the
797-
// session directory for the `/` sentinel; this refuses it in case one
798-
// forgets, since the failure mode is publishing anything on the machine.
799-
if (path.resolve(projectRoot) === path.parse(path.resolve(projectRoot)).root)
800-
throw new NotProjectSkillError(skillDirectory)
796+
// The boundary is the root's REAL path, resolved once and used for both
797+
// checks below. A filesystem root would contain everything: both callers
798+
// substitute the session directory for the `/` sentinel, and this refuses
799+
// it in case one forgets, since the failure mode is publishing anything
800+
// on the machine. Judged after resolving — a root that is a symbolic link
801+
// to `/` is `/` for the containment comparison, so it must be refused on
802+
// the same value that comparison uses.
803+
let root: string
804+
try {
805+
root = realpathSync(projectRoot)
806+
} catch {
807+
root = path.resolve(projectRoot)
808+
}
809+
if (root === path.parse(root).root) throw new NotProjectSkillError(skillDirectory)
801810
const lexical = path.resolve(skillDirectory)
802811
let real: string
803812
try {
@@ -817,12 +826,6 @@ export function assertProjectSkill(projectRoot: string, skillDirectory: string):
817826
return lexical
818827
}
819828
if (real !== path.join(parentReal, path.basename(lexical))) throw new NotProjectSkillError(skillDirectory)
820-
let root: string
821-
try {
822-
root = realpathSync(projectRoot)
823-
} catch {
824-
root = path.resolve(projectRoot)
825-
}
826829
const rel = path.relative(root, real)
827830
// Parent traversal exactly, not any name that begins with two dots: a
828831
// skill directory literally named `..foo` is inside the project.

‎packages/opencode/test/altimate/workspace/skill-publish.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,12 @@ describe("what counts as a project skill", () => {
687687
const elsewhere = mkdtempSync(path.join(SANDBOX, "elsewhere-"))
688688
writeFileSync(path.join(elsewhere, "SKILL.md"), "---\nname: x\n---\n")
689689
expect(() => assertProjectSkill("/", elsewhere)).toThrow(NotProjectSkillError)
690+
// And a root that is merely a LINK to `/`: lexically it is a directory
691+
// inside the sandbox, but the containment comparison resolves it, and
692+
// the refusal must be judged on that same resolved value.
693+
const rootLink = path.join(SANDBOX, `root-link-${Math.random().toString(36).slice(2)}`)
694+
symlinkSync("/", rootLink)
695+
expect(() => assertProjectSkill(rootLink, elsewhere)).toThrow(NotProjectSkillError)
690696
// The same skill against the session directory: outside it, refused;
691697
// inside it, allowed.
692698
expect(() => assertProjectSkill(project, elsewhere)).toThrow(NotProjectSkillError)

0 commit comments

Comments
 (0)