Any smart workaround to avoid having to introduce the h method worldwide?

It seems ridiculous (and a violation of DRY) to have it dial the h method all over the place of your view code to make it safe.

Has anyone come up with a smart workaround for this?

+4
source share
4 answers

You can use XSS_terminate , which filters the data entering your application (when saving), instead of trying to catch it at the last possible second of an hour ().

Theoretically, this should be enough, and you do not need to do anything.

If you want to be paranoid (which is not so bad in the security context), you must do both.

+3
source

DHH (Rails creator) agrees with you. By default, Rails 3 will produce output.

+4
source

You can use Erubis as your ERB engine, which offers automatic shielding. Their tests mark this as 3 times faster than ERB.

http://www.kuwata-lab.com/erubis/

The only problem is that it is unique to ERB, so if your Haml or some other template language (like us), then you are SOL. I used Erubis in the past and had no problem with this - before we switched to (slower) Haml.

+4
source

The Rails 3 approach is by far the best on the review side, because it clearly tracks the security of each line, which ultimately means what you need (taint mode) for a reliable solution.

However, there is another approach that ActsAsTextiled does. That is, override the accessor attribute to sanitize and cache the result so that you always get disinfected output by default. What I like about this and not the xss_terminate style is that it doesn't concern user input at all, so you get fewer complaints from users and the data will not be accidentally clogged, and you can go and change the rules later if you missed something.

I liked the approach so much, I wrote a plugin using the Sanitize gem ActsAsSanitiled . This does not give you a protective shell out of the box, as xss_terminate can, but also avoids unwanted side effects. In my case, relatively few text fields are actually edited directly by users, so I prefer to check them and declare them explicitly.

0
source

All Articles