|
@@ -1,6 +1,7 @@
|
|
|
module.exports = function(crowi) {
|
|
module.exports = function(crowi) {
|
|
|
var debug = require('debug')('crowi:models:revision')
|
|
var debug = require('debug')('crowi:models:revision')
|
|
|
, mongoose = require('mongoose')
|
|
, mongoose = require('mongoose')
|
|
|
|
|
+ , xss = require('xss')
|
|
|
, ObjectId = mongoose.Schema.Types.ObjectId
|
|
, ObjectId = mongoose.Schema.Types.ObjectId
|
|
|
, revisionSchema;
|
|
, revisionSchema;
|
|
|
|
|
|
|
@@ -12,6 +13,21 @@ module.exports = function(crowi) {
|
|
|
createdAt: { type: Date, default: Date.now }
|
|
createdAt: { type: Date, default: Date.now }
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ // create a XSS Filter instance
|
|
|
|
|
+ const myxss = new xss.FilterXSS({
|
|
|
|
|
+ stripIgnoreTag: true,
|
|
|
|
|
+ css: false,
|
|
|
|
|
+ // allow all attributes
|
|
|
|
|
+ onTagAttr: function (tag, name, value, isWhiteAttr) {
|
|
|
|
|
+ return `${name}="${value}"`;
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ // prevent XSS when pre save
|
|
|
|
|
+ revisionSchema.pre('save', function(next) {
|
|
|
|
|
+ this.body = myxss.process(this.body);
|
|
|
|
|
+ next();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
revisionSchema.statics.findLatestRevision = function(path, cb) {
|
|
revisionSchema.statics.findLatestRevision = function(path, cb) {
|
|
|
this.find({path: path})
|
|
this.find({path: path})
|
|
|
.sort({createdAt: -1})
|
|
.sort({createdAt: -1})
|