mirror of
https://github.com/UNITRONIX/BetterDesk.git
synced 2026-09-10 17:45:42 +00:00
6d7692ea6a
Stop logging generated admin passwords, redact API login usernames, confine font and file-transfer temp paths with safePath, and scope GitHub Actions permissions in build.yml.
32 lines
737 B
JavaScript
32 lines
737 B
JavaScript
'use strict';
|
|
|
|
/**
|
|
* Redact credentials and URL userinfo before writing to logs.
|
|
*/
|
|
|
|
function redactUrlForLog(rawUrl) {
|
|
const value = String(rawUrl || '').trim();
|
|
if (!value) return '';
|
|
|
|
try {
|
|
const parsed = new URL(value);
|
|
parsed.username = '';
|
|
parsed.password = '';
|
|
return parsed.toString();
|
|
} catch (_) {
|
|
return value.replace(/\/\/[^/@]+@/, '//***@');
|
|
}
|
|
}
|
|
|
|
function redactUsernameForLog(username) {
|
|
const value = typeof username === 'string' ? username.trim() : '';
|
|
if (!value) return '(empty)';
|
|
if (value.length <= 2) return '***';
|
|
return `${value[0]}***${value[value.length - 1]}`;
|
|
}
|
|
|
|
module.exports = {
|
|
redactUrlForLog,
|
|
redactUsernameForLog,
|
|
};
|