Skip to content
This repository was archived by the owner on Dec 25, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions projects/react_blog/blog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"antd": "^3.26.12",
"axios": "^0.19.2",
"babel-plugin-import": "^1.13.0",
"dompurify": "^3.0.6",
"highlight.js": "^9.18.1",
"lodash": "^4.17.15",
"markdown-navbar": "^1.4.1",
Expand Down
6 changes: 5 additions & 1 deletion projects/react_blog/blog/pages/detailed.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'markdown-navbar/dist/navbar.css'
import 'highlight.js/styles/monokai-sublime.css'
import Tocify from '../components/tocify.tsx'
import servicePath from '../config/apiConfig'
import DOMPurify from 'dompurify';

const Detailed = (props) => {
const tocify = new Tocify()
Expand All @@ -35,7 +36,10 @@ const Detailed = (props) => {
smartypants: false,
highlight: code => highlight.highlightAuto(code).value
});
let html = marked(props.content);

const sanitizedContent = DOMPurify.sanitize(props.content);

let html = marked(sanitizedContent);
return (
<>
<Head>
Expand Down
4 changes: 4 additions & 0 deletions projects/react_blog/egg-server/app/controller/admin/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const Controller = require('egg').Controller;
const sanitizeHtml = require('sanitize-html');

class MainController extends Controller {

Expand Down Expand Up @@ -37,6 +38,9 @@ class MainController extends Controller {
// 添加文章
async addArticle() {
const tmpArticle = this.ctx.request.body;
if (tmpArticle.content) {
tmpArticle.content = sanitizeHtml(tmpArticle.content);
}
const result = await this.app.mysql.insert('article', tmpArticle);
const isSuccess = result.affectedRows === 1;
const insertId = result.insertId;
Expand Down
3 changes: 2 additions & 1 deletion projects/react_blog/egg-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"egg": "^2.15.1",
"egg-cors": "^2.2.3",
"egg-mysql": "^3.0.0",
"egg-scripts": "^2.11.0"
"egg-scripts": "^2.11.0",
"sanitize-html": "^2.11.0"
},
"devDependencies": {
"autod": "^3.0.1",
Expand Down