calc: escaping pass 1 — escHtml on user-text render sinks (parity with production; partial, CSP-real is the durable fix)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LmGTn96JVn6xPNNTTW77g1
This commit is contained in:
1 parent
a83370900a
commit
b478d1122c
4 files changed
+25
-12
No files matched your search
+2
-2
@@ -81,7 +81,7 @@ function updateWordBreakdown(impName = breakCipher, impBool = false, chartUpd =
|
|||||||
simplePhr = sVal() // display full phrase
|
simplePhr = sVal() // display full phrase
|
||||||
}
|
}
|
||||||
oStart += '<div id="SimpleBreak">'
|
oStart += '<div id="SimpleBreak">'
|
||||||
oStart += '<span class="breakPhrase">' + simplePhr + '</span><span class="breakPhrase"> = </span><span class="breakSum">' + curCipher.sumArr.reduce(getSum) + ' </span>' // add all values in array
|
oStart += '<span class="breakPhrase">' + escHtml(simplePhr) + '</span><span class="breakPhrase"> = </span><span class="breakSum">' + curCipher.sumArr.reduce(getSum) + ' </span>' // add all values in array
|
||||||
oStart += '<span class="breakCipher"><font style="'+curCiphCol+'"> (' + curCipher.cipherName + gemCalcModeLabel(curCipher) + ')</font></span>'
|
oStart += '<span class="breakCipher"><font style="'+curCiphCol+'"> (' + curCipher.cipherName + gemCalcModeLabel(curCipher) + ')</font></span>'
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,7 +248,7 @@ function updateWordBreakdown(impName = breakCipher, impBool = false, chartUpd =
|
|||||||
var chartClass = 'SimpleBreakChart'
|
var chartClass = 'SimpleBreakChart'
|
||||||
if (curCipher.cp.length > chLimit) chartClass = 'SimpleBreakChartLong'
|
if (curCipher.cp.length > chLimit) chartClass = 'SimpleBreakChartLong'
|
||||||
o = '<tr><td colspan=' + tdCount + '>'
|
o = '<tr><td colspan=' + tdCount + '>'
|
||||||
o += '<div class="'+chartClass+'"><span class="breakPhraseChart">' + simplePhr + ' = ' + curCipher.sumArr.reduce(getSum) + ' </span>' // add all values in array
|
o += '<div class="'+chartClass+'"><span class="breakPhraseChart">' + escHtml(simplePhr) + ' = ' + curCipher.sumArr.reduce(getSum) + ' </span>' // add all values in array
|
||||||
o += '<span class="breakPhraseChartCiphName" style="'+curCiphCol+'">(' + curCipher.cipherName + gemCalcModeLabel(curCipher) + ')</span></div></td></tr>'
|
o += '<span class="breakPhraseChartCiphName" style="'+curCiphCol+'">(' + curCipher.cipherName + gemCalcModeLabel(curCipher) + ')</span></div></td></tr>'
|
||||||
$('#BreakTableContainer').prepend(o) // insert in the beginning of the table
|
$('#BreakTableContainer').prepend(o) // insert in the beginning of the table
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-3
@@ -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, """)
|
||||||
|
.replace(/'/g, "'");
|
||||||
|
}
|
||||||
|
|
||||||
function sVal() {
|
function sVal() {
|
||||||
return document.getElementById("phraseBox").value.trim(); // get value, remove spaces from both sides
|
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
|
// comment first, phrase without comment and leading/trailing spaces
|
||||||
dispPhrase =
|
dispPhrase =
|
||||||
'<span class="pCHT">' +
|
'<span class="pCHT">' +
|
||||||
tmpComment +
|
escHtml(tmpComment) +
|
||||||
"</span>" +
|
"</span>" +
|
||||||
sHistory[x].replace(/\[.+\]/g, "").trim();
|
escHtml(sHistory[x].replace(/\[.+\]/g, "").trim());
|
||||||
} else {
|
} else {
|
||||||
dispPhrase = sHistory[x];
|
dispPhrase = escHtml(sHistory[x]);
|
||||||
}
|
}
|
||||||
ms += '<tr><td class="hP" data-ind="' + x + '">' + dispPhrase + "</td>"; // hP - history phrase, add data index
|
ms += '<tr><td class="hP" data-ind="' + x + '">' + dispPhrase + "</td>"; // hP - history phrase, add data index
|
||||||
var col = ""; // value color
|
var col = ""; // value color
|
||||||
|
|||||||
+4
-4
@@ -249,7 +249,7 @@ function updateDatabaseQueryTable(stPos = 0, dItems, scrollBarEvent = false) { /
|
|||||||
ms += '<div id="queryMinBtn">_</div>'
|
ms += '<div id="queryMinBtn">_</div>'
|
||||||
ms += '</div>'
|
ms += '</div>'
|
||||||
ms += '<input type="range" min="0" max="'+sliderMax+'" value="'+curSliderPos+'" class="qSlider" id="queryScrollbar">' // slider/scrollbar
|
ms += '<input type="range" min="0" max="'+sliderMax+'" value="'+curSliderPos+'" class="qSlider" id="queryScrollbar">' // slider/scrollbar
|
||||||
ms += '<input id="querySearchInput" type="text" spellcheck="false" autocomplete="off" value="'+searchBarValue+'" placeholder="Find...">' // search bar
|
ms += '<input id="querySearchInput" type="text" spellcheck="false" autocomplete="off" value="'+escHtml(searchBarValue)+'" placeholder="Find...">' // search bar
|
||||||
ms += '<table id="QueryTable" class="HistoryTable" data-startpos='+stPos+' data-dispitems='+dItems+'>'
|
ms += '<table id="QueryTable" class="HistoryTable" data-startpos='+stPos+' data-dispitems='+dItems+'>'
|
||||||
ms += '<tbody>'
|
ms += '<tbody>'
|
||||||
} else { // scrollbar used
|
} else { // scrollbar used
|
||||||
@@ -296,12 +296,12 @@ function updateDatabaseQueryTable(stPos = 0, dItems, scrollBarEvent = false) { /
|
|||||||
tmpComment = commentMatch[0]
|
tmpComment = commentMatch[0]
|
||||||
}
|
}
|
||||||
// comment first, phrase without comment and leading/trailing spaces
|
// comment first, phrase without comment and leading/trailing spaces
|
||||||
dispPhrase = (encodingMenuOpened) ? '<span class="pCHT">'+tmpComment+'</span>' + queryResult[x].replace(/\[.+\]/g, '').trim() : '<span class="pCHT">'+tmpComment+'</span>' + queryResult[x][1].replace(/\[.+\]/g, '').trim()
|
dispPhrase = (encodingMenuOpened) ? '<span class="pCHT">'+escHtml(tmpComment)+'</span>' + escHtml(queryResult[x].replace(/\[.+\]/g, '').trim()) : '<span class="pCHT">'+escHtml(tmpComment)+'</span>' + escHtml(queryResult[x][1].replace(/\[.+\]/g, '').trim())
|
||||||
} else {
|
} 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]
|
var fullPhrase = (encodingMenuOpened) ? queryResult[x] : queryResult[x][1]
|
||||||
ms += '<tr><td class="hPQ" data-ind="'+x+'" title="'+fullPhrase.replace(/"/g, '"')+'">' + dispPhrase + '</td>' // phrase at index 1
|
ms += '<tr><td class="hPQ" data-ind="'+x+'" title="'+escHtml(fullPhrase)+'">' + dispPhrase + '</td>' // phrase at index 1 (title + body both escaped)
|
||||||
|
|
||||||
valPos = 2 // reset position for new phrase
|
valPos = 2 // reset position for new phrase
|
||||||
for (y = 0; y < gemArrCiph.length; y++) { // gemArrCiph contains indices of ciphers used for query
|
for (y = 0; y < gemArrCiph.length; y++) { // gemArrCiph contains indices of ciphers used for query
|
||||||
|
|||||||
+3
-3
@@ -16,7 +16,7 @@
|
|||||||
<!-- html2canvas v1.0.0-alpha.12 -->
|
<!-- html2canvas v1.0.0-alpha.12 -->
|
||||||
|
|
||||||
<script src="calc/gematria.js?v=3"></script>
|
<script src="calc/gematria.js?v=3"></script>
|
||||||
<script src="calc/calc.js?v=15"></script>
|
<script src="calc/calc.js?v=16"></script>
|
||||||
<script src="calc/init-variables.js?v=8"></script>
|
<script src="calc/init-variables.js?v=8"></script>
|
||||||
<script src="calc/ciphers.js?v=6"></script>
|
<script src="calc/ciphers.js?v=6"></script>
|
||||||
|
|
||||||
@@ -146,7 +146,7 @@
|
|||||||
|
|
||||||
<span id="loadPanel"></span>
|
<span id="loadPanel"></span>
|
||||||
|
|
||||||
<script src="calc/breakdown.js?v=2"></script>
|
<script src="calc/breakdown.js?v=3"></script>
|
||||||
|
|
||||||
<script src="calc/highlighter.js?v=3"></script>
|
<script src="calc/highlighter.js?v=3"></script>
|
||||||
<script src="calc/export.js?v=3"></script>
|
<script src="calc/export.js?v=3"></script>
|
||||||
@@ -154,7 +154,7 @@
|
|||||||
<script src="calc/num-prop.js?v=2"></script>
|
<script src="calc/num-prop.js?v=2"></script>
|
||||||
<script src="calc/edit-ciphers.js?v=2"></script>
|
<script src="calc/edit-ciphers.js?v=2"></script>
|
||||||
<script src="calc/date-calc.js?v=2"></script>
|
<script src="calc/date-calc.js?v=2"></script>
|
||||||
<script src="calc/database.js?v=7"></script>
|
<script src="calc/database.js?v=8"></script>
|
||||||
<script src="calc/quick-guide.js?v=2"></script>
|
<script src="calc/quick-guide.js?v=2"></script>
|
||||||
|
|
||||||
<script src="calc/localstorage.js?v=3"></script>
|
<script src="calc/localstorage.js?v=3"></script>
|
||||||
|
|||||||
Reference in new issue
Block a user