Skip to content

Commit 82ceace

Browse files
committed
#181 sanitize user input
1 parent 40b756f commit 82ceace

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/views/Media/News/NewsletterSignup.vue

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@
188188

189189
<script>
190190
import axios from 'axios';
191+
import Vue from 'vue';
191192
192193
export default {
193194
name: 'NewsletterSignup',
@@ -235,10 +236,34 @@ export default {
235236
}${/@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.source}`);
236237
return re.test(email);
237238
},
239+
sanitizeUserInput() {
240+
const htmlEntityencodingMap = {
241+
'&': '&amp;',
242+
'<': '&lt',
243+
'>': '&gt;',
244+
'"': '&quot;',
245+
"'": '&#x27;',
246+
};
247+
248+
Object.entries(this.userInfo).forEach((data) => {
249+
const [field, value] = data;
250+
251+
if (value.length > 0) {
252+
let sanitizedvalue = value;
253+
Object.entries(htmlEntityencodingMap).forEach((entry) => {
254+
const [readableChar, codedChar] = entry;
255+
sanitizedvalue = sanitizedvalue.replaceAll(readableChar, codedChar);
256+
});
257+
Vue.set(this.userInfo, field, sanitizedvalue);
258+
}
259+
});
260+
},
238261
subscribe() {
239262
this.submitted = true;
240263
this.subscribed = false;
241264
265+
this.sanitizeUserInput();
266+
242267
const instance = axios.create({
243268
baseURL: this.$store.state.API_BASE,
244269
});

0 commit comments

Comments
 (0)