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

Error: undefined method `node_type' for nil:NilClass case value.node_type #1790

Closed
tim-heinsohn opened this issue Aug 21, 2023 · 4 comments · Fixed by #1800
Closed

Error: undefined method `node_type' for nil:NilClass case value.node_type #1790

tim-heinsohn opened this issue Aug 21, 2023 · 4 comments · Fixed by #1800

Comments

@tim-heinsohn
Copy link

tim-heinsohn commented Aug 21, 2023

Background

Brakeman version: 6.0.1
Rails version: 7.0.4.3
Ruby version: 3.1.4p223

Issue

When running brakeman --debug . I get the following error:

Error: undefined method `node_type' for nil:NilClass          case value.node_type                   ^^^^^^^^^^
Location: /home/t/.rvm/gems/ruby-3.1.4/gems/brakeman-6.0.1/lib/brakeman/tracker/controller.rb:126:in `before_filter_to_hash'
/home/t/.rvm/gems/ruby-3.1.4/gems/brakeman-6.0.1/lib/brakeman/tracker/controller.rb:93:in `block in get_before_filters'
/home/t/.rvm/gems/ruby-3.1.4/gems/brakeman-6.0.1/lib/brakeman/tracker/controller.rb:92:in `each'
/home/t/.rvm/gems/ruby-3.1.4/gems/brakeman-6.0.1/lib/brakeman/tracker/controller.rb:92:in `get_before_filters'
/home/t/.rvm/gems/ruby-3.1.4/gems/brakeman-6.0.1/lib/brakeman/tracker/controller.rb:44:in `before_filter_list'
/home/t/.rvm/gems/ruby-3.1.4/gems/brakeman-6.0.1/lib/brakeman/processors/controller_alias_processor.rb:239:in `before_filter_list'
/home/t/.rvm/gems/ruby-3.1.4/gems/brakeman-6.0.1/lib/brakeman/processors/controller_alias_processor.rb:95:in `block in process_defn'
/home/t/.rvm/gems/ruby-3.1.4/gems/brakeman-6.0.1/lib/brakeman/processors/alias_processor.rb:523:in `block in meth_env'
/home/t/.rvm/gems/ruby-3.1.4/gems/brakeman-6.0.1/bundle/ruby/3.1.0/gems/sexp_processor-4.17.0/lib/sexp_processor.rb:452:in `scope'
/home/t/.rvm/gems/ruby-3.1.4/gems/brakeman-6.0.1/lib/brakeman/processors/alias_processor.rb:520:in `meth_env'
/home/t/.rvm/gems/ruby-3.1.4/gems/brakeman-6.0.1/lib/brakeman/processors/controller_alias_processor.rb:93:in `process_defn'
/home/t/.rvm/gems/ruby-3.1.4/gems/brakeman-6.0.1/lib/ruby_parser/bm_sexp_processor.rb:76:in `block in process'
/home/t/.rvm/gems/ruby-3.1.4/gems/brakeman-6.0.1/lib/ruby_parser/bm_sexp_processor.rb:113:in `in_context'
/home/t/.rvm/gems/ruby-3.1.4/gems/brakeman-6.0.1/lib/ruby_parser/bm_sexp_processor.rb:72:in `process'
/home/t/.rvm/gems/ruby-3.1.4/gems/brakeman-6.0.1/lib/brakeman/processors/alias_processor.rb:62:in `block in process_default'
(eval):3:in `map!'
(eval):3:in `map!'
/home/t/.rvm/gems/ruby-3.1.4/gems/brakeman-6.0.1/lib/brakeman/processors/alias_processor.rb:60:in `process_default'
/home/t/.rvm/gems/ruby-3.1.4/gems/brakeman-6.0.1/lib/brakeman/processors/controller_alias_processor.rb:31:in `process_controller'
/home/t/.rvm/gems/ruby-3.1.4/gems/brakeman-6.0.1/lib/brakeman/processor.rb:50:in `process_controller_alias'
/home/t/.rvm/gems/ruby-3.1.4/gems/brakeman-6.0.1/lib/brakeman/scanner.rb:280:in `block (2 levels) in process_controller_data_flows'
/home/t/.rvm/gems/ruby-3.1.4/gems/brakeman-6.0.1/lib/brakeman/scanner.rb:279:in `each'
/home/t/.rvm/gems/ruby-3.1.4/gems/brakeman-6.0.1/lib/brakeman/scanner.rb:279:in `block in process_controller_data_flows'
/home/t/.rvm/gems/ruby-3.1.4/gems/brakeman-6.0.1/lib/brakeman/scanner.rb:341:in `block in track_progress'
/home/t/.rvm/gems/ruby-3.1.4/gems/brakeman-6.0.1/lib/brakeman/scanner.rb:338:in `each'
/home/t/.rvm/gems/ruby-3.1.4/gems/brakeman-6.0.1/lib/brakeman/scanner.rb:338:in `track_progress'
/home/t/.rvm/gems/ruby-3.1.4/gems/brakeman-6.0.1/lib/brakeman/scanner.rb:277:in `process_controller_data_flows'
/home/t/.rvm/gems/ruby-3.1.4/gems/brakeman-6.0.1/lib/brakeman/scanner.rb:66:in `process'
/home/t/.rvm/gems/ruby-3.1.4/gems/brakeman-6.0.1/lib/brakeman.rb:392:in `scan'
/home/t/.rvm/gems/ruby-3.1.4/gems/brakeman-6.0.1/lib/brakeman.rb:86:in `run'
/home/t/.rvm/gems/ruby-3.1.4/gems/brakeman-6.0.1/lib/brakeman/commandline.rb:157:in `run_brakeman'
/home/t/.rvm/gems/ruby-3.1.4/gems/brakeman-6.0.1/lib/brakeman/commandline.rb:125:in `regular_report'
/home/t/.rvm/gems/ruby-3.1.4/gems/brakeman-6.0.1/lib/brakeman/commandline.rb:166:in `run_report'
/home/t/.rvm/gems/ruby-3.1.4/gems/brakeman-6.0.1/lib/brakeman/commandline.rb:35:in `run'
/home/t/.rvm/gems/ruby-3.1.4/gems/brakeman-6.0.1/lib/brakeman/commandline.rb:20:in `start'
/home/t/.rvm/gems/ruby-3.1.4/gems/brakeman-6.0.1/bin/brakeman:10:in `<top (required)>'
/home/t/.rvm/gems/ruby-3.1.4/bin/brakeman:25:in `load'
/home/t/.rvm/gems/ruby-3.1.4/bin/brakeman:25:in `<main>'
/home/t/.rvm/gems/ruby-3.1.4/bin/ruby_executable_hooks:22:in `eval'
/home/t/.rvm/gems/ruby-3.1.4/bin/ruby_executable_hooks:22:in `<main>'

in

case value.node_type

Using safe navigation seems to resolve the issue:

        case value&.node_type

but I'm not filing a PR as I'm not sure what the code is doing.

The args leading to the error look like this:

[1] pry(#<Brakeman::Controller>)> args
=> s(s(:lit, :fake_filter8984522737743934), s(:hash, s(:kwsplat, s(:lvar, :options))))
@tim-heinsohn
Copy link
Author

I get the same error with Brakeman 5.2.1, so probably a local / rvm issue.

@presidentbeef
Copy link
Owner

Hi @tqmz - wow this is some old Brakeman code that was written well before keyword splats existed in Ruby 😄

@tim-heinsohn
Copy link
Author

Nice @presidentbeef, thanks! (Will there be a patch release?)

@presidentbeef
Copy link
Owner

Yes, soon... 🤞

Repository owner locked and limited conversation to collaborators May 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants