SnmpKit.SafeFile (snmpkit v2.0.1)
Guarded file access for user-supplied inputs: walk files, JSON/YAML profiles, MIB sources and compiled MIBs, whether they reach the simulator, the MIB compiler, the linter or the manager's MIB registry.
Two limits apply to every read:
Size - files larger than
:snmpkit, :max_input_file_bytes(default 64 MiB) are refused before they are read into memory.Location - when
:snmpkit, :input_rootsis set to a list of directories, the expanded path (symlinks resolved) must live under one of them; anything else is refused with{:error, :outside_allowed_roots}. The default isnil, i.e. no confinement, which keeps existing deployments that load profiles from arbitrary paths working.config :snmpkit,
max_input_file_bytes: 16 * 1024 * 1024, input_roots: ["/srv/snmp/profiles", "priv/walks"]
Summary
Functions
Validates a path against the configured roots and size limit and returns the resolved path to use.
The configured size limit in bytes.
The configured allowed roots, or nil when unconfined.
Reads a whole file after checking its location and size.
Opens a line stream over a file after checking its location and size.
Types
@type reason() :: :file_too_large | :outside_allowed_roots | File.posix()
Functions
Validates a path against the configured roots and size limit and returns the resolved path to use.
@spec configured_max_bytes() :: pos_integer()
The configured size limit in bytes.
@spec configured_roots() :: [Path.t()] | nil
The configured allowed roots, or nil when unconfined.
Reads a whole file after checking its location and size.
@spec stream( Path.t(), keyword() ) :: {:ok, Enumerable.t()} | {:error, reason()}
Opens a line stream over a file after checking its location and size.