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

Check Unscoped AR queries with find_by/find_by! #1797

Closed
wants to merge 3 commits into from
Closed

Check Unscoped AR queries with find_by/find_by! #1797

wants to merge 3 commits into from

Conversation

thukim
Copy link

@thukim thukim commented Sep 17, 2023

Fixes 2 issues described in #1786

Brakeman has been updated to include find_by but it does not include find_by!.
Brakeman only checks for find_by on id and doesn't look for any other attributes. In our project the attribute we use public_id instead of id as the publicly facing ID of our models. This means we don't get any warnings for unscoped find for most of our models.

@thukim
Copy link
Author

thukim commented Sep 19, 2023

Hi @presidentbeef ,

I think this repository is having flaky tests (screenshot attached below)

Screenshot 2023-09-19 at 18 30 06

Ref: https://app.circleci.com/pipelines/github/presidentbeef/brakeman?branch=pull%2F1797

The same set of failed tests happen for test-3-2 first and then test-3-1 and it seems to be related to the file lib/sweet_lib.rb
Screenshot 2023-09-19 at 18 32 15

@presidentbeef
Copy link
Owner

Yes, that is a flaky test. Sorry for the trouble. Now I'm finally motivated to fix it - fix incoming shortly, I hope.

@presidentbeef
Copy link
Owner

Should be fixed with #1798. Please rebase on main and try again.

@thukim
Copy link
Author

thukim commented Sep 20, 2023

Thanks, @presidentbeef ! After merging the latest changes from the main branch to this branch, all the tests are green 👍
This PR is also ready to be reviewed.

@presidentbeef
Copy link
Owner

Warning on all uses of find_by/find_by! is a pretty major change.

The intent of the original code was to warn about equivalents to find or find_by_id, and the overall intent of the check is to warn about insecure direct object references - i.e. uses of the row id directly.

This check already has pretty high false positive rate (which is why it is off by default), so I'm pretty hesitant to make it worse.

@thukim
Copy link
Author

thukim commented Sep 27, 2023

I see, thanks @presidentbeef! I will close this PR then

@thukim thukim closed this Sep 27, 2023
@thukim thukim deleted the fix_issue_1786 branch September 27, 2023 03:56
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 this pull request may close these issues.

None yet

2 participants