Skip to content

fix(cache): stop bundle-set thrash and symlink 500s in kernel cache - #38

Merged
brianvarskonst merged 2 commits into
mainfrom
fix/kernel-cache-reaudit
Nov 23, 2026
Merged

brianvarskonst merged 2 commits into
mainfrom
fix/kernel-cache-reaudit

Conversation

@brianvarskonst

Copy link
Copy Markdown
Member

Problem

From the Fable re-audit (2026-11-22) of sympress/kernel v1.1.17:

  • feat: improve kernel runtime services #1 (Medium, DoS): with more than 32 bundle sets (multisite), cleanup evicted the oldest meta_*.json by creation time. Every recompile evicted another live set, whose next request recompiled under LOCK_EX and evicted the next one. With 34 sets in rotation, every request recompiled.
  • Prepare kernel v0.1.0 release checklist #4 (Low, local DoS): a symlink named kernel in the implicit cache path (var/cache/<env>/kernel) skipped the trust check in CachePath::resolve(). ensureDirectory() then refused it after a full compile, so every request failed with HTTP 500.

Fix

  • Warm hits refresh the bundle-set metadata mtime at most hourly (skipped when the file is not writable, so a read-only prewarmed cache is left alone). Metadata beyond the 32-set cap is evicted only after 30 days without use.
  • CachePath::resolve() no longer exempts symlinks from isTrusted(). The implicit path falls back to the private cache. An explicit APP_CACHE_DIR whose kernel entry is a symlink now fails in resolve() with the existing diagnostic, instead of failing later in ensureDirectory().

The read-only prewarmed cache behaviour (re-audit #2) and the group-writable var/ parent rule (#3) are unchanged. Both are owner decisions.

Tests

  • BundleSetCacheTest::testMoreThanThirtyTwoLiveBundleSetsDoNotEvictEachOther: 34 live sets stay warm, and a warm hit refreshes stale metadata mtime. Fails on main (actual size 32 matches expected size 34).
  • The existing retired-set test now seeds metadata older than 30 days. The cap still holds at 32.
  • CacheRequestCompatibilityTest::testSymlinkedImplicitKernelDirectoryUsesPrivateFallback: fails on main (resolve returns the symlinked path). Passes now: the boot succeeds in the private fallback, nothing is written through the symlink, and an explicit APP_CACHE_DIR throws.
  • composer qa passes: CS clean, PHPStan max clean, 112 tests, 1 FPM-only skip. composer validate --strict is valid.

Release

Patch. This PR has no release commit. It ships in 1.1.18 with the follow-up PR, which carries chore(release): prepare kernel v1.1.18.

Cleanup dropped the oldest meta_*.json by creation time once more than
32 bundle sets existed. The mtime only changed on rebuild, so with 33+
live sets every compile evicted another live set, whose next request
recompiled under LOCK_EX and evicted the next one: each request
recompiled.

Warm hits now refresh the metadata mtime at most hourly (skipped for a
read-only prewarmed cache), and metadata beyond the cap is evicted only
after 30 days without use.
resolve() skipped the trust check when <cache>/<env>/kernel was a
symlink and returned it unchanged. ensureDirectory() then refused it
after a full compile, so every request failed with HTTP 500. A local
user able to write var/cache/<env>/ could cause that.

A symlink is now untrusted like any foreign directory: the implicit
path falls back to the private cache, and an explicit APP_CACHE_DIR
fails early in resolve() with the existing diagnostic.
@brianvarskonst
brianvarskonst merged commit d2da99d into main Nov 23, 2026
3 checks passed
@brianvarskonst
brianvarskonst deleted the fix/kernel-cache-reaudit branch November 23, 2026 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant