MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / validateTeamMemWritePath

Function validateTeamMemWritePath

source code/memdir/teamMemPaths.ts:230–258  ·  view source on GitHub ↗
(
  filePath: string,
)

Source from the content-addressed store, hash-verified

228 * directory via .. segments, or escapes via a symlink (PSR M22186).
229 */
230export async function validateTeamMemWritePath(
231 filePath: string,
232): Promise<string> {
233 if (filePath.includes('\0')) {
234 throw new PathTraversalError(`Null byte in path: "${filePath}"`)
235 }
236 // First pass: normalize .. segments and check string-level containment.
237 // This is a fast rejection for obvious traversal attempts before we touch
238 // the filesystem.
239 const resolvedPath = resolve(filePath)
240 const teamDir = getTeamMemPath()
241 // Prefix attack protection: teamDir already ends with sep (from getTeamMemPath),
242 // so "team-evil/" won't match "team/"
243 if (!resolvedPath.startsWith(teamDir)) {
244 throw new PathTraversalError(
245 `Path escapes team memory directory: "${filePath}"`,
246 )
247 }
248 // Second pass: resolve symlinks on the deepest existing ancestor and verify
249 // the real path is still within the real team dir. This catches symlink-based
250 // escapes that path.resolve() alone cannot detect.
251 const realPath = await realpathDeepestExisting(resolvedPath)
252 if (!(await isRealPathWithinTeamDir(realPath))) {
253 throw new PathTraversalError(
254 `Path escapes team memory directory via symlink: "${filePath}"`,
255 )
256 }
257 return resolvedPath
258}
259
260/**
261 * Validate a relative path key from the server against the team memory directory.

Callers

nothing calls this directly

Calls 4

getTeamMemPathFunction · 0.85
realpathDeepestExistingFunction · 0.85
isRealPathWithinTeamDirFunction · 0.85
resolveFunction · 0.50

Tested by

no test coverage detected