Bound stdlib file filters and define a safe symlink/file-type policy (#648) - #669
Conversation
Add a file-reading safety policy for the contents, linecount, hash, and digest filters. StdlibConfig gains a file_max_read_bytes budget (default 8 MiB) mirroring the fetch response limit, threaded into the path filters through a FileConfig carrier. The reading filters now open the final path component without following symlinks (O_NOFOLLOW on Unix, a pre-open symlink check on Windows), verify the opened object is a regular file through the opened handle, stream reads against a running byte total, and count lines incrementally instead of materialising the whole file. Per-call max_bytes kwargs may narrow the operator ceiling and a follow_symlinks kwarg opts back into link following. Rejections and over-budget reads surface localized InvalidOperation diagnostics naming the path and limit without file contents. New localization keys ship in every catalogue; en-US carries the source wording.
Thread an unbounded FileReadLimits through the hash utility unit tests and widen into_components destructuring in the configuration tests so the lib test build compiles against the new policy signatures.
Replace the English scaffolding in the Arabic, Persian, and Hebrew catalogues with translated copy so the paragraph-direction test passes: RTL locales must not render messages that begin with a Latin letter.
Add integration tests pinning the new policy: a within-budget read returns unchanged contents, line counts, and digests; a file exactly at the limit renders; one byte over fails with the limit interpolated and no file content; per-call max_bytes narrows and clamps; symlinks are rejected by default with a follow_symlinks opt-in; and a FIFO fixture is refused. Unix opens carry O_NONBLOCK so a FIFO final component cannot wedge a render worker inside open, and the flag is cleared once the handle is confirmed to be a regular file. Policy tests live in their own module to respect the 400-line file limit.
Add a users-guide section covering the 8 MiB default budget, the with_file_max_read_bytes operator seam, symlink and special-file rejection, and the follow_symlinks/max_bytes per-call options, plus a safety-boundary bullet. Extend the Jinja guide's file-filter section with the same policy and cross-link it, and record the finding and remediation in the security audit document.
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueWarning Your free Security trial is over. An organization admin can upgrade to Advanced for continuous pull request security review or dismiss this notice. Comment |
Reviewer's GuideThe PR adds a configurable, streaming byte budget and safe final-entry policy to the Sequence diagram for bounded safe file filter readssequenceDiagram
participant Template
participant Filter as PathFilter
participant FS as fs_utils
participant File as FileHandle
Template->>Filter: contents(raw, encoding, kwargs)
Filter->>Filter: path_call_limits(kwargs, configured_max_read_bytes)
Filter->>FS: read_utf8(path, limits)
FS->>FS: open_file_checked(path, limits)
FS->>File: open_with(path, O_NOFOLLOW)
File-->>FS: opened handle
FS->>File: metadata()
File-->>FS: regular-file metadata
loop bounded chunks
FS->>File: read(buffer)
File-->>FS: chunk
FS->>FS: read_bounded_chunk(total, max_bytes)
end
FS-->>Filter: contents or localized limit/type error
Filter-->>Template: rendered value or diagnostic
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
@coderabbitai Please investigate the cause of the following issue using codegraph exploration and research, identify a fix and provide an AI coding agent prompt for the fix: https://github.com/leynos/netsuke/actions/runs/33702312492/job/100484346530?pr=669 |
|
Oops, something went wrong! Please try again later. 🐰 💔 |
Summary
Bounds the stdlib file-reading filters (
contents,linecount,hash, anddigest) and defines one coherent symlink/file-type policy for them.StdlibConfiggainswith_file_max_read_bytes(default 8 MiB, mirroringfetch_max_response_bytes), threaded into the path filters through aFileConfigcarrier.O_NOFOLLOWon Unix, a pre-open symlink check on Windows), open non-blocking so a FIFO or device cannot wedge a worker, verify the opened handle is a regular file, and stream against a running byte total.linecountcounts line terminators incrementally instead of materialising the file in aString.hashanddigeststop digesting once the budget is exceeded; within-budget results are unchanged.max_bytesnarrows the operator ceiling (never raises it) and a namedfollow_symlinks=trueopt-in permits reading through a final symlink.InvalidOperationdiagnostics naming the path and the applicable limit, never file contents; new keys ship in all 35 catalogues with RTL-catalogue translations.Closes #648
References
Summary by Sourcery
Bound standard-library file reads and enforce a consistent safe policy for symlinks and file types.
New Features:
contents,linecount,hash, anddigestfilters, with per-call narrowing and explicit symlink-following opt-in.Bug Fixes:
Enhancements:
Build:
Documentation:
Tests: