
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
mongoose-model-security
Advanced tools
Data driven access control layer for mongoose.
This node.js module for mongoose is still under development. Changes are documented in CHANGELOG.md.
If you are using this module and experiencing problems, please report them here.
npm install -save mongoose-model-security
Please note that this module does not automatically install mongoose.
var security;
security.buildPolicy('MyModel').
read({someProperty: 'someValue'}).
// only fields with final 'false' value are removed (or excluded) from select, query and ordering
readFields({someProperty: false, otherField: false}).
update(function(parameters) {
// some complicated logic...
if (satisfied) {
return true;
} else {
return false;
}
}).
update({someOtherProperty: {$in: ['value1', 'value2']}}).
remove(false).
create(true);
mongoosevar mongoose = require('mongoose'),
Security = require('mongoose-model-security');
// setup mongoose / connection
// ...
// initialize security
var security = new Security(mongoose);
// load your models
// ...
// load your policy
security.loadPolicy(policyConfig);
mongoose like you're used tovar mongoose = require('mongoose'),
myModel = mongoose.model('MyModel');
myModel.find(someQueryObj).exec(function(err, myDocuments) {
// only returns myDocuments that satisfy any of the read conditions
// defined in the policy file
myDocuments[0].someProperty = 'someNewValue';
myDocuments[0].save(function(err) {
// will return with an error and not save the document, if none of the
// update conditions from the policy file are met
});
});
Using this module in combination with mongoose allows defining access permissions (create, read, update, remove) for all models. It acts transparently on all interactions with mongoose, i.e. you should not have to change already implemented business code, in order to have permissions checked.
Queries are automatically decorated with conditions as defined in the model's policy. Queries will always only return documents that the current user has permission to read.
Each of these operations are automatically intercepted and permissions are tested before the operation is executed. The provided callback is called with an error if the current user has insufficient permissions.
A policy can be defined per model and per permission (create, read, update, remove). This is done by providing rules. A rule might be any of the following:
All provided rules for the same model and permission are or-combined when
evaluated, i.e. the permission is granted if any of the provided conditions
are met.
When using functions to return rules (see above), a parameters object is passed in as the only argument. The parameters object contains the following properties:
var security;
security.addModelProvider(function() {
var myValue;
return {
myParam: myValue
};
});
All defined model providers will be called before the rules are evaluated.#find[*]And[Remove|Update] methods on both
model and query as well as Model.update. This is due to the fact that mongoose middleware is not
called for these methods (see here).Copyright (c) 2015 Thomas Forrer
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Data driven access control layer for mongoose.
We found that mongoose-model-security demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.