Returns a securer::securer_tool() that reads files from specified
directories with format detection and size limits.
Usage
tool_read_file(
allowed_dirs,
max_file_size = "50MB",
max_rows = 10000,
max_calls = NULL
)
read_file_tool(...)Arguments
- allowed_dirs
Character vector of directories the tool can read from.
- max_file_size
Max file size. Default
"50MB". Accepts bytes or string like"10MB".- max_rows
Maximum rows for tabular formats. Default 10000.
- max_calls
Maximum invocations.
NULLmeans unlimited.- ...
Arguments passed to
tool_read_file().
Details
Supported formats: csv, json, txt, xlsx, parquet, rds. Format is detected
automatically from the file extension, or can be specified explicitly via
the format argument.
Security measures:
Path validation: All paths are resolved via
base::normalizePath()and checked againstallowed_dirs. Symlinks are resolved before the directory check, preventing symlink-based escapes.RDS sandboxing: RDS files are deserialized in a separate subprocess via callr, isolating the main process from malicious objects that execute code on load.
Size limits: Files exceeding
max_file_sizeare rejected before reading.Row limits: Tabular formats (csv, xlsx) are capped at
max_rowsrows.
See also
Other tool factories:
tool_calculator(),
tool_data_profile(),
tool_fetch_url(),
tool_plot(),
tool_query_sql(),
tool_r_help(),
tool_write_file()
Examples
# \donttest{
tool <- tool_read_file(
allowed_dirs = c("/data/reports", "/data/exports"),
max_file_size = "10MB",
max_rows = 5000
)
# }