You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "wenjin272 (via GitHub)" <gi...@apache.org> on 2026/08/12 10:57:09 UTC
[I] [Bug][security][bash] Constrain redirect targets and execution-changing environment assignments [flink-agents]
wenjin272 opened a new issue, #1004:
URL: https://github.com/apache/flink-agents/issues/1004
### Description
The built-in Bash tool currently validates the executable name of each command against `allowed_commands` or `allowed_script_dirs`, but it does not constrain file redirect destinations. The accepted AST also allows environment-variable assignments that can change how an otherwise allowed command executes.
As a result, a narrow command allowlist does not currently imply a narrow filesystem or execution boundary. For example, a command using an allowed executable can redirect output to any path writable by the TaskManager process. Materialized skill directories are also automatically added to `allowed_script_dirs`, so writable files in those directories deserve additional protection.
Flink Agents is currently in the experimental 0.x release series and does not provide production-readiness guarantees. This issue tracks the hardening needed before production readiness / 1.0.
### Expected behavior
- Define and document the Bash allowlist's security contract explicitly.
- Reject file redirects by default, or validate their destinations against a separate, explicitly configured set of writable directories. Executable directories should not implicitly become writable directories.
- Reject or safely constrain environment assignments that alter command resolution or execution behavior, such as `PATH`, `BASH_ENV`, and dynamic-loader variables.
- Make materialized skill content immutable or read-only where practical, as defense in depth.
- Keep validation behavior aligned across Java and Python.
- Add focused tests covering redirects inside and outside permitted write locations, behavior-changing environment assignments, and normal pipes / descriptor redirects that remain supported.
- Update the skills and Bash tool documentation so that the allowlist's guarantees and limitations are clear.
### How to reproduce
Without executing a command, call the Java or Python Bash validator with:
```text
command: echo hi > /tmp/out
allowed_commands: [echo]
allowed_script_dirs: []
```
The validator currently accepts the command even though the redirect destination is outside every allowed directory. Existing Java and Python unit tests also pin this behavior.
### Version and environment
Confirmed in Apache Flink Agents 0.3.1 and on `main` as of 2026-08-12, in both the Java and Python implementations.
--
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: issues-unsubscribe@flink.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Bug][security][bash] Constrain redirect targets and execution-changing environment assignments [flink-agents]
Posted by "wenjin272 (via GitHub)" <gi...@apache.org>.
wenjin272 commented on issue #1004:
URL: https://github.com/apache/flink-agents/issues/1004#issuecomment-5521655373
Thanks for the detailed analysis @Ashfaqbs. This has already been addressed by #1079, which is now on `main`. Both Java and Python reject file redirects except for file-descriptor duplication/closure, and also reject execution-changing environment assignments such as `PATH`, `BASH_ENV`, `LD_*`, and `DYLD_*`. The two reported reproducers therefore no longer pass validation.
I simply had not closed this issue yet. The read-only materialized skill directory item can be tracked separately as defense in depth. Closing this as fixed.
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Bug][security][bash] Constrain redirect targets and execution-changing environment assignments [flink-agents]
Posted by "wenjin272 (via GitHub)" <gi...@apache.org>.
wenjin272 closed issue #1004: [Bug][security][bash] Constrain redirect targets and execution-changing environment assignments
URL: https://github.com/apache/flink-agents/issues/1004
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Bug][security][bash] Constrain redirect targets and execution-changing environment assignments [flink-agents]
Posted by "Ashfaqbs (via GitHub)" <gi...@apache.org>.
Ashfaqbs commented on issue #1004:
URL: https://github.com/apache/flink-agents/issues/1004#issuecomment-5518972068
Confirmed still current on `main` — reproduced exactly: `BashValidator.validate("echo hi > /tmp/x", List.of("echo"), List.of(), null)` returns `Optional.empty()` (allowed) even with an empty `allowedScriptDirs`, because `walk()`'s recursion visits `file_redirect` nodes (they're in `ALLOWED_NAMED`, so the construct itself passes) but only `command` nodes ever get their content validated — the redirect target text is never inspected. `BashValidatorTest.redirectAllowed()` and the Python equivalent both currently assert this as the expected/passing behavior, so they'd need updating alongside any fix. Same gap for `variable_assignment` — its value is likewise never validated, so `PATH=/tmp/evil echo hi` (with `echo` allowed) passes unchanged today.
On the redirect half of this issue, I'd lean toward the second option over "reject by default": a distinct `allowed_write_dirs` parameter (separate from `allowed_script_dirs`, mirroring the "executable directories should not implicitly become writable directories" concern already in the issue), defaulting to empty — so out of the box every redirect is rejected (since nothing is in the empty default), and an operator opts a directory into writability explicitly rather than it happening implicitly via the execute-allowlist. Concretely:
- Add `allowedWriteDirs`/`allowed_write_dirs` alongside `allowed_commands`/`allowed_script_dirs` in `BashTool`'s parameter surface (Java + Python), threaded into `BashValidator.validate`/`validate_command`.
- In `walk`, when visiting a `file_redirect` node, extract its target (the `word`/`string` child after the redirect operator) and validate it the same way `validateCommand` validates the executable — against `allowedWriteDirs` via the existing `isUnderAllowedDirs` helper, rather than `allowedScriptDirs`.
- Update `redirectAllowed()` (and the Python equivalent) to pass an explicit `allowedWriteDirs` containing `/tmp`, and add a new test asserting a redirect to a path outside it is now rejected — matching this issue's own repro.
- Materialized skill directories would need to *not* be auto-added to this new list (only to `allowed_script_dirs`, as today), so skill-provided scripts stay executable-only, not writable, by default.
The variable-assignment / environment-hardening half (`PATH`, `BASH_ENV`, dynamic-loader vars) and the skill-directory-immutability item feel like they warrant their own follow-up rather than folding into the same PR — different validation surface (assignment *values*, not redirect targets) and a different enforcement mechanism (denylist of variable names vs. an allowlist of directories). Happy to open a PR for the redirect half along these lines if that direction sounds right, and split a second issue for the environment-assignment half — or take a different shape if you'd rather keep it together or go with "reject all redirects, no config" instead.
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org