Repository navigation
fix(cache): verify owner and parent directories before trusting cache - #33
Merged
Merged
Conversation
Only the leaf kernel cache directory was checked (no symlink, not group/world-writable). A local user with write access to var/cache or var/cache/<env> could plant their own kernel/ directory with meta.json and container_*.php, which were then require_once'd as the PHP-FPM user. CachePath::isTrusted() is now the single trust check for the container cache and the discovery manifest: the directory must be owned by the process user, and every parent up to the project (up to / for caches outside it) must not be group/world-writable unless sticky. Compiled containers and discovery manifests must also be owned by the process user. An untrusted implicit cache moves to the private fallback, an explicit APP_CACHE_DIR fails with a diagnostic, and the writer refuses to compile into an untrusted directory.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Audit finding M1 (kernel v1.1.14). Cache trust was only checked on the leaf directory (
is_link,perms & 0022) inCachePath::resolve(),ContainerCacheManager::tryUseRuntimeContainer()andKernelPackageManifestCache::read(). Owner and parent directories were never checked. A local user with write access tovar/cacheorvar/cache/<env>(for example afterchmod -R g+w var) could rename the realkernel/and plant a 0755kernel/withmeta.jsonandcontainer_*.php. The kernel would thenrequire_oncethat PHP as the PHP-FPM user.discovery-packages.jsonhas the same pattern and controls bundle paths.Fix
CachePath::isTrusted($directory, $project), the single trust check for all three call sites. The directory must be a real directory owned by the process user (posix_geteuid(), or the existing memoized tmpfile probe without ext-posix) and not group/world-writable. Every parent up to the project (up to/for caches outside the project, such asAPP_CACHE_DIRor the/tmpfallback) must not be group/world-writable unless it has the sticky bit. The project directory itself is the boundary because the deployed code already depends on it. A missing directory is judged by its existing parents.CachePath::ownedByProcess(): compiledcontainer_*.phpanddiscovery-packages.jsonmust be owned by the process user before they are included or read.resolve()sends an untrusted implicit cache to the private fallback. The fallback also skipsvar/cache-private-<uid>when its parents are untrusted.APP_CACHE_DIRthrows with a diagnostic.tryUseRuntimeContainer()returns false.createRuntimeContainer()refuses to compile into an untrusted directory.ContainerResourceFingerprinter::projectDir()getter, soContainerCacheManagerkeeps its constructor signature.privateFallback()used for the temp dir is reused, not copied.docs/dependency-injection.mdnow describes the enforced rule.Tests
CacheRequestCompatibilityTest::testCacheBelowParentWritableByOthersIsNotTrusted: builds a real cache, then setsvar/cacheto01777(still trusted) and then to0777. With0777,tryUseRuntimeContainer()must return false, the discovery manifest must be rejected,resolve()must move to the private fallback, an explicitAPP_CACHE_DIRmust throw, andcreateRuntimeContainer()must refuse. Before the fix it fails withFailed asserting that true is false(the cache was trusted); after the fix it passes.composer validate --strictvalid.Release
Patch release 1.1.15. The CHANGELOG entry is in a separate
chore(release)commit. No unreleased commits since v1.1.14.