rubocop-rails icon indicating copy to clipboard operation
rubocop-rails copied to clipboard

New cop to make sure Digest is used within OpenSSL context

Open BackendDev-Auction opened this issue 3 years ago • 2 comments

Is your feature request related to a problem? Please describe.

The is for the rails Issue - https://github.com/rails/rails/issues/42665 Basically the team wants to use OpenSSL::Digest and prevent any new code to use Digest.

Describe the solution you'd like

So a new cop lint rule for that.

A clear and concise description of what you want to happen.

I have already opened a PR on the rails repo, but I suppose the likely outcome is to have an optional cop on the rubocop-rails repo

Solution Suggestion Cop could look something like this

    class DigestWithOpenSSL < RuboCop::Cop::Base
      MSG = "Digest may only be called from OpenSSL"

      def_node_matcher :digest_open_call?, <<~PATTERN
        (const nil? :Digest)
      PATTERN

      def on_const(node)
        return unless digest_open_call?(node)
        add_offense(node)
      end
    end

BackendDev-Auction avatar Jul 14 '21 12:07 BackendDev-Auction

Which of the following layers has this issue?

  1. Rails framework layer (rails/rails repo) specific issue
  2. The issue that Rails application layer will be affected
  3. General issue with OpenSSL library of Ruby (e.g. https://github.com/ruby/openssl)

I'm not sure about this issue. Could you summarize and explain the background of this issue?

koic avatar Jul 15 '21 09:07 koic

I think its both 1 and 2. Though I'm not completely sure myself. These can provide more context, https://github.com/rails/rails/pull/40770#issuecomment-748347066 Though the actual issue states new code going into rails/rails

vishaldeepak avatar Jul 15 '21 10:07 vishaldeepak

I tried to read the links, but it seems difficult to understand without the summary. I will close this issue, but if there is an explanation that is easy to understand for user level (In other words, the cop manual text) , I think we can consider it again. Thank you.

koic avatar Apr 04 '23 02:04 koic