fix(cli): sanitize test_name on GET, DELETE, and rebuild - #7034
Open
Oskii wants to merge 1 commit into
Open
Conversation
create_test already used basename so a test name cannot leave tests/. The other three endpoints joined the name as given. Share one helper. Fixes google#7033
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Author
|
I added the required CLA from this github account :) |
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 #7033
What
adk webcan create, read, delete, and rebuild agent test JSON files under<agent>/tests/.create_testalready ranos.path.basenameontest_nameso a name cannot leave that folder. GET, DELETE, and rebuild did not.On
main@b018062, this DELETE removes a file next totests/, not inside it:The path param decodes to
../outside.json.os.path.join(tests_dir, test_name)follows it. GET reads the same way.POST .../tests/rebuild?test_name=../outside.jsonpasses that path intorebuild_tests.This is the local unauthenticated dev server. Default bind is loopback. It still matters if someone uses
--host 0.0.0.0, or if anything else can hit those routes.After the fix, those names are stripped to
outside.jsonand resolved only undertests/. A missing file is 404. The file outsidetests/is left alone.Why
I was reading the test-file routes next to
test_create_test. The create handler has an explicit comment about directory traversal. I tried the same name on DELETE with a percent-encoded../and the file outsidetests/was gone.How
One helper,
_sanitize_test_filename, used by create, get, delete, and rebuild. Samebasenameplus the existing.jsonsuffix rule. No new public API.Testing
Added
test_delete_test_rejects_path_traversalandtest_rebuild_single_test_rejects_path_traversal. Existing create/get/delete/rebuild cases still pass.6 passed.
Testing plan
adk web).toxmatrix on this machine.