fix: judge the working directory and the arguments a tool declares
The guard resolved relative paths against the session directory the conversation started in, but the file tools resolve them against the session's *current* working directory — which `working_directory` can change with no guard opinion. In a `deny` facet, `cd /etc` followed by `read` of a relative path read from /etc. The same mismatch made a shadowed tool invisible: this deployment installs `dsh-better-edit`, which replaces `read` (argument `path`) and `edit` (argument `file`), so a table written against the built-in `file_path` left the busiest read tool unguarded — an outside file could be read with `deny` in force. Now: - `working_directory` is in the path table, so a `cd` outside the facet is refused (or put to the user, by mode) like any other out-of-facet path; - a relative argument is judged against the directory the tool will actually use, read lazily from `ctx.workingDirectory`, and the implicit-search rule judges that same directory; - path parameter names come from the tool's own declaration when the registry can supply one, so a shadowed tool is judged by the arguments it really takes; - a delegated session started with a `subagent` `cwd` outside the parent's facet is clamped to the parent root instead of being scoped to the outside directory. `undo_last_edit` (write-like) and the delegation tools join the table. Verified against a profile with dsh-better-edit: in `deny` mode the outside `read`, `edit`, `cd /etc` and `subagent cwd /etc` are all refused, while an inside read still works — and the relative-read bypass from the same profile now stays inside.
This commit is contained in:
1 parent
c48e9cabd9
commit
40574505f2
7 files changed
+309
-27
No files matched your search
+8
-2
@@ -165,7 +165,12 @@ export function createFacetPolicy(config) {
|
||||
*
|
||||
* Inheritance is the same kind of test, and it is skipped when the user made a
|
||||
* declaration of their own: that is their decision about *this* session, and
|
||||
* the point of inheriting is to answer the case where they made none.
|
||||
* the point of inheriting is to answer the case where they made none. A child
|
||||
* whose own directory is *outside* the inherited root is clamped to the
|
||||
* inherited root rather than trusted with its own: a delegated session may be
|
||||
* started anywhere, and "somewhere else" is the one direction the invariant
|
||||
* forbids. A child started inside the inherited root keeps its own, narrower
|
||||
* directory.
|
||||
*
|
||||
* @param {string|undefined} sessionId - the session.
|
||||
* @param {string} sessionCwd - its resolved working directory.
|
||||
@@ -176,7 +181,8 @@ export function createFacetPolicy(config) {
|
||||
const declared = declaredScope(sessionId)?.focus
|
||||
const stated = typeof declared === 'string' && declared.trim() !== ''
|
||||
const own = stated ? resolve(sessionCwd, declared) : sessionCwd
|
||||
const base = !stated && inherited !== undefined && within(inherited, own) ? inherited : own
|
||||
const base =
|
||||
!stated && inherited !== undefined ? (within(own, inherited) ? own : inherited) : own
|
||||
const agentFocus = sessionId === undefined ? undefined : narrowed.get(sessionId)
|
||||
if (agentFocus !== undefined && within(agentFocus, base)) return agentFocus
|
||||
return base
|
||||
|
||||
Reference in new issue
Block a user