diff --git a/calc/breakdown.js b/calc/breakdown.js index a8ef12d..d8d9567 100644 --- a/calc/breakdown.js +++ b/calc/breakdown.js @@ -81,7 +81,7 @@ function updateWordBreakdown(impName = breakCipher, impBool = false, chartUpd = simplePhr = sVal() // display full phrase } oStart += '
' - oStart += '' + simplePhr + ' = ' + curCipher.sumArr.reduce(getSum) + ' ' // add all values in array + oStart += '' + escHtml(simplePhr) + ' = ' + curCipher.sumArr.reduce(getSum) + ' ' // add all values in array oStart += ' (' + curCipher.cipherName + gemCalcModeLabel(curCipher) + ')' } @@ -248,7 +248,7 @@ function updateWordBreakdown(impName = breakCipher, impBool = false, chartUpd = var chartClass = 'SimpleBreakChart' if (curCipher.cp.length > chLimit) chartClass = 'SimpleBreakChartLong' o = '' - o += '
' + simplePhr + ' = ' + curCipher.sumArr.reduce(getSum) + ' ' // add all values in array + o += '
' + escHtml(simplePhr) + ' = ' + curCipher.sumArr.reduce(getSum) + ' ' // add all values in array o += '(' + curCipher.cipherName + gemCalcModeLabel(curCipher) + ')
' $('#BreakTableContainer').prepend(o) // insert in the beginning of the table } diff --git a/calc/calc.js b/calc/calc.js index 3b6f5cf..a6d2092 100644 --- a/calc/calc.js +++ b/calc/calc.js @@ -1763,6 +1763,19 @@ function updateEnabledCipherCount() { } } +// Entity-escape user-supplied text before it enters an innerHTML string — for the HTML body AND +// for values inside double-quoted attributes (escapes & < > " '). Store phrases RAW; escape only +// here at render. Added 2026-09-13 (the calc had no escaping; phrases reached the DOM raw). Keep +// every user-text sink routed through this. +function escHtml(s) { + return String(s) + .replace(/&/g, "&") + .replace(//g, ">") + .replace(/"/g, """) + .replace(/'/g, "'"); +} + function sVal() { return document.getElementById("phraseBox").value.trim(); // get value, remove spaces from both sides } @@ -2248,11 +2261,11 @@ function updateHistoryTable(hltBoolArr) { // comment first, phrase without comment and leading/trailing spaces dispPhrase = '' + - tmpComment + + escHtml(tmpComment) + "" + - sHistory[x].replace(/\[.+\]/g, "").trim(); + escHtml(sHistory[x].replace(/\[.+\]/g, "").trim()); } else { - dispPhrase = sHistory[x]; + dispPhrase = escHtml(sHistory[x]); } ms += '' + dispPhrase + ""; // hP - history phrase, add data index var col = ""; // value color diff --git a/calc/database.js b/calc/database.js index 8c6d058..ae626f6 100644 --- a/calc/database.js +++ b/calc/database.js @@ -249,7 +249,7 @@ function updateDatabaseQueryTable(stPos = 0, dItems, scrollBarEvent = false) { / ms += '
_
' ms += '
' ms += '' // slider/scrollbar - ms += '' // search bar + ms += '' // search bar ms += '' ms += '' } else { // scrollbar used @@ -296,12 +296,12 @@ function updateDatabaseQueryTable(stPos = 0, dItems, scrollBarEvent = false) { / tmpComment = commentMatch[0] } // comment first, phrase without comment and leading/trailing spaces - dispPhrase = (encodingMenuOpened) ? ''+tmpComment+'' + queryResult[x].replace(/\[.+\]/g, '').trim() : ''+tmpComment+'' + queryResult[x][1].replace(/\[.+\]/g, '').trim() + dispPhrase = (encodingMenuOpened) ? ''+escHtml(tmpComment)+'' + escHtml(queryResult[x].replace(/\[.+\]/g, '').trim()) : ''+escHtml(tmpComment)+'' + escHtml(queryResult[x][1].replace(/\[.+\]/g, '').trim()) } else { - dispPhrase = (encodingMenuOpened) ? queryResult[x] : queryResult[x][1] + dispPhrase = (encodingMenuOpened) ? escHtml(queryResult[x]) : escHtml(queryResult[x][1]) } var fullPhrase = (encodingMenuOpened) ? queryResult[x] : queryResult[x][1] - ms += '' // phrase at index 1 + ms += '' // phrase at index 1 (title + body both escaped) valPos = 2 // reset position for new phrase for (y = 0; y < gemArrCiph.length; y++) { // gemArrCiph contains indices of ciphers used for query diff --git a/index.html b/index.html index ef2fb2a..8c15168 100644 --- a/index.html +++ b/index.html @@ -16,7 +16,7 @@ - + @@ -146,7 +146,7 @@ - + @@ -154,7 +154,7 @@ - +
' + dispPhrase + '
' + dispPhrase + '