在节点中禁用不需要的 xss 保护
Disable unwanted xss protection in node
我从来没有安装任何 xss 保护或类似的东西。我意识到我正在使用头盔,但没有头盔也可以保护输出。
在数据库中输入头盔:
"\"<p>\\"<p>sdfsdf<strong>sdfsdf</strong>f</p>\\"<\/p>\""
在没有头盔的情况下输入数据库
"\"<p>fsdfds<strong>fsdfsd<em>fdsfsdfs<\/em><\/strong><\/p>\""
但是网站没有头盔的输出仍然是
"<p>fsdfds<strong>fsdfsd<em>fdsfsdfs</em></strong></p>"
我该怎么做才能显示正确的格式而不是标签?
添加文章控制器
const Article = require("../models/article")
exports.articleAdd = function (req, res) {
var heading = req.body.heading;
var author = req.user.firstname;
var body = req.body.body;
var slug = req.body.slug;
var thumbnail = "/uploads/thumbnails/" + req.body.slug + ".jpg";
// Validation
req.checkBody("heading", "heading is required").notEmpty();
req.checkBody("body", "body is required").notEmpty();
req.checkBody("slug", "slug is not valid").notEmpty();
var errors = req.validationErrors();
if (errors) {
res.render("../core/modules/articles/views/addArticles", {
errors: errors,
layout: 'cmsLayout',
heading: heading,
author: author,
body: body,
slug: slug
});
} else {
let article = new Article({
heading: heading,
author: author,
body: body,
slug: slug,
thumbnail: "/uploads/thumbnails/" + req.body.slug + ".jpg"
});
article.save(function (err) {
if (err) {
console.log(err);
return;
} else {
res.redirect('/');
}
});
}
}
抱歉可能是我的错误,我没有说我正在使用 HANDLEBARS。这实际上是问题。要像 html 一样输出它,我需要使用 {{{something}}}
而不是 {{something}}
我从来没有安装任何 xss 保护或类似的东西。我意识到我正在使用头盔,但没有头盔也可以保护输出。
在数据库中输入头盔:
"\"<p>\\"<p>sdfsdf<strong>sdfsdf</strong>f</p>\\"<\/p>\""
在没有头盔的情况下输入数据库
"\"<p>fsdfds<strong>fsdfsd<em>fdsfsdfs<\/em><\/strong><\/p>\""
但是网站没有头盔的输出仍然是
"<p>fsdfds<strong>fsdfsd<em>fdsfsdfs</em></strong></p>"
我该怎么做才能显示正确的格式而不是标签?
添加文章控制器
const Article = require("../models/article")
exports.articleAdd = function (req, res) {
var heading = req.body.heading;
var author = req.user.firstname;
var body = req.body.body;
var slug = req.body.slug;
var thumbnail = "/uploads/thumbnails/" + req.body.slug + ".jpg";
// Validation
req.checkBody("heading", "heading is required").notEmpty();
req.checkBody("body", "body is required").notEmpty();
req.checkBody("slug", "slug is not valid").notEmpty();
var errors = req.validationErrors();
if (errors) {
res.render("../core/modules/articles/views/addArticles", {
errors: errors,
layout: 'cmsLayout',
heading: heading,
author: author,
body: body,
slug: slug
});
} else {
let article = new Article({
heading: heading,
author: author,
body: body,
slug: slug,
thumbnail: "/uploads/thumbnails/" + req.body.slug + ".jpg"
});
article.save(function (err) {
if (err) {
console.log(err);
return;
} else {
res.redirect('/');
}
});
}
}
抱歉可能是我的错误,我没有说我正在使用 HANDLEBARS。这实际上是问题。要像 html 一样输出它,我需要使用 {{{something}}}
而不是 {{something}}