Files
BetterDesk/web-nodejs/lib/stripUntilStable.js
T
UNITRONIX c2e0e2e784 fix(security): harden CodeQL findings across console and Go server
Address GitHub code scanning alerts with OIDC SSRF guards, confined path
helpers, safer client routing, branding sanitization, upload rate limits,
and CodeQL config exclusions for dev-only and protocol-intentional hashes.
2026-06-11 06:57:58 +02:00

39 lines
1.1 KiB
JavaScript

'use strict';
/**
* Strip dangerous substrings until a full pass produces no change.
* @param {string} input
* @param {Array<(s: string) => string>} replacers
* @returns {string}
*/
function stripUntilStable(input, replacers) {
let result = String(input ?? '');
let prev;
do {
prev = result;
for (const replacer of replacers) {
result = replacer(result);
}
} while (result !== prev);
return result;
}
/**
* Remove opening/closing HTML/SVG tags for a given tag name (case-insensitive).
* @param {string} input
* @param {string} tagName
* @returns {string}
*/
function stripTagName(input, tagName) {
const name = String(tagName).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const open = new RegExp(`<\\s*${name}\\b[^>]*>`, 'gi');
const close = new RegExp(`<\\s*/\\s*${name}\\b[^>]*>`, 'gi');
const selfClose = new RegExp(`<\\s*${name}\\b[^>]*/\\s*>`, 'gi');
return input.replace(open, '').replace(close, '').replace(selfClose, '');
}
module.exports = {
stripUntilStable,
stripTagName,
};