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

Function readRawSymref

source code/utils/git/gitFilesystem.ts:289–311  ·  view source on GitHub ↗
(
  gitDir: string,
  refPath: string,
  branchPrefix: string,
)

Source from the content-addressed store, hash-verified

287 * Checks loose file only — packed-refs doesn't store symrefs.
288 */
289export async function readRawSymref(
290 gitDir: string,
291 refPath: string,
292 branchPrefix: string,
293): Promise<string | null> {
294 try {
295 const content = (await readFile(join(gitDir, refPath), 'utf-8')).trim()
296 if (content.startsWith('ref:')) {
297 const target = content.slice('ref:'.length).trim()
298 if (target.startsWith(branchPrefix)) {
299 const name = target.slice(branchPrefix.length)
300 // Reject path traversal and argument injection from a tampered symref.
301 if (!isSafeRefName(name)) {
302 return null
303 }
304 return name
305 }
306 }
307 } catch {
308 // Not a loose ref
309 }
310 return null
311}
312
313// ---------------------------------------------------------------------------
314// GitFileWatcher — watches git files and caches derived values.

Callers 1

computeDefaultBranchFunction · 0.85

Calls 2

readFileFunction · 0.85
isSafeRefNameFunction · 0.85

Tested by

no test coverage detected