wenjin272 opened a new issue, #1392:
URL: https://github.com/apache/flink-agents/issues/1392
### Search before asking
- [x] I searched the existing issues and found no matching issue.
### Description
BashTool can accept a bare command that is absent from `allowed_commands`
when `cwd` is inside an allowed script directory. This affects both Java and
Python.
The validator treats the command name as a path relative to `cwd`, while
Bash uses command lookup for a bare name. For example, `pwd` passes validation
with an empty command list if an allowed directory is supplied as `cwd`, even
when that directory has no file named `pwd`.
Bare command names should require an entry in `allowed_commands`. Only
explicit literal paths such as `./run.sh` should use `allowed_script_dirs`.
Executable names should also reject shell expansion so that validation and
execution refer to the same name. Argument expansion should remain supported.
### How to reproduce
With the Python dependencies installed:
```python
from pathlib import Path
from tempfile import TemporaryDirectory
from flink_agents.plan.tools.bash.bash_tool import BashTool
with TemporaryDirectory() as directory:
cwd = str(Path(directory).resolve())
print(BashTool().call(
command="pwd",
cwd=cwd,
allowed_commands=[],
allowed_script_dirs=[cwd],
))
```
Expected: `Command rejected`, because `pwd` is not allowed.
Actual: the command executes and returns the working directory. The Java
implementation has the same behavior.
### Version and environment
Main at `5b0b5531657aacb050201056ebc717fc8e683f09`. Verified locally on
macOS arm64, JDK 11 and Python 3.11.
### Are you willing to submit a PR?
- [x] I'm willing to submit a PR.
--
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]