Repository navigation
fix(mrml-core): make local loader containment hold - #695
Merged
Merged
Conversation
Signed-off-by: Jeremie Drouet <jeremie.drouet@gmail.com>
Contributor
|
📈 This is how your metrics evolved 📉 |
Open
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.
Breaking — for 7.0. Removes
LocalIncludeLoader::default().The type documents that it "doesn't allow to go fetch a template that is in a parent directory of the root directory". That guarantee fails in both directions.
It reads anything. The struct derived
Default, givingroot == PathBuf::default() == "", andPath::starts_with("")is unconditionally true. So every canonicalized path passes:file:////etc/hostnamegets there too — the fourth slash survivestrim_start_matches("file:///"), andPathBuf::joinwith an absolute path discards the root.It reads nothing.
build_pathcanonicalizes the target but compares it against the root as supplied. Any root that is not already canonical matches nothing, so the loader rejects every input — including legitimate ones. The crate's own documented example is in this state: its root is relative, so it could never load a file. Same formrml --local-loader ../partials, and for any root reached through a symlinked ancestor.The containment check itself is right — with an absolute, canonical root I confirmed both traversal payloads are blocked. So this fixes the two ways its precondition gets violated, not the check:
Defaultderive is gone, so the empty-root state is no longer constructible...and symlinked ancestors all behave. If the root does not exist, that is now an error rather than a silent fallback to the raw path — a fallback would just reinstate the second bug...and symlinks resolved first.mrml-cli and mrml-python both build their root absolutely and call
new, so neither needed a change.Three regression tests, each checked failing before and passing after: a relative root loading a legitimate file, and both traversal payloads still refused under a relative root.
should_handle_dots_with_existing_fileused to pass for the wrong reason — its relative root rejected everything — and now passes because the path genuinely resolves to a sibling of the root.Tests 621 -> 624.