wenjin272 opened a new pull request, #1393:
URL: https://github.com/apache/flink-agents/pull/1393

   Linked issue: #1392
   Closes #1392
   
   ### Purpose of change
   
   BashTool now rejects bare commands absent from `allowed_commands`, even when 
`cwd` is an allowed script directory. Java and Python apply the same rules, and 
explicit script paths such as `./run_task-2.sh` continue to work.
   
   #### Runtime flow
   
   `BashTool.call` checks an explicit `cwd`, then the validator checks each 
command's executable before starting Bash. The executable must use only ASCII 
letters, digits, `_`, `-`, `.`, and `/`. It must then either match 
`allowed_commands` or contain `/` and resolve under `allowed_script_dirs`.
   
   #### Key decisions
   
   Bare names use Bash command lookup, so resolving them against `cwd` does not 
identify what Bash executes. Directory checks therefore apply only to explicit 
paths. Restricting executable spelling also avoids interpreting shell 
expansion, quotes, or escapes as literal filesystem paths. Argument handling 
retains its existing rules.
   
   ### Behavioral Semantics
   
   #### Interaction decisions
   
   The table assumes the existing `cwd` check passes.
   
   | Executable | In command list | Directory check | Result |
   |---|---|---|---|
   | Literal bare name | Yes | Not needed | Allowed |
   | Literal bare name | No | Not used, regardless of `cwd` | Rejected |
   | Literal path containing `/` | Yes | Not needed | Allowed |
   | Literal path containing `/` | No | Resolves under an allowed directory | 
Allowed |
   | Literal path containing `/` | No | Outside allowed directories | Rejected |
   | Contains unsupported characters or shell syntax | Either | Not used | 
Rejected |
   
   #### Behavioral contracts
   
   - Providing an allowed `cwd`, or placing a same-named file there, does not 
authorize an unlisted bare command. The same rule applies to the implicit 
process working directory and commands inside pipelines or chains.
   - Literal relative and absolute script paths can use directory 
authorization. Underscores, hyphens, and digits are supported; argument quoting 
and variable expansion remain supported.
   - Executable names containing variable expansion, wildcards, quotes, or 
escapes are rejected.
   - Existing checks continue to reject paths outside allowed directories, 
including parent traversal and symlinks resolving outside them.
   
   #### Failure behavior
   
   Invalid executable spelling and failed command/path checks return a 
descriptive `Command rejected` result before Bash starts. There is no fallback 
or retry. Existing cwd rejection, process exit errors, timeouts, and 
cancellation behavior are unchanged.
   
   ### Tests
   
   | Contract | Coverage |
   |---|---|
   | cwd and same-named files cannot authorize bare commands, including 
pipelines/chains | Java `cwdDoesNotAllowBareCommand`; Python 
`test_cwd_does_not_allow_bare_command` |
   | Implicit process cwd cannot authorize a bare command | Java 
`processCwdDoesNotAllowBareCommand`; Python 
`test_process_cwd_does_not_allow_bare_command` |
   | Literal paths with ordinary filename characters execute; arguments still 
expand | Java `cwdAllowsExplicitScriptPaths`; Python 
`test_cwd_allows_explicit_script_path` |
   | Shell syntax in executable names is rejected | Java 
`nonliteralExecutableRejected`; Python `test_reject_nonliteral_executable` |
   | Whitelisted commands still execute with cwd | Java 
`cwdAllowsWhitelistedCommand`; Python `test_cwd_enables_relative_script_path` |
   | Directory boundaries still apply | Java 
`cwdRejectsScriptOutsideAllowedDir`; Python 
`test_cwd_rejects_script_outside_allowed_dir` |
   
   Passed: 45 Java tests across `BashValidatorTest` and `BashToolTest`, 90 
Python BashTool/validator tests, Spotless, Ruff, and `git diff --check`. The 
Java run rebuilt the affected reactor modules from source. Python regression 
cases fail against the previous validation behavior.
   
   Not verified: full repository suites, live-model tool calls, or deployed 
Flink jobs. The focused tests exercise validation and actual local BashTool 
execution in both languages.
   
   <details>
   <summary>Verification commands</summary>
   
   ```bash
   mvn --batch-mode --no-transfer-progress -pl plan -am test \
     -Dtest=BashValidatorTest,BashToolTest \
     -Dsurefire.failIfNoSpecifiedTests=false
   
   # From python/, using the existing test environment:
   export PYTHONPATH=$(.venv/bin/python -c 'import sysconfig; 
print(sysconfig.get_paths()["purelib"])')
   .venv/bin/python -m pytest 
flink_agents/plan/tools/bash/tests/test_bash_tool.py -q
   .venv/bin/ruff check flink_agents/plan/tools/bash
   ```
   
   </details>
   
   ### API
   
   No API signatures or configuration fields change. Calls that relied on cwd 
to permit an unlisted bare executable must allow that command or use an 
explicit script path. Executable names containing spaces, non-ASCII characters, 
quoting, escapes, or expansion are now rejected, including names explicitly 
listed in `allowed_commands`. Existing argument syntax is unchanged. The Python 
interpreter test now explicitly allows `python3`.
   
   ### Documentation
   
   - [ ] `doc-needed`
   - [ ] `doc-not-needed`
   - [x] `doc-included`
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   - [x] Yes
   - [ ] No
   
   Generated-by: Codex CLI 0.153.4 (GPT-6)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to