fix(ecs-mcp-server): add path validation for user-supplied paths - #4480
Open
matthewgoodman13 wants to merge 1 commit into
Open
fix(ecs-mcp-server): add path validation for user-supplied paths#4480matthewgoodman13 wants to merge 1 commit into
matthewgoodman13 wants to merge 1 commit into
Conversation
Path validation only pattern-matched the raw string for "../" sequences, so an absolute path, a "~" prefix, or a symlink pointing at a user configuration directory was accepted. prepare_template_files also swallowed validation errors containing "does not exist", so a rejected path could still be created. Add a path_validation module, mirroring the one in eks-mcp-server, that expands "~", resolves paths with os.path.realpath, and rejects any path resolving inside or containing a sensitive directory (~/.aws, ~/.ssh, ~/.kube, ~/.gnupg, ~/.docker, /etc, /root, /var/lib). Relative paths stay supported, and the resolved absolute path is returned. Applied in prepare_template_files, build_and_push_image, and validate_cloudformation_template, replacing validate_file_path in utils/security.py.
matthewgoodman13
requested review from
a team,
nineonine and
tusharbabbar
as code owners
August 11, 2026 21:45
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4480 +/- ##
=======================================
Coverage 93.14% 93.15%
=======================================
Files 1038 1039 +1
Lines 87530 87568 +38
Branches 14121 14124 +3
=======================================
+ Hits 81529 81570 +41
+ Misses 3638 3637 -1
+ Partials 2363 2361 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
nineonine
approved these changes
Aug 11, 2026
matthewgoodman13
enabled auto-merge
August 11, 2026 22:39
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.
Fixes N/A
Summary
Changes
Add a shared
path_validationmodule toecs-mcp-server, mirroring the one ineks-mcp-server.validate_file_path()inutils/security.pyonly pattern-matched the raw string for../sequences, so an absolute path, a~prefix, or a symlink pointing at a userconfiguration directory was accepted.
prepare_template_files()also swallowed validationerrors whose message contained
does not exist, so a rejected path could still be created.The new
validate_path():~and resolves paths withos.path.realpath, collapsing..and followingsymlinks before any check
~/.aws,~/.ssh,~/.kube,~/.gnupg,~/.docker,/etc,/root,/var/lib), and paths containing one, since aparent such as
$HOMEwould pull it into a Docker build context$HOMEand the password databaseApplied in
prepare_template_files(beforeos.makedirsand the template writes),build_and_push_image(before the directory becomes thedocker buildx buildcontext), andvalidate_cloudformation_template.validate_file_pathis removed; every caller now uses thenew module.
Two differences from the EKS module: relative paths are accepted rather than rejected, and one
validate_path(path, must_exist=False)replaces two functions with identical bodies.User experience
Before,
app_pathwas used as written, so~/.aws— or a symlink resolving to it — becamethe template output directory and the Docker build context. Now such a path is rejected
before anything is written or built:
Project directories, absolute or relative, are unaffected.
Testing
787 tests pass, up from 722 on
main.path_validation.pyis at 100% line and branchcoverage, covering symlink,
~, relative, traversal, ancestor, prefix-collision andcase-insensitive-filesystem inputs.
ruff check,ruff format,pyright,banditanduv buildare clean.Checklist
If your change doesn't seem to apply, please leave them unchecked.
Is this a breaking change? (N)
Paths resolving inside or containing one of the listed directories are now rejected where they
were previously accepted. No other input is affected.
RFC issue number: N/A
Checklist:
Acknowledgment
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.