diff --git a/lib/SanitizeString/index.js b/lib/SanitizeString/index.js new file mode 100644 index 0000000..3d0b7ee --- /dev/null +++ b/lib/SanitizeString/index.js @@ -0,0 +1,5 @@ +export default function SanitizeString(str, punctuation = false, space = false, replace = false) +{ + const r = new RegExp(`[^\\d${ space ? `\\s` : `` }\\.\\-@${ punctuation ? `"'=+,;«»()&!?%` : ``}\\p{A-z}\u0401\u0451\u0410-\u044f]`, 'gi'); + return str.replace(r, replace ? ' ' : ''); +} \ No newline at end of file diff --git a/pages/api/auth/switch.js b/pages/api/auth/switch.js index 2d11bc0..4fa6205 100644 --- a/pages/api/auth/switch.js +++ b/pages/api/auth/switch.js @@ -6,11 +6,12 @@ import moment from 'moment'; import jwt from 'jsonwebtoken'; import { cors } from '../../../lib/cors'; +import SanitizeString from '../../../lib/SanitizeString'; export default async function handler(req, res) { await cors(req, res); - let { acc_number } = req.body; + let acc_number = SanitizeString(req.body.acc_number, false, false, true); console.log("API", "auth/switch"); if(req.headers.cookie !== undefined)