docker: validate serverAddress
This commit is contained in:
@@ -50,6 +50,7 @@ const apps = require('./apps.js'),
|
||||
shell = require('./shell.js')('docker'),
|
||||
safe = require('safetydance'),
|
||||
timers = require('timers/promises'),
|
||||
tld = require('tldjs'),
|
||||
volumes = require('./volumes.js');
|
||||
|
||||
const DOCKER_SOCKET_PATH = '/var/run/docker.sock';
|
||||
@@ -720,9 +721,24 @@ async function getRegistryConfig() {
|
||||
return value || { provider: 'noop' };
|
||||
}
|
||||
|
||||
function validateServerAddress(serverAddress) {
|
||||
assert.strictEqual(typeof serverAddress, 'string');
|
||||
|
||||
// workaround https://github.com/oncletom/tld.js/issues/73
|
||||
const tmp = serverAddress.replace('_', '-');
|
||||
if (!tld.isValidHostname(tmp)) return new BoxError(BoxError.BAD_FIELD, 'serverAddress is not a valid hostname');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
async function setRegistryConfig(registryConfig) {
|
||||
assert.strictEqual(typeof registryConfig, 'object');
|
||||
|
||||
if (registryConfig.provider !== 'noop') {
|
||||
const error = validateServerAddress(registryConfig.serverAddress);
|
||||
if (error) throw error;
|
||||
}
|
||||
|
||||
const currentConfig = await getRegistryConfig();
|
||||
|
||||
injectPrivateFields(registryConfig, currentConfig);
|
||||
|
||||
Reference in New Issue
Block a user