Skip to content
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
12 changes: 7 additions & 5 deletions src/Middlewares/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ export const JwtPhoneValidation: RequestHandler = async (req, res, next) => {

//XSS 공격 대비 body에 check

export function scriptFilter(body:any){
const filterBody:any = {}
for(let key in body){
filterBody[key] = sanitizeHtml(body[key])
export function scriptFilter(body: any) {
const filterBody: any = { ...body };
for (let key in body) {
if (typeof body[key] === "string") {
filterBody[key] = sanitizeHtml(body[key]);
}
}
return filterBody
return filterBody;
}
23 changes: 23 additions & 0 deletions src/Middlewares/wordfilter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import express, { RequestHandler } from "express";

const badWords = ["바보", "멍청이"]

const wordFilter: RequestHandler = async (req, res, next) => {
const body = req.body
try {
for (let key in body) {
for (let j = 0; j < badWords.length; j++) {
if (body[key].length >= badWords[j].length) {
if (body[key].indexOf(badWords[j]) !== -1) {
body[key] = body[key].replace(badWords[j], "**")
}
}
}
}
next()
} catch (err) {
next(new Error("비속어 필터 중 문제가 생겼습니다."))
}
};

export default wordFilter
4 changes: 3 additions & 1 deletion src/routers/Post/postController.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import express, { RequestHandler } from "express";
import Controller from "../interfaces/controller";
import { Post, PostDto, ParticipantDto } from "../../models/Post";
import { validation, JwtValidation,scriptFilter } from "../../middlewares/validation";
import { validation, JwtValidation, scriptFilter } from "../../middlewares/validation";
import wordFilter from "../../middlewares/wordfilter";
import PostService from "./postService";
import MapService from "./mapService";
import { Types } from "mongoose";
Expand All @@ -23,6 +24,7 @@ export default class PostController implements Controller {
this.router.post(
this.path,
JwtValidation,
wordFilter,
validation(PostDto, true),
this.createPost
);
Expand Down