MCPcopy Index your code
hub / github.com/simstudioai/sim / resolveRepoPath

Function resolveRepoPath

apps/sim/executor/handlers/pi/ssh-tools.ts:75–85  ·  view source on GitHub ↗

Resolves a tool-supplied path against `repoPath`, rejecting traversal/escape.

(repoPath: string, candidate: string)

Source from the content-addressed store, hash-verified

73
74/** Resolves a tool-supplied path against `repoPath`, rejecting traversal/escape. */
75function resolveRepoPath(repoPath: string, candidate: string): string {
76 const clean = sanitizePath(candidate)
77 const root = repoPath.replace(/\/+$/, '')
78 if (clean.startsWith('/')) {
79 if (clean !== root && !clean.startsWith(`${root}/`)) {
80 throw new Error(`Path is outside the repository: ${candidate}`)
81 }
82 return clean
83 }
84 return `${root}/${clean}`
85}
86
87function asString(value: unknown): string {
88 return typeof value === 'string' ? value : ''

Callers 1

buildSshToolSpecsFunction · 0.85

Calls 2

sanitizePathFunction · 0.90
replaceMethod · 0.65

Tested by

no test coverage detected