Skip to content

fix: keep view templates inside the views directory - #729

Open
ambrose5773 wants to merge 2 commits into
masterfrom
fix/view-template-containment
Open

ambrose5773 wants to merge 2 commits into
masterfrom
fix/view-template-containment

Conversation

@ambrose5773

Copy link
Copy Markdown
Collaborator

Summary

View::getTemplate() now rejects absolute template paths and any path that resolves outside the configured views directory. render(), fetch(), and exists() all go through that resolver, so a template that cannot be shown to stay inside the views directory is not included.

Reported by Arekkusul.

Test plan

  • A normal view under the views path still renders
  • A path that leaves the views directory is rejected
  • An absolute path is rejected
  • Full PHPUnit suite: 496 tests, 964 assertions

Reject absolute template paths and any resolved path outside the configured views directory.
Normalize both separators before the containment check, and build the regression next to the views directory so it stays on the same drive.
@enlivenapp

Copy link
Copy Markdown

Howdy folks,

I saw this come across the Discord channel and thought I'd pop over and toss in my 25 cents (inflation, ya know).

This would change getTemplate() from returning full paths to throwing, and would flip a test that checks the old behavior. Anyone on ^3.0 might get blindsided if this is a patch (an assumption since it's fix: in the commit.)

exists() looks like it would throw, which would break if ($view->exists($f)).

A missing views folder and a disallowed path would give the same message, Template path is not allowed.

Pubvana (my cms) overrides flight\template\View::getTemplate() currently so this doesn't really break anything for me as written but if flight\template\View::render() or flight\template\View::fetch() change that'd blow me up since I do call them with absolute paths.

Anyway, figured I'd toss that stuff out for consideration. ☮️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants