[SHOPWARE] Fix world readable var/cache directory#4228
Open
null93 wants to merge 2 commits into
Open
Conversation
Added functionality to copy .env files during build process so that we have sane defaults for APP_ENV and APP_DEBUG
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.
Added functionality to copy .env files during build process so that we have sane defaults for
APP_ENVandAPP_DEBUG.The Problem
The reason this matters is because by default, sw-build-without-db:build runs
./bin/build-js.shvia runLocally, which has no.envfile (it's git ignored anddeploy:envonly writes one to the release path, much later):Symfony Runtime then falls back to its defaults at
GenericRuntime.php#L65-L72, soAPP_DEBUGends uptrueand a few lines down that triggersumask(0o000). Every call insidebuild-js.shthen writesvar/cachewith mode0777and files at0666.End result is a world-writable cache directory in every release which is not favorable:
The Proposed Solution
The fix is to seed the build checkout with the user's existing
.env*files fromcurrent_pathbefore the build runs. The build phase then boots Symfony with the realAPP_ENVandAPP_DEBUGthe user already configured, no hardcodedvalues needed. The change goes in sw-build-without-db:get-remote-config since it already pulls config from
current_path. This results in a correctly permissionedvar/cachedirectory:Backwards Compatibility
No backwards compatibility break IMO. The change only adds a download step, it doesn't alter existing task behavior.
On a first deploy where
current_pathdoesn't exist, the early return preserves the current behavior exactly. On subsequent deploys, it uses the user's realAPP_ENVandAPP_DEBUGinstead of falling back to dev/debug values.For anyone running with
APP_ENV=prod(the documented default in .env.example), this fixes the world readable permissions invar/cache.For anyone who deliberately runs with
APP_ENV=dev, the build now correctly reflects that choice and behaves the same as before.These values are obviously also able to be overwritten by actual environmental variables.