You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The active model where method should act as a normal parameterized scope #116
Currently returns nil if used on a AR class, and throws a non-related error if used on a scope.
THIS WAS THE ORIGINAL CONCLUSION BUT ITS INCORRECT SEE DISCUSSION:
The reasons we won't implement where is that it could be used to insecurely determine counts on data.
For example Customers.where(top_secret_attribute: true).count could be executed from the JS console to find the count of customers with the top_secret_attribute.
where should be implemented as a scope.
We will need to add scope called __hyperstack_internal_where_scope
classActiveRecord::Basescope__hyperstack_internal_where_scope,->(attrs){where(attrs)},# server side we just call wherefilter: ->(attrs){ !attrs.detect{ |k,v| self[k] != v}# client side optimizationdefself.where(attrs)__hyperstack_internal_where_scope(attrs)endifRUBY_ENGINE == 'opal'end
On the client side we can add the class level where method to ActiveRecord::Base and which simpy calls the `__hyperstack_internal_where_scope.
where is working within scopes, I presume this is not a security issue?
Suggestion for an error message:
Hypermodel does not support where outside of a scope for "security reasons". See [link to explanation] for details.
Please use scopes, find, find_by and ActiveRecord relations to query your data.
If you think you can write a secure where implementation, feel free to impress us.
changed the title [-]The active model `where` method should consistently throw an error.[/-][+]The active model `where` method should act as a normal parameterized scope[/+]on Feb 14, 2019
@Tim-Blokdijk yes you are right, and in fact, I am wrong in my overall conclusion. where can act like any other scope, and will simply follow the normal security rules. Thus if you do not open up the all scope then doing Customers.where(top_secret_attribute: true) will fail because no scope ever granted permission.
In practical terms you could do this:
classCustomer < ApplicationRecordregulate_scope:all,->(){acting_user.admin?}# admins can get any data neededend
Activity
Tim-Blokdijk commentedon Jan 28, 2019
where is working within scopes, I presume this is not a security issue?
Suggestion for an error message:
Hypermodel does not support
whereoutside of a scope for "security reasons". See [link to explanation] for details.Please use
scopes,find,find_byand ActiveRecordrelationsto query your data.If you think you can write a secure
whereimplementation, feel free to impress us.[-]The active model `where` method should consistently throw an error.[/-][+]The active model `where` method should act as a normal parameterized scope[/+]catmando commentedon Feb 16, 2019
@Tim-Blokdijk yes you are right, and in fact, I am wrong in my overall conclusion.
wherecan act like any other scope, and will simply follow the normal security rules. Thus if you do not open up theallscope then doingCustomers.where(top_secret_attribute: true)will fail because no scope ever granted permission.In practical terms you could do this:
now
will only work if executed by an admin.
closes #116 #127 #399 #358 (again)
catmando commentedon Apr 5, 2021
closed in 1.0.alpha1.7
closes hyperstack-org#116 hyperstack-org#127 hyperstack-org#399 hyper…
CI: start Postgres and Redis only in the jobs that use them (hypersta…
Merge branch 'ci/issue-116-service-gating' into 'edge'
CI: parse .gitlab-ci.yml in gem:check instead of pattern-matching it (h…