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

ActiveRecord::UnknownAttributeReference - Dangerous query method #1094

Open
activklaus opened this issue Dec 19, 2022 · 1 comment
Open

ActiveRecord::UnknownAttributeReference - Dangerous query method #1094

activklaus opened this issue Dec 19, 2022 · 1 comment

Comments

@activklaus
Copy link

Trying to run something simple like

post.tagged_with('awesome')

and keep getting

ActiveRecord::UnknownAttributeReference (Dangerous query method (method whose arguments are used as raw SQL) called with non-attribute argument(s): "SELECT COUNT(taggings.*) AS taggings_count FROM taggings ORDER BY taggings_count DESC".This method should not be called with user-provided values, such as request parameters or model attributes. Known-safe values can be passed by wrapping them in Arel.sql().)

When I run

post.tagged_with('awesome', any: true)

everything works fine.

Running Rails 7 on Ruby 3, acts-as-taggable-on 9.0.1

@activklaus
Copy link
Author

Sorry, I wasn't precise enough. The query looked like this:

post.tagged_with('awesome', any: false, order_by_matching_tag_count: true)

After removing order_by_matching_tag_count: true the exception disappeared.

Although this makes sense in a logical way (when you look for items that are all tagged with the exact same tags you cannot order them by tag count) I think it is still in an issue because in a technical way the query should be perfectly valid. Yet, the gem builds a query that violates the Rails logic of safe queries by creating a query string that contains stringified potentially insuecure ("user-provided") values.

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

No branches or pull requests

1 participant