Files
BetterDesk/web-nodejs/lib/safeSqlIdent.js
UNITRONIX 235c9c0706 security: implement Phase 0-3 remediation (deps, SQL ident, JWT, CSP, suite)
Bump axios/multer and npm overrides; add safeSqlIdent and multer cleanup;
harden JWT aud/iss/nbf; CSP without unsafe-eval via static protobuf build
and data-bd-call delegation; ship Security Test Suite v1.2.0 and docs.
Ignore generated RdClient protobuf artifacts (~40k lines) — rebuild locally
with npm run protocols:rdclient.

Thanks: INSOLVE (Honorary); Marco Jakobs (@jacotec); MyNameisStitch (@MyNameisStitch); Redspin (@playerumpknow); muopc (@muopc)
2026-10-17 15:33:48 +02:00

31 lines
739 B
JavaScript

'use strict';
/** Unquoted SQL identifier: letters, digits, underscore; must not start with a digit. */
const SAFE_SQL_IDENT_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
/**
* @param {unknown} name
* @returns {string} validated identifier
* @throws {Error} when name is not a safe SQL identifier
*/
function assertSafeSqlIdent(name) {
if (typeof name !== 'string' || !SAFE_SQL_IDENT_RE.test(name)) {
throw new Error(`Unsafe SQL identifier: ${String(name)}`);
}
return name;
}
/**
* @param {unknown} name
* @returns {boolean}
*/
function isSafeSqlIdent(name) {
return typeof name === 'string' && SAFE_SQL_IDENT_RE.test(name);
}
module.exports = {
SAFE_SQL_IDENT_RE,
assertSafeSqlIdent,
isSafeSqlIdent,
};