Skip to content

Changes default render behavior from file to template. #16888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 22, 2014

Conversation

jejacks0n
Copy link
Contributor

Currently the default behavior of render "foo/bar" is to expand to render file: "foo/bar".

That means that the file being looked up is not restricted to the view paths, or the rails root path, and can lead to potentially vulnerable leaks from the filesystem.

This pull request changes the default behavior to render template: "foo/bar" instead of render file: "foo/bar", which is restricted to the view paths, as exposing a high level of access to the file system outside of rails views should potentially be explicitly opt-in and not the default.

This may result in a more secure system without having to know the low level underpinnings of the ActionView::Rendering implementation, and I'm submitting this to open a conversation about it. When I first came across this it appeared to be a security issue, and reached out to the security team before looking into it and realizing it was the behavior as designed.

@jejacks0n
Copy link
Contributor Author

I'll fix the specs, but want to have the conversation first, because it has some impacts outside of ActionView.

@sevenseacat
Copy link
Contributor

👍 to the idea

@josevalim
Copy link
Contributor

👍. We have wanted to do this change since Rails 3 but we dropped the ball somewhere along the way. With Rails 5 coming, it seems to be the perfect time to get this in.

@jejacks0n
Copy link
Contributor Author

I'll finish it up then. Thanks for the feedback.

@senny
Copy link
Member

senny commented Sep 15, 2014

should this go through a deprecation cycle in 4.2?

@rafaelfranca
Copy link
Member

If we want to deprecate we need to ask users to explicitly say :file or :template and I think this will lead a lot of changes, but I'm positive for this deprecation cycle (not that it is needed though).

@jejacks0n
Copy link
Contributor Author

@rafaelfranca, the change is only to change the default from :file to :template, not to remove the default entirely. I'd suspect (from searching github) that most people didn't realize that it defaults to :file, so the change may not effect everyone, if what they're rendering is within the view paths.

To clarify, most people who are using this are probably assuming it defaulted to template, and not to file, and so are unlikely to experience issues. It's likely only the cases where someone in fact knew that not supplying an options hash defaulted to :file, and then specifically chose not to use the hash syntax, which I think is a low number.

That being said, I'm happy to follow instructions, and just need guidance on what should happen where, and when.

@rafaelfranca
Copy link
Member

I know, I just pointing if we are going to add deprecation message the only way of people remove the message from their logs is changing the code to explicitly use :file or :template.

For example if we add deprecation message to:

render 'something'

And we show the message: render will change the behaviour from :file to :template.

What would the users will have to do to remove this deprecation warning?

@jejacks0n
Copy link
Contributor Author

Ah, point taken. So, we'd need to verify that the file is within a views path, and if it is don't display the deprecation warning, else display it. Seems hard given what I understand of how that part of the system works currently.

@jejacks0n
Copy link
Contributor Author

Nevermind, I understand what you mean.

@rafaelfranca
Copy link
Member

Yeah, and maybe not worth to show any deprecation message. Since we are going to apply this change in a major bump and, as you said, users will probably not notice something changed I'd go without deprecation and with a note in the upgrading guides.

@chancancode chancancode merged commit 428722b into rails:master Sep 22, 2014
chancancode added a commit that referenced this pull request Sep 22, 2014
Changes default render behavior from file to template.
@jejacks0n
Copy link
Contributor Author

Oh, wow. I was going to fix specs from the other gems first. As long as that's known, awesome. :)

@chancancode
Copy link
Member

@jejacks0n Sorry, no, not known. 😅 I didn't know we have open action items on this one, what gems were you referring to?

@jejacks0n
Copy link
Contributor Author

ActionController and a few others had failing tests. I only adjusted the ActionView tests as a proof, but it apparently has usage outside of that in other tests.

@jejacks0n
Copy link
Contributor Author

I assume any call to render "foo/bar" in the tests would be affected but haven't had time to spend on them. For me each one requires considerable effort to understand the implications and then resolve.

chancancode added a commit that referenced this pull request Sep 22, 2014
This reverts commit 07635a7, reversing
changes made to 1b5f61a.

Reason: it's not ready 💣, see #16888 (comment)
@chancancode
Copy link
Member

Oops, I reverted. We should definitely should get those fixed 😄

chancancode added a commit that referenced this pull request Sep 25, 2014
chancancode added a commit that referenced this pull request Sep 25, 2014
chancancode added a commit that referenced this pull request Sep 25, 2014
chancancode added a commit that referenced this pull request Sep 25, 2014
@jejacks0n
Copy link
Contributor Author

@chancancode what's the status of this? Is it in, or was it reverted? In either case, thanks for fielding this, I was pulled away on work stuff.

@rafaelfranca rafaelfranca modified the milestones: 5.0.0 [temp], 5.0.0 Dec 30, 2015
eileencodes pushed a commit that referenced this pull request Jan 28, 2016
…ate""

This reverts commit 585e756.

Conflicts:
	actionview/CHANGELOG.md
	guides/source/4_2_release_notes.md
eileencodes pushed a commit that referenced this pull request Jan 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants