使用 lusca 扩展内置安全性的 Sails
Extend Sails built in security with lusca
如何扩展内置安全性的 Sails?例如,如何在 Sails 中实现 lusca (module from Kraken)?扩展 Sails 中内置安全性的其他替代方法是什么?
您可以在 http.js
中添加 lusca
和 helmet
等模块并配置顺序。
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
};
@MjZac 给出的上述答案非常有效。我只想根据最新版本的 sails Js 添加文件的更新版本。
var helmet = require('helmet');
module.exports.http = {
cache: 365.25 * 24 * 60 * 60 * 1000,
trustProxy: true,
middleware: {
order: [
'cookieParser',
'session',
'bodyParser',
'compress',
'helmetProtection',
'xss',
'router',
'www',
'favicon'
],
xss: require('lusca').xssProtection('1'),
helmetProtection: function helmetProtection(req, res, next) {
return helmet({
frameguard: false
})(req, res, next);
}
}
};
如何扩展内置安全性的 Sails?例如,如何在 Sails 中实现 lusca (module from Kraken)?扩展 Sails 中内置安全性的其他替代方法是什么?
您可以在 http.js
中添加 lusca
和 helmet
等模块并配置顺序。
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
};
@MjZac 给出的上述答案非常有效。我只想根据最新版本的 sails Js 添加文件的更新版本。
var helmet = require('helmet');
module.exports.http = {
cache: 365.25 * 24 * 60 * 60 * 1000,
trustProxy: true,
middleware: {
order: [
'cookieParser',
'session',
'bodyParser',
'compress',
'helmetProtection',
'xss',
'router',
'www',
'favicon'
],
xss: require('lusca').xssProtection('1'),
helmetProtection: function helmetProtection(req, res, next) {
return helmet({
frameguard: false
})(req, res, next);
}
}
};