-
-
Notifications
You must be signed in to change notification settings - Fork 753
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
Database adapter security and usability improvements #925
Comments
@daffl Fully support the direction of these breaking changes, especially the points under |
For the Non-Feathers query syntax, @vonagam has already done great work and submitted pretty much everything we need in feathersjs-ecosystem/commons#73 |
Love this proposal. It addresses exactly the painpoints I head when I was starting with feathers. Multi updates & Non Feathers query syntaxDo you plan that these features can be set by hooks too or only at service creation? The former one would be really nice. For example: Admins or import / export software should be able to to use mutli but regular users shouldn't. Same with queries:
ChannelsAnother thing that comes to my mind: What about channels? All events are sent to all clients by default. I get that you want to provide a neat first-use experience and therefore the system should work right out of the box. And there is a warning in the console about this behavior, too. But do you think that this is sufficient or should the developer need to uncomment something in channels.js to get this functionality so that it is more obvious whats happening? EDIT: DataIs there anything planned to remove special operators from the data the user sends to the service? For example mongodb supports $set syntax. Might be a special case for mongo that should be addresses in the specific database adapter. Just curious if you did think about it :) |
Multi updates & Non Feathers query syntaxOnce enabled this should already possible with a hook right? context => {
if(Array.isArray(context.data) && !isAdmin(context.params.user)) {
throw new Error('Multi update not allowed');
}
} ChannelsThis is no longer the case in Feathers Buzzard. By default a generated application is set up to publish to all authenticated users but that is explicitly defined in the generated DataHm, I haven't really thought about that. Should it remove those parameters? Are there any that could be a potential security issue? |
Multi updates & Non Feathers query syntaxYeah, that works. Thought about like setting a special param or something to allow multi updates. But your way is way more clean by not using some magic params 😄 ChannelsI did not express myself correctly. I meant the new behavior. Just replace "All events are sent to all clients by default." with "All events are sent to all authenticated clients by default." in my comment. Which is a bit more secure but if your app is open for registration it quickly loses this advantage. I just want to discuss if it might be better to comment this line out: I can say from my own experience that I ignored how channels work at first. It just worked out and I was satisfied. Only later did I look at the details and changed the default implementation. My laziness may have come from being accustomed to firebase, not having to worry about event handling. DataWell, it depends on how you do your validation. For Example: You are stripping the role attribute from your users input, so that he could not make himself an admin. Here is how a malicious user could gain admin access: // userSchema
interface User {
displayName: string // Can be changed by user
role: 'admin' | 'user' // Stripped in before hook if it is an user
// ...
}
// Set role
patch({ something: 'foo', $set: { role: 'admin' } })
// Another Way
patch({ displayName: 'admin' })
patch({ $rename: { 'displayName': 'admin' } }) But if you use something like JSON Schema with |
Released @feathersjs/adapter-commons. To be updated:
Migration instructions can be found at https://crow.docs.feathersjs.com/migrating.html#database-adapters |
@daffl I started to work on integrating these changes into feathers-objection & feathers-cassandra. I'm using the migration guide and your feathers-sequelize PR as a reference. |
@dekelev Awesome! Let me know if you need anything. The basic steps are
You can use the new test suite via const adaptertests = require('@feathersjs/adapter-commons/tests');
const testSuite = adaptertests([
]); This will not run any adapter tests (yet) and just print a list of test that have been skipped. Then you can selectively work on the tests you want to run (instead of when all tests ran at once). For example const testSuite = adaptertests([
'.get',
'.get + $select'
]); Will run the test for |
@daffl Thanks! I'll start adding support in |
It wasn't using the previous test suite either right? Part of the idea for the new one was to not having to enable all tests but still having partial adapter functionality covered. What are the limitations for Cassandra? |
It is using a modified version of the previous test suite. The limitations that I remember is that pagination & skip does not exists in Cassandra. There's also no $or, $ne or $nin and some queries requires the allowFiltering param or using the PK fields in some other way to make it work. There's no auto-increment PK and sorting is very limited. Some of the querying limitations were solved by using SASI indexes. I'll check if I can use the new test suite there and will let you know what I found, but for now I'll use what I got. Here are the operators I used as default in feathers-cassandra until now. I guess that it should also work with the defaults for security reasons, from the kind that can drastically affects the DB server performance if the client used $allowFiltering on column without SASI index, using $if to add transaction like operation when it should be forbidden or the $noSelect to effect the results the server might expects. Relation load are not an issue since there are no model relations in feathers-cassandra.
|
@daffl |
Feathers database adapters cover a wide range of standard CRUD functionality. Although the standard behaviour is documented, their currently very open nature can make it easy to miss adding certain restrictions in order to secure your application properly. To improve this, I am planning to implement the following breaking changes:
Single items and
params.query
get
,remove
,update
andpatch
will respect thequery
object additionally to theid
. This will make it much easier to limit access for users by setting thequery
with limitations (e.g. an owneruserId
) much like it is already done for normalfind
calls.Multiple updates
create
with arrays and multiple updates (patch
,update
andremove
with idnull
) will be disabled by default. They can be enabled explicitly by setting themulti
options totrue
(or the list or methods to allow). It is then up to the developer to make sure that those calls are secured properly and all affected hooks are also taking result arrays into consideration.Non Feathers query syntax
All adapters support Feathers common query syntax. However, some adapters like
feathers-nedb
,feathers-mongodb
andfeathers-mongoose
allow passing other queries as well. The next version of all database adapters will no longer allow any non-Feathers queries that are directly passed to the database. Instead, additional database specific query properties that should be allowed have to be explicitly whitelisted and secured appropriately:Improved
feathers-service-tests
How to write your own database adapter is a question that comes up quite often. Although the most straightforward answer is to create a custom service, there is also some infrastructure in feathers-service-tests in place that makes sure that the official adapters all support the common syntax properly. The tests will now be split into stages to make it easier to implement other adapters that work the same way step-by-step:
get
,create
,patch
,update
andremove
functionality andfind
by properties$limit
,$skip
,$sort
and$select
, multiupdate
,patch
andremove
$lt
,$in
etc.)feathers-rethinkdb
Because of the still uncertain future of RethinkDB, low download numbers and some notable challenges working with RethinkDB, I am not planning on including feathers-rethinkdb in these updates. It will continue to work as is an and can be added to your project manually but it will not be included in future versions of the generator.
The text was updated successfully, but these errors were encountered: