Skip to content
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

Disable logging args in ShopifyApp jobs #1086

Merged
merged 2 commits into from
Sep 29, 2020
Merged

Conversation

tanema
Copy link
Contributor

@tanema tanema commented Sep 28, 2020

Since shop tokens are passed into the parameters of the jobs and there has been a tendency for people to copy and paste these logs while debugging, it seems safest to redact the arguments from the jobs so that this will not happen accidentally in the future.

This will patch ActiveJob::Logging::LogSubscriber for rails < 6.1 and use log_arguments = false for rails >= 6.1

@tanema tanema requested a review from a team as a code owner September 28, 2020 17:23
private

def args_info(job)
log_disabled_classes = %w(ShopifyApp::ScripttagsManagerJob ShopifyApp::WebhooksManagerJob)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to define this behaviour in the classes themselves? It seems like it would be easy to forget to add new classes to the list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we could add an attribute to check on each class but these jobs have been consistently alone for 5 years now :D

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough 😄 , I just thought that this isn't something we want to forget in the future.

Security
--------

Please be certain to redact any private information from your logs or code snippets such as Api Keys, Api Secrets, and any authentication tokens such as shop_tokens.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Please be certain to redact any private information from your logs or code snippets such as Api Keys, Api Secrets, and any authentication tokens such as shop_tokens.
Please be certain to redact any private information from your logs or code snippets such as API keys, API secrets, and any authentication tokens such as shop tokens.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I specifically used shop_token so that they would see that visually and look in their logs for it visually.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe write it as "shop_tokens"? (bit clunky, I know)

lib/shopify_app/engine.rb Outdated Show resolved Hide resolved
@@ -21,5 +31,16 @@ class Engine < Rails::Engine
app.config.middleware.insert_after(ShopifyApp::SameSiteCookieMiddleware, ShopifyApp::JWTMiddleware)
end
end

initializer "shopify_app.redact_job_params" do
ActiveSupport.on_load(:active_job) do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to consider older Rails apps that don't use ActiveJob?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ActiveJob was introduced in Rails 4.2 and this gem required 5.2

Tim Anema added 2 commits September 29, 2020 14:44
redacting job params in the shopify app jobs so that sensitive
information is not accidentally pasted into issues.
@tanema tanema merged commit 9813df1 into master Sep 29, 2020
@tanema tanema deleted the disable_logging_args_in_jobs branch September 29, 2020 19:31
@tanema tanema temporarily deployed to rubygems September 29, 2020 20:17 Inactive
@netwire88
Copy link

Hi @andyw8 , Do you know which version of Rails is required for log_arguments to work? When I added self.log_arguments to class OrdersUpdatedJob < ActiveJob::Base, it didn't work. I believe log_arguments requires rails 6.1, but shopify_app doesn't work on 6.1 yet.

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

Successfully merging this pull request may close these issues.

None yet

5 participants