Skip to content
This repository has been archived by the owner on Dec 8, 2020. It is now read-only.

Timber silence log from action_on_unpermitted_parameters #172

Open
jonquach opened this issue Oct 25, 2017 · 5 comments
Open

Timber silence log from action_on_unpermitted_parameters #172

jonquach opened this issue Oct 25, 2017 · 5 comments

Comments

@jonquach
Copy link

jonquach commented Oct 25, 2017

It seems that timber is silencing the logs from action_on_unpermitted_parameters, I currently have set in developement.rb the following configuration:

config.action_controller.action_on_unpermitted_parameters = :log

I also tried to set the silence integration to false:

config.integrations.action_controller.silence = false

But it still doesn't log the unpermitted params, maybe I missed something in the configuration, any help ?

@binarylogic
Copy link
Contributor

Hi @jonquach, that's odd. We'll take a look and see what's going on. Thanks for reporting.

@binarylogic
Copy link
Contributor

Hi @jonquach, good news and bad news. The bad news is that we could not reproduce; we tested this extensively and confirmed that it is working for us. The good news is that I'm thinking your log level is not set to :debug which would be a very easy fix. Notice here that the method is part of the ActionController::LogSubscriber class and the message is logged at the debug level. Then, if you head over to the TimberLogSubscriber class you'll notice it extends the same ActionController::LogSubscriber class. That method is included through inheritance.

An easy way to test on your end is to do throw this temporary code in your config/initializers/timber.rb file:

# config/initializers/timber.rb

class ::ActionController::LogSubsucriber
  def unpermitted_parameters(event)
    info do
        unpermitted_keys = event.payload[:keys]
        "Unpermitted parameter#{'s' if unpermitted_keys.size > 1}: #{unpermitted_keys.map { |e| ":#{e}" }.join(", ")}"
    end
  end
end

This patch will raise the level to info and you will (hopefully) see these log messages again. Let me know if that helps.

@jonquach
Copy link
Author

jonquach commented Oct 30, 2017

Hello @binarylogic, thanks for your help
I checked and the log level is correctly set at :debug, and still nothing.

I tried to add the code you provided into config/initializers/timber.rb but it seems that it's not taken into account, I tried to put some print and the method isn't called at all.

But, after that I tried to edit the TimberLogSubscriber class to add the unpermitted_parameters method, and then it worked, correctly logged the Unpermitted parameter.
See gist here

Do you have any idea why ?

By the way, I notice that in the code snippet there is a typo on

class ::ActionController::LogSubsucriber

to

class ::ActionController::LogSubscriber

@jonquach
Copy link
Author

jonquach commented Oct 31, 2017

I tested on a new rails project from scratch, you can clone it here, it's the getting started from rails. I used rails 5.1.

In the article_controller.rb, only the params :title and :text are allowed, in the view articles/new.html.erb, there is a form with a extra params called :not_allowed_params that I passed for the creation, and it is not logged as an unpermitted params.

screen shot 2017-10-31 at 10 56 15

@binarylogic
Copy link
Contributor

Hi @jonquach thank you for putting this together. Going to pull down your test app and see what's going on.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants