fix: keep Alta bearer out of proxy command lines

This commit is contained in:
2026-08-19 22:26:47 +00:00
parent 582fc46914
commit 808698dc46
15 changed files with 207 additions and 101 deletions
+15 -16
View File
@@ -5,7 +5,7 @@ const nodePath = require('node:path');
const { spawn: nodeSpawn } = require('node:child_process');
const HELPER_FILENAME = 'aware-cam-proxy.exe';
const MAX_COOKIE_LENGTH = 4096;
const MAX_USERNAME_LENGTH = 254;
const MAX_HOST_LENGTH = 253;
const DEVICE_ID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
const DNS_LABEL_PATTERN = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
@@ -41,20 +41,19 @@ function validateDeviceId(value) {
return value.toLowerCase();
}
function validateCookie(value) {
if (typeof value !== 'string' || value.length === 0 || value.length > MAX_COOKIE_LENGTH) {
throw new ProxyLaunchError('Cookie is invalid.', 'INVALID_COOKIE');
function validateUsername(value) {
if (typeof value !== 'string' || value.length === 0 || value.length > MAX_USERNAME_LENGTH || value.trim().length === 0) {
throw new ProxyLaunchError('Alta username is invalid.', 'INVALID_USERNAME');
}
if (/[\u0000-\u001f\u007f]/.test(value)) {
throw new ProxyLaunchError('Cookie must not contain control characters.', 'INVALID_COOKIE');
if (/[\u0000-\u001f\u007f-\u009f]/.test(value)) {
throw new ProxyLaunchError('Alta username must not contain control characters.', 'INVALID_USERNAME');
}
return value;
}
function redactMessage(error, secret) {
function safeProcessError(error) {
const source = error && typeof error.message === 'string' ? error.message : 'Unknown process error';
const withoutSecret = secret ? source.split(secret).join('[REDACTED]') : source;
return withoutSecret.replace(/[\u0000-\u001f\u007f]/g, ' ').slice(0, 512);
return source.replace(/[\u0000-\u001f\u007f-\u009f]/g, ' ').slice(0, 512);
}
function safeMetadata(entry, status = entry.status) {
@@ -98,7 +97,7 @@ function createProxyManager({
const deploymentHost = validateDeploymentHost(request.deploymentHost);
const deviceId = validateDeviceId(request.deviceId);
const cookie = validateCookie(request.cookie);
const username = validateUsername(request.username);
if (!fs.existsSync(helperPath)) {
throw new ProxyLaunchError('Proxy helper was not found in the approved application directory.', 'HELPER_NOT_FOUND');
@@ -108,17 +107,17 @@ function createProxyManager({
try {
child = spawn(
helperPath,
['-a', deploymentHost, '-d', deviceId, '-k', cookie],
['-a', deploymentHost, '-u', username, '-d', deviceId],
{
shell: false,
detached: false,
detached: true,
stdio: 'ignore',
windowsHide: false
}
);
} catch (error) {
throw new ProxyLaunchError(
`Failed to launch proxy helper: ${redactMessage(error, cookie)}`,
`Failed to launch proxy helper: ${safeProcessError(error)}`,
'SPAWN_FAILED'
);
}
@@ -202,10 +201,10 @@ function createProxyManager({
module.exports = {
HELPER_FILENAME,
MAX_COOKIE_LENGTH,
MAX_USERNAME_LENGTH,
ProxyLaunchError,
createProxyManager,
validateCookie,
validateDeploymentHost,
validateDeviceId
validateDeviceId,
validateUsername
};