Fix CodeQL code-scanning alerts
- Values pasted into eval'd or inline-script code go through lit() (scripts/lib/js-literal.js), which escapes <, >, /, U+2028 and U+2029 after JSON.stringify - build test and i18n-check read script tags with a DOM parser or a plain search, not HTML regexes - mcp.js parses the Authorization header without a backtracking regex
This commit is contained in:
parent
e7729d0a1e
commit
dd6e4f4f8a
89 changed files with 316 additions and 213 deletions
5
scripts/lib/js-literal.js
Normal file
5
scripts/lib/js-literal.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
// A value as a JavaScript literal, safe to paste into code that is eval'd or into an inline <script>: JSON, with the
|
||||
// characters that could end a script tag or break a string (<, >, /, U+2028, U+2029) written as \u escapes.
|
||||
const ESC = /[<>\/\u2028\u2029]/g;
|
||||
const lit = (v) => { const s = JSON.stringify(v); return s === undefined ? 'undefined' : s.replace(ESC, (c) => '\\u' + c.charCodeAt(0).toString(16).padStart(4, '0')); };
|
||||
module.exports = { lit };
|
||||
Loading…
Add table
Add a link
Reference in a new issue