Repository navigation
fix: enrich session_end lifecycle hooks - #59715
Conversation
🔒 Aisle Security AnalysisWe found 2 potential security issue(s) in this PR:
1. 🟠 Symlink traversal allows arbitrary file rename during session transcript archiving
Description
This is dangerous because:
Vulnerable code path:
Vulnerable code: function canonicalizePathForComparison(filePath: string): string {
const resolved = path.resolve(filePath);
try {
return fs.realpathSync(resolved);
} catch {
return resolved;
}
}
...
const candidatePath = canonicalizePathForComparison(candidate);
...
archivedPath: archiveFileOnDisk(candidatePath, opts.reason),
...
fs.renameSync(filePath, archived);Impact: arbitrary file move/rename (and effectively deletion from original location) on the host filesystem when a reset/delete triggers transcript archiving. RecommendationAvoid resolving symlinks for the path you later mutate, and explicitly reject symlinks before archiving. Suggested approach:
Example hardening: function resolveForComparison(p: string): string {
return path.resolve(p);
}
function assertSafeRegularFile(p: string): void {
const st = fs.lstatSync(p);
if (st.isSymbolicLink()) throw new Error("refusing to archive symlink");
if (!st.isFile()) throw new Error("refusing to archive non-file");
}
// In archive loop:
const opPath = path.resolve(candidate); // path used for rename
const comparePath = resolveForComparison(candidate);
if (storeDir) {
const rel = path.relative(storeDir, comparePath);
if (!rel || rel.startsWith("..") || path.isAbsolute(rel)) continue;
}
if (!fs.existsSync(opPath)) continue;
assertSafeRegularFile(opPath);
archivedPath: archiveFileOnDisk(opPath, opts.reason);This prevents symlink targets outside the sessions directory from being renamed. 2. 🟡 Filesystem path disclosure to plugins via session_end hook payload (sessionFile)
DescriptionThe Why this matters:
Vulnerable flow:
RecommendationAvoid exposing raw filesystem paths across plugin boundaries. Options (pick based on product needs):
Example (minimize to basename + relative path): // When building hook payload:
const safeSessionFile = transcript.sessionFile
? path.basename(transcript.sessionFile)
: undefined;
const payload = buildSessionEndHookPayload({
...,
sessionFile: safeSessionFile,
});Also consider adding a plugin capability/permission like Analyzed PR: #59715 at commit Last updated on: 2026-04-02T14:27:21Z |
Greptile SummaryThis PR enriches Confidence Score: 5/5
Reviews (1): Last reviewed commit: "Hooks: enrich session_end lifecycle hook" | Re-trigger Greptile |
791192b to
052c773
Compare
052c773 to
b3ef62b
Compare
|
Merged via squash.
Thanks @jalehman! |
Merged via squash. Prepared head SHA: b3ef62b Co-authored-by: jalehman <[email protected]> Co-authored-by: jalehman <[email protected]> Reviewed-by: @jalehman
Merged via squash. Prepared head SHA: b3ef62b Co-authored-by: jalehman <[email protected]> Co-authored-by: jalehman <[email protected]> Reviewed-by: @jalehman
Merged via squash. Prepared head SHA: b3ef62b Co-authored-by: jalehman <[email protected]> Co-authored-by: jalehman <[email protected]> Reviewed-by: @jalehman
Merged via squash. Prepared head SHA: b3ef62b Co-authored-by: jalehman <[email protected]> Co-authored-by: jalehman <[email protected]> Reviewed-by: @jalehman
Merged via squash. Prepared head SHA: b3ef62b Co-authored-by: jalehman <[email protected]> Co-authored-by: jalehman <[email protected]> Reviewed-by: @jalehman
Merged via squash. Prepared head SHA: b3ef62b Co-authored-by: jalehman <[email protected]> Co-authored-by: jalehman <[email protected]> Reviewed-by: @jalehman
Merged via squash. Prepared head SHA: b3ef62b Co-authored-by: jalehman <[email protected]> Co-authored-by: jalehman <[email protected]> Reviewed-by: @jalehman
Merged via squash. Prepared head SHA: b3ef62b Co-authored-by: jalehman <[email protected]> Co-authored-by: jalehman <[email protected]> Reviewed-by: @jalehman
Merged via squash. Prepared head SHA: b3ef62b Co-authored-by: jalehman <[email protected]> Co-authored-by: jalehman <[email protected]> Reviewed-by: @jalehman
What
Make
session_endthe generic old-session lifecycle hook by adding optional reason, transcript, archive, and replacement metadata, then emit it consistently for reset, rollover, delete, and compaction-driven session replacement flows.Why
Transcript-aware plugins need one stable hook whenever an old session is ending or being replaced. This keeps
before_resetcommand-specific while giving plugins a post-archive path they can safely read.Changes
session_endevent metadata/newand/resetTesting
node scripts/test-parallel.mjs src/plugins/wired-hooks-session.test.ts src/auto-reply/reply/session-hooks-context.test.ts src/auto-reply/reply/session-updates.lifecycle.test.tsnode scripts/test-parallel.mjs src/gateway/server.sessions.gateway-server-sessions-a.test.ts -- -t "sessions.reset emits enriched session_end and session_start hooks|sessions.delete emits session_end with deleted reason and no replacement"./node_modules/.bin/oxlint src/plugins/types.ts src/auto-reply/reply/session-hooks.ts src/gateway/session-transcript-files.fs.ts src/gateway/session-archive.fs.ts src/gateway/session-archive.runtime.ts src/auto-reply/reply/session.ts src/gateway/session-reset-service.ts src/gateway/server-methods/sessions.ts src/auto-reply/reply/session-updates.ts src/auto-reply/reply/session-run-accounting.ts src/auto-reply/reply/agent-runner.ts src/auto-reply/reply/followup-runner.ts src/auto-reply/reply/agent-runner-memory.ts src/auto-reply/reply/commands-compact.ts src/plugins/wired-hooks-session.test.ts src/auto-reply/reply/session-hooks-context.test.ts src/auto-reply/reply/session-updates.lifecycle.test.ts src/gateway/server.sessions.gateway-server-sessions-a.test.ts./node_modules/.bin/oxfmt --check src/plugins/types.ts src/auto-reply/reply/session-hooks.ts src/gateway/session-transcript-files.fs.ts src/gateway/session-archive.fs.ts src/gateway/session-archive.runtime.ts src/auto-reply/reply/session.ts src/gateway/session-reset-service.ts src/gateway/server-methods/sessions.ts src/auto-reply/reply/session-updates.ts src/auto-reply/reply/session-run-accounting.ts src/auto-reply/reply/agent-runner.ts src/auto-reply/reply/followup-runner.ts src/auto-reply/reply/agent-runner-memory.ts src/auto-reply/reply/commands-compact.ts src/plugins/wired-hooks-session.test.ts src/auto-reply/reply/session-hooks-context.test.ts src/auto-reply/reply/session-updates.lifecycle.test.ts src/gateway/server.sessions.gateway-server-sessions-a.test.tspnpm checkis currently blocked by unrelated existingpnpm tsgofailures inextensions/msteams/src/sdk.ts,src/agents/skills.test-helpers.ts, andsrc/agents/skills/local-loader.ts