fix: keep Alta bearer out of proxy command lines
This commit is contained in:
@@ -10,7 +10,7 @@ const {
|
||||
readJsonBody,
|
||||
} = require('./bridge-auth');
|
||||
const { RELEASES_PAGE_URL } = require('./update-policy');
|
||||
const { validateDeviceId } = require('./proxy-launch');
|
||||
const { validateDeviceId, validateUsername } = require('./proxy-launch');
|
||||
|
||||
const PAIRING_ENVELOPE_FILENAME = 'bridge-pairing.json';
|
||||
|
||||
@@ -19,7 +19,7 @@ function safeErrorMessage(error, fallback) {
|
||||
'NO_ALTA_SESSION', 'INVALID_ALTA_ARGUMENTS', 'ALTA_TIMEOUT', 'ALTA_HTTP_ERROR',
|
||||
'INVALID_ALTA_RESPONSE', 'INVALID_ALTA_RESPONSE_DATA', 'ALTA_RESPONSE_TOO_LARGE',
|
||||
'UNSAFE_ALTA_REDIRECT', 'TOO_MANY_ALTA_REDIRECTS', 'HELPER_NOT_FOUND',
|
||||
'UNSUPPORTED_PLATFORM', 'INVALID_DEVICE_ID', 'SPAWN_FAILED',
|
||||
'UNSUPPORTED_PLATFORM', 'INVALID_DEVICE_ID', 'INVALID_USERNAME', 'SPAWN_FAILED',
|
||||
]);
|
||||
return error && allowed.has(error.code) && typeof error.message === 'string'
|
||||
? error.message
|
||||
@@ -253,9 +253,10 @@ class AppRuntime {
|
||||
}
|
||||
}
|
||||
|
||||
async launchProxy(deviceId) {
|
||||
async launchProxy(deviceId, username) {
|
||||
try {
|
||||
const validatedId = validateDeviceId(deviceId);
|
||||
const validatedUsername = validateUsername(username);
|
||||
this._reconcileProxies();
|
||||
if (!this.allowedDeviceIds.has(validatedId)) {
|
||||
return { success: false, message: 'Select a device from the current Alta device list.' };
|
||||
@@ -266,7 +267,7 @@ class AppRuntime {
|
||||
const session = this.sessionStore.requireSession();
|
||||
const result = this.proxyManager.launchProxy({
|
||||
deploymentHost: new URL(session.origin).hostname,
|
||||
cookie: session.cookie,
|
||||
username: validatedUsername,
|
||||
deviceId: validatedId,
|
||||
});
|
||||
this.proxyByDevice.set(validatedId, result.processId);
|
||||
|
||||
+15
-16
@@ -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
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user