-
Notifications
You must be signed in to change notification settings - Fork 734
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
Namespaced classes that are not fully qualified can cause difference in false positives/negatives #1387
Comments
Thank you for the clear examples and the example application! I am looking at this now... I really don't want to try to replicate Ruby's name resolution, but I don't think it would be too difficult to at least store alternate names for each class. |
I've tracked this down with the code that @doliveirakn included for his example app to the problem occurring in: brakeman/lib/brakeman/checks/base_check.rb Lines 443 to 455 in a882d53
Specifically the failure occurs here where
And I put together a poor man's fix against line 451:
This gets the desired test results and passes all specs, but I suspect this is largely because namespaced specs have not been written, likely this is not performant, and I can think of a few cases where this could report false positives. Hopefully this is enough to kick off conversation on a fix, and if there is a different direction I should be taking, please let me know. Thanks! |
I spent some time on this previously: https://github.com/presidentbeef/brakeman/compare/class_names There are a lot of changes because I tried to lift class names into an actual class instead of managing them as symbols. However, in the end the result was probably similar to yours: fuzzier matching on class names. Unfortunately, it was too fuzzy. It seemed to only really work okay for models, not controllers. This led to too many weird results and false positives. I haven't revisited it since, but I do believe there is still room for improvement. |
Background
Brakeman version: 4.5.1
Rails version: 5.0.7.2
Ruby version: 2.4.3
Link to Rails application code:
Issue
What problem are you seeing?
If we reference a namespaced ActiveRecord module without it being fully qualified constant, Brakeman will fail to identify it as a model and may report false positives or negatives.
Code:
Running brakeman on this will result in 2 security warnings
It appears that brakeman is able to determine that
Document
is an ActiveRecord model but it cannot determine thatTask
is a model. This causes the checks to differ in behaviour and may report false negatives (Namespace::TasksController#index
should have the same warning as the document one), or false positives (Namespace::TasksController#show
should not have this warning)It was not clear to me how many checks would be affected by this. It is clear that the
Redirect
check is affected, but there may be more. This may also affect more types of files as opposed to just models too as I believe any class lookup (such as controllers or jobs) would have a similar issueThe text was updated successfully, but these errors were encountered: