fix(media): retain inbound media with recursive cleanup TTL#38292
fix(media): retain inbound media with recursive cleanup TTL#38292vincentkoc merged 7 commits intomainfrom
Conversation
🔒 Aisle Security AnalysisWe found 1 potential security issue(s) in this PR:
1. 🟡 Potential DoS from unbounded recursive media cleanup on gateway maintenance timer
DescriptionA new hourly gateway maintenance interval runs a recursive filesystem cleanup over the entire media directory tree:
Vulnerable code (trigger): mediaCleanupInFlight = cleanOldMedia(params.mediaCleanupTtlMs, {
recursive: true,
pruneEmptyDirs: true,
});
...
const mediaCleanup = setInterval(() => {
void runMediaCleanup();
}, 60 * 60_000);Note: RecommendationMitigate worst-case traversal costs and attacker-amplification:
Example (time/entry budget): async function cleanOldMediaBudgeted(ttlMs: number, budget: { maxEntries: number; maxMs: number }) {
const start = Date.now();
let seen = 0;
// walk directories but stop when (seen >= maxEntries || Date.now() - start >= maxMs)
// persist cursor for next run
}
setInterval(() => void cleanOldMediaBudgeted(ttlMs, { maxEntries: 10_000, maxMs: 2_000 }), 60*60_000);This prevents a single run from monopolizing IO/CPU when the media tree is large. Analyzed PR: #38292 at commit Last updated on: 2026-03-07T03:39:00Z |
Greptile SummaryThis PR introduces a configurable inbound media retention TTL ( Key observations:
Confidence Score: 4/5
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a97cd56a2a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8d2a17c8fd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
* Config: add media retention TTL setting * Media: recurse persisted media cleanup * Gateway: add persisted media cleanup timer * Media: harden retention cleanup sweep * Media: make recursive retention cleanup opt-in * Media: retry writes after empty-dir cleanup race
…#38292) * Config: add media retention TTL setting * Media: recurse persisted media cleanup * Gateway: add persisted media cleanup timer * Media: harden retention cleanup sweep * Media: make recursive retention cleanup opt-in * Media: retry writes after empty-dir cleanup race
…#38292) * Config: add media retention TTL setting * Media: recurse persisted media cleanup * Gateway: add persisted media cleanup timer * Media: harden retention cleanup sweep * Media: make recursive retention cleanup opt-in * Media: retry writes after empty-dir cleanup race
…#38292) * Config: add media retention TTL setting * Media: recurse persisted media cleanup * Gateway: add persisted media cleanup timer * Media: harden retention cleanup sweep * Media: make recursive retention cleanup opt-in * Media: retry writes after empty-dir cleanup race
…#38292) * Config: add media retention TTL setting * Media: recurse persisted media cleanup * Gateway: add persisted media cleanup timer * Media: harden retention cleanup sweep * Media: make recursive retention cleanup opt-in * Media: retry writes after empty-dir cleanup race (cherry picked from commit ba9eaf2)
…#38292) * Config: add media retention TTL setting * Media: recurse persisted media cleanup * Gateway: add persisted media cleanup timer * Media: harden retention cleanup sweep * Media: make recursive retention cleanup opt-in * Media: retry writes after empty-dir cleanup race (cherry picked from commit ba9eaf2)
…#38292) * Config: add media retention TTL setting * Media: recurse persisted media cleanup * Gateway: add persisted media cleanup timer * Media: harden retention cleanup sweep * Media: make recursive retention cleanup opt-in * Media: retry writes after empty-dir cleanup race
…#38292) * Config: add media retention TTL setting * Media: recurse persisted media cleanup * Gateway: add persisted media cleanup timer * Media: harden retention cleanup sweep * Media: make recursive retention cleanup opt-in * Media: retry writes after empty-dir cleanup race
…#38292) * Config: add media retention TTL setting * Media: recurse persisted media cleanup * Gateway: add persisted media cleanup timer * Media: harden retention cleanup sweep * Media: make recursive retention cleanup opt-in * Media: retry writes after empty-dir cleanup race
Summary
media.ttlHoursas the persisted inbound media retention knob (default 24 hours)Testing
pnpm vitest run src/media/store.test.ts src/gateway/server-maintenance.test.tspnpm check(fails in pre-existingextensions/feishu/src/media.tswith unrelatedtimeouttype errors)Fixes #33078
Related #24519
Related #29211