You are here: Forums Ask a Rails expert implementing whitelist plugin ...
Posted in Forums : Ask a Rails expert
Authority 0
Posting Rating 27
Sign in to rate this post
|
Hi everyone |
Authority 37
Posting Rating 100
Sign in to rate this post
|
Could you describe what you’re trying to achieve and maybe give a more detailed description of your problem? If you want to whitelist more tags than the ones that Rick whitelists as a default (check out the bottom of http://svn.techno-weenie.net/projects/plugins/white_list/lib/white_list_helper.rb for details), you just call WhiteListHelper.tags.merge %w(...) and replace the stuff in parentheses with the tags you want to add to the whitelist. |
Authority 0
Posting Rating 27
Sign in to rate this post
|
I have a textarea like this in one of my forms: I need to use the whitelist plugin for this textarea so that if the user adds any javascript tag here it should be removed. So basically my question is how do I make use of the white list plugin for this textarea ? |
Authority 37
Posting Rating 100
Sign in to rate this post
|
You think wrongly of what the whitelist plugin does. It does NOT filter the user INPUT but the OUTPUT. You could of course already write the filtered input to the database, but it’s more common to write the stuff in the database as the user wrote it in the form and then, when you output it, run the whitelist helper on it. So, in your case, you would put the whitelist call in the templates that actually output the description like this: <%= white_list @product.description %> I put @product as the object because I don’t know what model we’re talking about. HTH |
|
Authority 0
Posting Rating 73
Sign in to rate this post
|
To do it at a app level upon form/data submission, I use a slightly modified version of the whitelist helper and use it as a library.. So then in application_controller.rb include HtmlFilterHelper before_filter :sanitize_params
|
Authority 0
Posting Rating 27
Sign in to rate this post
|
I have tried all possible methods but to no avail. Actually there is the tiny_mce plugin used as well. If I remove that javascript then it is working fine on textarea in edit page. But on the actual page it does not. If I look at the page source I can see the scriptt ag converted perfectly to plain html and even in the database table but it does not somehow appear that way on the screen. |
Authority 37
Posting Rating 100
Sign in to rate this post
|
I still don’t understand what your actual problem is … Why would you want to write sanitized HTML in your database? There’s no real use to it except that you only have to sanitize it once which will save some resources on the long run. On the other hand, if you decide to add tags/attributes to your whitelist, you’ll have to update all records in the database to make sure that the change is persistent. And if you remove tags/attributes from your whitelist, strings that have been sanitized using the outdated configuration will can’t be restored to their original state. You see: Sanitizing user input (beware: not talking about sanitizing SQL here) is usually a bad idea except if you have very good reasons for it. Filter the output instead. |
Authority 0
Posting Rating 27
Sign in to rate this post
|
I finally found a method through which I can apply the white_list plugin for all elements in my project. I followed the link “http://code.google.com/p/sanitizeparams/source/diff?r=7&format=side&path=/trunk/sanitize_params/README”. But the problem is when I add the line config.plugins = [:white_list, :sanitize_params, :all] to my environment.rb i get an error: Pls help. I’m using ruby 1.8.6 and rails 1.2.6. |
Authority 37
Posting Rating 100
Sign in to rate this post
|
Why do you have that line in your config? The config.plugins stuff is only needed when you need to specify a certain order for your plugins … Just leave this line out and have them included in alphabetical order. PS: The error’s there because you probably haven’t moved your plugin to the correct directory (vendor/plugins/white_list). |
Ask a Rails expert : Sanitizing html
Ask a Rails expert : First post, requesting sage perspective
Ask a Rails expert : How to use mephisto
Ask a Rails expert : How to use mephisto
Ask a Rails expert : will_paginate customization problem
Ask a Rails expert : BackgroundRB still wants 'development' environment...?
Ask a Rails expert : activescaffold, sql exception
Ask a Rails expert : Passing non-english chars in query string
Ask a Rails expert : Rails and 2D barcodes
Ask a Rails expert : apache giving proxy error