Contain @import file loads within base_dir (arbitrary local file read) - #192
Open
Guilhermemury wants to merge 1 commit into
Open
Guilhermemury wants to merge 1 commit into
Guilhermemury wants to merge 1 commit into
Conversation
The base_dir arm of add_block!'s @import handler routed the attacker-controlled import path straight into load_file! -> File.expand_path + File.read with no containment. CSS containing `@import "/etc/passwd"` or `@import "../../secret"` could therefore read arbitrary local files: the content is merged into the ruleset and, via Premailer's local-file input (base_dir set, base_uri nil), inlined into the produced HTML. This is the base_dir sibling of the file://-via-base_uri hole closed in GHSA-9pmc-p236-855h / CVE-2026-53727, which only gated load_uri! and left this arm (and load_file!) untouched. Fix: mark @import-sourced load_file! calls (from_import) and contain the resolved path within the import root -- the top-level base_dir, threaded through nested imports. Absolute paths and `..` traversal that escape the root are refused (RemoteFileError when io_exceptions is on, otherwise a silent no-op). `..` that stays inside the root still works, and direct load_file! callers (the trusted local-file API) are unaffected. Adds test/test_css_parser_import_lfi.rb covering the refusals, the in-root cases, and the direct-caller API. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the
base_dirarm of the@importhandler — the local-file-read siblingof the SSRF/
file://issue fixed in GHSA-9pmc-p236-855h / CVE-2026-53727.Tracked privately as GHSA-w3mx-4vv9-hjpg (fix #1 from that advisory).
Problem
When the caller sets
:base_dirwithout:base_uri(the default for Premailerlocal-file input),
add_block!'s@importhandler passed the import pathstraight into
load_file!→File.expand_path+File.readwith nocontainment. CSS containing
@import "/etc/passwd";(absolute) or@import "../../secret";(traversal) could read an arbitrary local file, mergeit into the ruleset, and — via Premailer — inline it into the output HTML. The
GHSA-9pmc-p236-855h fix only gated
load_uri!/ thebase_uriarm; this armand
load_file!were untouched.Fix
@importhandler marks these loads (from_import: true) and threads animport_root(the top-levelbase_dir) through nested imports.load_file!containsfrom_importloads withinimport_root: absolute pathsand
..that escape the root are refused (RemoteFileErrorwhenio_exceptionsis on, otherwise a silent no-op)...imports that stay inside the root still work (e.g.subdir/import2.css→../simple.css, as in the existing fixtures).load_file!callers — the explicit, trusted local-file API — areunaffected.
Tests
New
test/test_css_parser_import_lfi.rb(7 tests): absolute + traversalrefusals,
io_exceptions:falseno-op, in-root imports still load,..-within-root still loads, direct
load_file!unaffected. Full suite green(
246 runs, 758 assertions, 0 failures); RuboCop clean.