aft_delete: a temp-folder refusal says 'not safe or not owned by this session' without the file or the rule
Summary
aft_delete refuses a recursive delete of a folder under the temporary directory when the folder contains a SQLite file, or a file whose name contains .sqlite. The refusal is correct for that rule, but the message does not say why. It says:
temporary path '<folder>' is not safe or not owned by this session
The message names ownership, but ownership is not the cause in this case. The message does not name the file that failed the check, or the rule. An agent that reads it can conclude that its own scratch folder is "not owned" and remove the folder with a shell command instead. That loses the reason for the refusal.
Reproduction (v0.64.0, Linux)
- In a session, use a shell command to make three folders under
/tmp/<scratch>/:with-db/a/x.db: a SQLite database (sqlite3 x.db 'CREATE TABLE t(a);')named/a/notes.sqlite.txt: a plain text fileno-db/a/x.txt: a plain text file
- Call
aft_deletewithrecursive: trueon each folder, one call for each.
Result:
| Folder | Result |
|---|---|
with-db |
refused: temporary path '…/with-db' is not safe or not owned by this session |
named |
refused: same message |
no-db |
deleted |
The same shell command in the same session made all three folders. Thus, the refusal comes from the folder contents, not from who made the folder. The client also gets the refusal with error type unknown, not the unsafe_temp_path code that the module sets.
Cause
decide_tree_write (crates/aft/src/access_policy.rs) calls temp::safe_tree for a path under a temporary root. safe_tree (crates/aft/src/access_policy_temp.rs:174) calls safe_file on each entry. safe_file (access_policy_temp.rs:106-128) returns false for:
- a name that contains
.sqlite; - a file that
project_content::is_sqlite_or_metadatafinds, which includes a live SQLite database; - a regular file with more than one hard link.
The first entry that fails makes the full tree AccessDenial::UnsafeTemp. Then context.rs:12058 gives the general message for all of these causes and for the managed-scratch ownership cause. The anchors are on main at 80c00780d, the same as v0.64.0.
Request
- Put the entry that did not pass and its rule in the refusal, for example:
temporary path '<folder>' contains a SQLite database ('<entry>'); AFT does not delete SQLite files under the temporary directory. Do the same for a hard link and for the managed scratch of a different session. - Send the
unsafe_temp_pathcode to the client, so that a caller can tell this refusal from other errors. - In the
aft_deletedescription ordocs/tools.md, say that AFT refuses a temporary folder that contains SQLite files or hard links, and give the supported procedure to remove such a folder.
This request does not make the rule weaker. Test fixtures frequently keep SQLite files in the temporary directory, so this message shows frequently.
Thanks for the precise report. You're right on each point. safe_tree stops at the first entry that fails safe_file (a .sqlite name, a SQLite database, or a file with more than one hard link), but it returns only true or false, so the refusal can't say which entry or which rule. The same message also covers another session's scratch folder.
The rule stays: a hard-linked file can be a path outside the temporary directory, and a SQLite file there can be another program's live database. The next release names the entry and the rule in the refusal, keeps the unsafe_temp_path code all the way to the caller, and documents the rule in docs/tools.md.
Fixed in v0.65.0, released today: Temporary-folder refusals now name the file and the rule that blocked it. Thanks for the report. If you still see it after updating, reply here and we'll reopen.