Skip to content

Commit dc7e2ad

Browse files
fix(opencode,core): close audit-v10 wave G findings
- instance-store: claim the entry before draining so an explicit dispose tears down a leased instance and rejects pending prompts (R-V10-01), while keeping the W5 provide-after-dispose handshake; reinstate the F4a race harness - shell: resolve ~+ / ~- / ~N without path.join so symlink+`..` still scans; shell-unescape backslash escapes before classification; anchor the scan at the root for cd/pushd/popd with an unresolvable target and refuse always - fs-util: stop lexically collapsing `..` after a non-existent component (glob-anchor / dangling-symlink escape) and split only on `/` on unix - wildcard: unescape `\.` so an escaped traversal cannot match a persisted literal grant - catalog: validate schema-map values, `type` members and `dependentRequired`; make dropDanglingRefs scope- and instance-aware; declare ajv as a devDependency of packages/opencode so the schema gate is hermetic - tests: fail-on-base coverage for every probe
1 parent 02750b7 commit dc7e2ad

11 files changed

Lines changed: 405 additions & 77 deletions

File tree

‎bun.lock‎

Lines changed: 2 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/core/src/fs-util.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,9 @@ export namespace FSUtil {
288288
const root = parse(absolute).root || sep
289289
let current = root
290290
const remainder: string[] = []
291-
const parts = absolute.slice(root.length).split(/[\\/]+/)
291+
// On unix a backslash is an ordinary filename character, not a separator, so
292+
// splitting on it would hide a literal `..`-looking component from the check below.
293+
const parts = absolute.slice(root.length).split(process.platform === "win32" ? /[\\/]+/ : "/")
292294
for (let index = 0; index < parts.length; index++) {
293295
const part = parts[index]
294296
if (part === "" || part === ".") continue
@@ -306,7 +308,14 @@ export namespace FSUtil {
306308
break
307309
}
308310
}
309-
return remainder.length > 0 ? normalizePath(join(current, ...remainder)) : normalizePath(current)
311+
if (remainder.length === 0) return normalizePath(current)
312+
// Once a component does not exist the kernel cannot follow anything after it, so the
313+
// real target is unknowable. A `..` in that remainder cannot be collapsed lexically:
314+
// `*/../linkroot/../etc` resolves to `<cwd>/etc` that way while a glob-selected
315+
// symlink makes bash read `/etc`. Treat any such `..` as escaping and anchor at the
316+
// filesystem root so containment fails and the external-directory prompt fires.
317+
if (remainder.includes("..")) return normalizePath(root)
318+
return normalizePath(join(current, ...remainder))
310319
}
311320

312321
export function windowsPath(p: string): string {

‎packages/core/src/util/wildcard.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ function unquote(value: string) {
3131
quote = char
3232
continue
3333
}
34-
if (char === "\\" && index + 1 < value.length && SHELL_ESCAPES.has(value[index + 1])) {
34+
// `\.` is `..` after the shell strips the escape, so an escaped traversal must
35+
// unescape here too or it slips past the TRAVERSAL check below. A backslash is a
36+
// Windows separator, not an escape, so only unix honours the dot escape.
37+
const escaped = index + 1 < value.length && (SHELL_ESCAPES.has(value[index + 1]) || nextIsDotEscape(value, index))
38+
if (char === "\\" && escaped) {
3539
out += value[++index]
3640
continue
3741
}
@@ -40,6 +44,10 @@ function unquote(value: string) {
4044
return out
4145
}
4246

47+
function nextIsDotEscape(value: string, index: number) {
48+
return process.platform !== "win32" && value[index + 1] === "."
49+
}
50+
4351
function glob(pattern: string, strict: boolean) {
4452
const cacheKey = (strict ? "strict:" : "glob:") + pattern
4553
const cached = compiled.get(cacheKey)

‎packages/core/test/wildcard.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ describe("Wildcard.match", () => {
8181
expect(Wildcard.matchStrict("cat foo.txt", "cat *")).toBe(true)
8282
})
8383

84+
test("matchStrict refuses backslash-escaped traversal", () => {
85+
expect(Wildcard.matchStrict("cat \\.\\./etc/passwd", "cat *")).toBe(false)
86+
expect(Wildcard.matchStrict("cat \\.\\./\\.\\./etc/passwd", "cat *")).toBe(false)
87+
expect(Wildcard.matchStrict("cat \\../etc/passwd", "cat *")).toBe(false)
88+
// An escaped dot that does not form `..` is an ordinary hidden path.
89+
expect(Wildcard.matchStrict("cat \\.hidden", "cat *")).toBe(true)
90+
})
91+
8492
test("matchStrict leaves file-path grants unaffected by traversal guards", () => {
8593
expect(Wildcard.matchStrict("../sibling/file.txt", "../sibling/*")).toBe(true)
8694
expect(Wildcard.matchStrict("./nested/file.txt", "./nested/*")).toBe(true)

‎packages/opencode/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"@types/turndown": "5.0.5",
4646
"@types/yargs": "17.0.33",
4747
"@typescript/native-preview": "catalog:",
48+
"ajv": "8.20.0",
4849
"drizzle-orm": "catalog:",
4950
"prettier": "3.6.2",
5051
"typescript": "catalog:",

0 commit comments

Comments
 (0)