implemented sanitizing
This commit is contained in:
parent
57d5fcceb4
commit
fecd26f4bb
@ -1,6 +1,6 @@
|
|||||||
import {setNewTemplate, loadTemplate} from "./web.js";
|
import {setNewTemplate, loadTemplate} from "./web.js";
|
||||||
import { retrieveData } from "./storage.js";
|
|
||||||
import { hideMenus, modalNotifier } from "./evts.js";
|
import { hideMenus, modalNotifier } from "./evts.js";
|
||||||
|
import { sanitize } from "./scripts.js";
|
||||||
|
|
||||||
function createTemplate(template = false) {
|
function createTemplate(template = false) {
|
||||||
|
|
||||||
@ -8,7 +8,6 @@ function createTemplate(template = false) {
|
|||||||
//set current page value in activeState object
|
//set current page value in activeState object
|
||||||
activeState.activePage = "createTemplate";
|
activeState.activePage = "createTemplate";
|
||||||
|
|
||||||
|
|
||||||
if (screen.width > 992) {
|
if (screen.width > 992) {
|
||||||
document.getElementById("siteTitle").innerHTML = "Manage templates";
|
document.getElementById("siteTitle").innerHTML = "Manage templates";
|
||||||
} else {
|
} else {
|
||||||
@ -145,7 +144,7 @@ function createTemplate(template = false) {
|
|||||||
case "Save":
|
case "Save":
|
||||||
let fileName;
|
let fileName;
|
||||||
let userFileNameField = document.getElementById("userFileName");
|
let userFileNameField = document.getElementById("userFileName");
|
||||||
let userFileName = userFileNameField.value;
|
let userFileName = sanitize(userFileNameField.value);
|
||||||
let userFileNamePH = userFileNameField.getAttribute("placeholder");
|
let userFileNamePH = userFileNameField.getAttribute("placeholder");
|
||||||
if (userFileName.length != 0) {
|
if (userFileName.length != 0) {
|
||||||
fileName = userFileName;
|
fileName = userFileName;
|
||||||
|
|||||||
@ -251,11 +251,8 @@ function formEvts() {
|
|||||||
document.getElementById("sidebar").addEventListener("click", (e) => {
|
document.getElementById("sidebar").addEventListener("click", (e) => {
|
||||||
if (e.target) {
|
if (e.target) {
|
||||||
if (e.target.id == "sb-submit") {
|
if (e.target.id == "sb-submit") {
|
||||||
if (screen.width < 993) {
|
|
||||||
showSidebar();
|
|
||||||
}
|
|
||||||
parseFormOnSubmit();
|
parseFormOnSubmit();
|
||||||
focusOnField("output");
|
modalNotifier("File saved and copied to clipboard", 2);
|
||||||
}
|
}
|
||||||
if (e.target.id == "sb-item") {
|
if (e.target.id == "sb-item") {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import { sanitize } from "./scripts.js";
|
||||||
import { storeData, clearData, retrieveData } from "./storage.js";
|
import { storeData, clearData, retrieveData } from "./storage.js";
|
||||||
|
|
||||||
function parseFormOnSubmit(returnJSON = false, parseOnly = false) {
|
function parseFormOnSubmit(returnJSON = false, parseOnly = false) {
|
||||||
@ -43,7 +44,7 @@ function parseFormOnSubmit(returnJSON = false, parseOnly = false) {
|
|||||||
|
|
||||||
//set filename to active state according to userFileName field from loadTemplate
|
//set filename to active state according to userFileName field from loadTemplate
|
||||||
let userFileNameField = document.getElementById("userFileName");
|
let userFileNameField = document.getElementById("userFileName");
|
||||||
let userFileName = userFileNameField.value;
|
let userFileName = sanitize(userFileNameField.value);
|
||||||
let userFileNamePH = userFileNameField.getAttribute("placeholder");
|
let userFileNamePH = userFileNameField.getAttribute("placeholder");
|
||||||
if (userFileName.length != 0) {
|
if (userFileName.length != 0) {
|
||||||
activeState.fileName = userFileName;
|
activeState.fileName = userFileName;
|
||||||
|
|||||||
@ -47,7 +47,7 @@ export const passwordHash = {
|
|||||||
|
|
||||||
function setPassword() {
|
function setPassword() {
|
||||||
let x = document.getElementById("loginForm");
|
let x = document.getElementById("loginForm");
|
||||||
let pw = x.elements[0].value;
|
let pw = sanitize(x.elements[0].value);
|
||||||
|
|
||||||
if (pw != "" || pw !== "undefined") {
|
if (pw != "" || pw !== "undefined") {
|
||||||
let pwOld = pw;
|
let pwOld = pw;
|
||||||
@ -164,4 +164,22 @@ export function logout() {
|
|||||||
document.getElementById("login").style.display = "block";
|
document.getElementById("login").style.display = "block";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export function sanitize(string) {
|
||||||
|
const map = {
|
||||||
|
'&': '_',
|
||||||
|
'<': '_',
|
||||||
|
'>': '_',
|
||||||
|
'"': '_',
|
||||||
|
"'": '_',
|
||||||
|
'/': '_',
|
||||||
|
'`': '_',
|
||||||
|
'=': '_'
|
||||||
|
};
|
||||||
|
const reg = /[&<>"'/]/ig;
|
||||||
|
console.log(string.replace(reg, (match)=>(map[match])));
|
||||||
|
return string.replace(reg, (match)=>(map[match]));
|
||||||
|
}
|
||||||
|
|
||||||
export default setPassword;
|
export default setPassword;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import XORCipher from "./xorc.js";
|
import XORCipher from "./xorc.js";
|
||||||
import sha256 from "./sha256.min.js";
|
import sha256 from "./sha256.min.js";
|
||||||
import { getUsrId, passwordHash } from "./scripts.js";
|
import { getUsrId, passwordHash, sanitize } from "./scripts.js";
|
||||||
|
|
||||||
|
|
||||||
function createStorageObj() {
|
function createStorageObj() {
|
||||||
@ -19,10 +19,10 @@ function createStorageObj() {
|
|||||||
//console.log(this, dataArray);
|
//console.log(this, dataArray);
|
||||||
|
|
||||||
let userFileNameField = document.getElementById("userFileName");
|
let userFileNameField = document.getElementById("userFileName");
|
||||||
let userFileName = userFileNameField.value;
|
let userFileName = sanitize(userFileNameField.value);
|
||||||
let userFileNamePH = userFileNameField.getAttribute("placeholder");
|
let userFileNamePH = userFileNameField.getAttribute("placeholder");
|
||||||
if (userFileName.length != 0) {
|
if (userFileName.length != 0) {
|
||||||
activeState.fileName = userFileName.replace;
|
activeState.fileName = userFileName;
|
||||||
//clear old data as file switches to new filename
|
//clear old data as file switches to new filename
|
||||||
if (userFileNamePH.length != 0) {
|
if (userFileNamePH.length != 0) {
|
||||||
clearData(userFileNamePH);
|
clearData(userFileNamePH);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user