fix(cli): sanitize test_name on GET, DELETE, and rebuild - #7034
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. |
|
I added the required CLA from this github account :) |
|
Follow-up: dedicated GET traversal test is in |
77710c4 to
a75c3a5
Compare
|
Rewrote the follow-up commit so
@surajksharma07 you already confirmed the helper locally; this is ready for review once CI is allowed to run. |
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_get_test_rejects_path_traversal,test_delete_test_rejects_path_traversal, andtest_rebuild_single_test_rejects_path_traversal. Existing create/get/delete/rebuild cases still pass.7 passed.
Testing plan
adk web).toxmatrix on this machine.