使用 lusca 扩展内置安全性的 Sails

Cir*_*uze 2 security sails.js kraken.js

如何扩展内置安全性的 Sails?例如,我如何在 Sails 中实现lusca(来自Kraken 的模块)?在 Sails 中扩展内置安全性的其他替代方法是什么?

MjZ*_*Zac 5

你可以像添加模块lusca,并helmethttp.js和配置的顺序。

var lusca = require('lusca');
var helmet = require('helmet');
module.exports.http = {

  middleware: {
    order: [
      'startRequestTimer',
      'cookieParser',
      'session',
      'bodyParser',
      'handleBodyParserError',
      'compress',
      'methodOverride',
      '$custom',
      'helmetProtection',
      'xframe',
      'router',
      'www',
      'favicon',
      '404',
      '500'
    ],

    xframe: function xframe(req, res, next) {
      return lusca.xframe('SAMEORIGIN')(req, res, next);
    },

    helmetProtection: function helmetProtection(req, res, next) {
      return helmet({
        frameguard: false
      })(req, res, next);
    }
  },
  cache: 1 * 60 * 60
};
Run Code Online (Sandbox Code Playgroud)