Repository navigation
Confine envfile S3 key paths to task resource directory - #5011
Merged
Merged
Conversation
singholt
reviewed
Jun 18, 2026
singholt
previously approved these changes
Jun 22, 2026
harishxr
force-pushed
the
dev
branch
2 times, most recently
from
June 22, 2026 17:57
8e6ec87 to
48e5005
Compare
singholt
previously approved these changes
Jun 22, 2026
mye956
reviewed
Jun 22, 2026
When a task uses environmentFiles, the agent joins the S3 bucket and object key from the task definition onto the per-task envfile resource directory and then creates directories, writes, and reads files at that path. The key was used without input validation, so a key containing relative path segments could resolve to a location outside the resource directory. Validate the bucket/key with filepath.IsLocal before joining it onto the resource directory, in both the download and read paths and before MkdirAll. Keys that would resolve outside the resource directory are rejected and fail the envfile resource transition; legitimate nested keys are unaffected.
mye956
approved these changes
Jun 22, 2026
singholt
approved these changes
Jun 22, 2026
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.
Summary
Adds input validation for the S3 object key used when downloading environment files. When a task uses
environmentFiles, the agent joins the S3 bucket and object key from the task definition onto the task's per-task envfile resource directory, and then creates directories, writes, and reads files at that path. The key was used without validation, so a key containing relative path segments could resolve to a location outside the intended resource directory. This change validates the bucket/key before it is used, so it must resolve to a location inside the resource directory.Implementation details
verifyEnvfileKeyLocal, which usesfilepath.IsLocalto confirm the joinedbucket/keystays within the resource directory after.,.., and separators are resolved.getEnvfileDownloadPath, used by both the download and read paths, which validates the bucket/key before joining it ontoresourceDir.MkdirAllincreateEnvfileDirectory.resourceDirare rejected and fail the envfile resource transition; legitimate nested keys are unaffected.Testing
TestVerifyEnvfileKeyLocal— exercises the helper directly: simple, nested, and parent-reference-resolving-back-inside keys are allowed; keys that resolve outside the resource directory (including backslash-padded keys) are rejected.TestCreateRejectsNonLocalKey— a single envfile whose key resolves outsideresourceDirfails the resource transition before any temp file is created or any S3 download is attempted.TestCreateRejectsNonLocalEnvfileInMultiFileSet— with one normal and one non-local key downloading concurrently, the non-local key is rejected and never renamed into place, while every rename that occurs stays withinresourceDir.TestReadEnvVarsRejectsNonLocalKey— the read path is validated as well.TestCreateWithEnvVarFile,TestReadEnvVarsFromEnvfiles, etc.) continue to pass, confirming legitimate nested keys are unaffected.go test -tags unit ./agent/taskresource/envFiles/passes.make release-agent), loaded it on a fresh Amazon Linux 2023 instance, and ran ECS tasks (EC2 launch type) with environment files staged in S3:New tests cover the changes: yes
Description for the changelog
Bugfix - Validate environment file S3 keys so they stay within the task resource directory
Additional Information
Does this PR include breaking model changes? If so, Have you added transformation functions? no
Does this PR include the addition of new environment variables in the README? no