0

We have a problem with Sails policies.

Our default policy is:

'*': [
'basicAuth',
'passport',
'sessionAuth',
'ModelPolicy',
'AuditPolicy',
'UpdatedByPolicy',
'OwnerPolicy',
'OmniPolicy'
],

But when I start the server is complains about another policy called CriteriaPolicy, which is NEVER referenced in our policies.js

The CriteriaPolicy comes from the Sails module called sails-permission, which we have installed. However we only want to use some of its polices and not all.

So why is Sails not using our app's config/policies.js as the TRUTH. Why does it allow modules to ADD policies, if I dont want them?

How can I force Sails to only adhere to the policies from the app's config/policies.js?

This the error we get:

TypeError: Cannot read property 'length' of undefined at /node/ourapp/node_modules/sails-permissions/dist/api/policies/CriteriaPolicy.js:50:12 at arrayMap (/node/ourapp/node_modules/sails-permissions/node_modules/lodash/index.js:1406:25) at Function.map (/node/ourapp/node_modules/sails-permissions/node_modules/lodash/index.js:6710:14) at module.exports (/node/ourapp/node_modules/sails-permissions/dist/api/policies/CriteriaPolicy.js:49:96) at routeTargetFnWrapper (/node/ourapp/node_modules/sails/lib/router/bind.js:181:5) at callbacks (/node/ourapp/node_modules/@sailshq/express/lib/router/index.js:164:37) at param (/node/ourapp/node_modules/@sailshq/express/lib/router/index.js:138:11) at param (/node/ourapp/node_modules/@sailshq/express/lib/router/index.js:135:11) at pass (/node/ourapp/node_modules/@sailshq/express/lib/router/index.js:145:5) at nextRoute (/node/ourapp/node_modules/@sailshq/express/lib/router/index.js:100:7) at callbacks (/node/ourapp/node_modules/@sailshq/express/lib/router/index.js:167:11) at /node/ourapp/plugins/plugin-ourapp-foundation/api/policies/OmniPolicy.js:184:12 at /node/ourapp/node_modules/sails/node_modules/async/lib/async.js:52:16 at done (/node/ourapp/node_modules/sails/node_modules/async/lib/async.js:246:17) at /node/ourapp/node_modules/sails/node_modules/async/lib/async.js:44:16 at /node/ourapp/plugins/plugin-ourapp-foundation/api/policies/OmniPolicy.js:169:14 at tryCatcher (/node/ourapp/node_modules/waterline/node_modules/bluebird/js/release/util.js:11:23)

ChrisWorks
  • 207
  • 1
  • 4
  • 11
  • Do you get this error when you sails lift, or when sails gets a request (and the policies run)? – arbuthnott Sep 07 '17 at 23:50
  • Also, did you do all the recommended setup? I glanced at the docs and it looks like they have a fair amount of configuration: https://github.com/trailsjs/sails-permissions – arbuthnott Sep 07 '17 at 23:51
  • I followed the setup, which basically states that you need to add the policies to your apps policies.js, but even if I dont they are still applied. My workaround was to create an empty policy file called CriteriaPolicy.js in my policies folder. That way it got used instead of the one from the node_modules. Could not figure out another way :( – ChrisWorks Sep 18 '17 at 16:12

0 Answers0