Skip to content

Commit

Permalink
Update the rendering guide to match the current behavior
Browse files Browse the repository at this point in the history
In the latest security releases render with a trailing slash no more call
render :file.

Also add a note about the security implications of using it with user
parameters.
  • Loading branch information
rafaelfranca committed Mar 5, 2016
1 parent 23d5559 commit 3f0cbcb
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions guides/source/layouts_and_rendering.md
Expand Up @@ -175,23 +175,22 @@ render template: "products/show"

#### Rendering an Arbitrary File

The `render` method can also use a view that's entirely outside of your application (perhaps you're sharing views between two Rails applications):

```ruby
render "/u/apps/warehouse_app/current/app/views/products/show"
```

Rails determines that this is a file render because of the leading slash character. To be explicit, you can use the `:file` option (which was required on Rails 2.2 and earlier):
The `render` method can also use a view that's entirely outside of your application:

```ruby
render file: "/u/apps/warehouse_app/current/app/views/products/show"
```

The `:file` option takes an absolute file-system path. Of course, you need to have rights to the view that you're using to render the content.
The `:file` option takes an absolute file-system path. Of course, you need to have rights
to the view that you're using to render the content.

NOTE: Using the `:file` option in combination with users input can lead to security problems
since an attacker could use this action to access security sensitive files in your file system.

NOTE: By default, the file is rendered using the current layout.

TIP: If you're running Rails on Microsoft Windows, you should use the `:file` option to render a file, because Windows filenames do not have the same format as Unix filenames.
TIP: If you're running Rails on Microsoft Windows, you should use the `:file` option to
render a file, because Windows filenames do not have the same format as Unix filenames.

#### Wrapping it up

Expand Down

0 comments on commit 3f0cbcb

Please sign in to comment.