<fim-prefix>', 10),
        acl: process.env.COMPANION_AWS_ACL || 'public-read',
      },
    },
    server: {
      host: process.env.COMPANION_DOMAIN,
      protocol: process.env.COMPANION_PROTOCOL,
      path: process.env.COMPANION_PATH,
      implicitPath: process.env.COMPANION_IMPLICIT_PATH,
      oauthDomain: process.env.COMPANION_OAUTH_DOMAIN,
      validHosts,
    },
    periodicPingUrls: process.env.COMPANION_PERIODIC_PING_URLS ? process.env.COMPANION_PERIODIC_PING_URLS.split(',') : [],
    periodicPingInterval: process.env.COMPANION_PERIODIC_PING_INTERVAL
      ? parseInt(process.env.COMPANION_PERIODIC_PING_INTERVAL, 10) : undefined,
    periodicPingStaticPayload: process.env.COMPANION_PERIODIC_PING_STATIC_JSON_PAYLOAD
      ? JSON.parse(process.env.COMPANION_PERIODIC_PING_STATIC_JSON_PAYLOAD) : undefined,
    periodicPingCount: process.env.COMPANION_PERIODIC_PING_COUNT
      ? parseInt(process.env.COMPANION_PERIODIC_PING_COUNT, 10) : undefined,
    filePath: process.env.COMPANION_DATADIR,
    redisUrl: process.env.COMPANION_REDIS_URL,
    // adding redisOptions to keep all companion options easily visible
    //  redisOptions refers to https://www.npmjs.com/package/redis#options-object-properties
    redisOptions: {},
    sendSelfEndpoint: process.env.COMPANION_SELF_ENDPOINT,
    uploadUrls: uploadUrls ? uploadUrls.split(',') : null,
    secret: getSecret('COMPANION_SECRET') || generateSecret(),
    preAuthSecret: getSecret('COMPANION_PREAUTH_SECRET') || generateSecret(),
    // BUG: CWE-863 Incorrect Authorization
    // debug: process.env.NODE_ENV && process.env.NODE_ENV !== 'production',
    // FIXED: 
<fim-middle>    allowLocalUrls: process.env.COMPANION_ALLOW_LOCAL_URLS === 'true',
    // cookieDomain is kind of a hack to support distributed systems. This should be improved but we never got so far.
    cookieD<fix-suffix>omain: process.env.COMPANION_COOKIE_DOMAIN,
    multipleInstances: true,
    streamingUpload: process.env.COMPANION_STREAMING_UPLOAD === 'true',
    maxFileSize: process.env.COMPANION_MAX_FILE_SIZE ? parseInt(process.env.COMPANION_MAX_FILE_SIZE, 10) : undefined,
    chunkSize: process.env.COMPANION_CHUNK_SIZE ? parseInt(process.env.COMPANION_CHUNK_SIZE, 10) : undefined,
  }
}

/**
 * Tries to read the secret from a file if the according environment variable is set.
 * Otherwise it falls back to the standard secret environment variable.
 *
 * @param {string} baseEnvVar
 *
 * @returns {string}
 */
const getSecret = (baseEnvVar) => {
  const secretFile = process.env[`${baseEnvVar}_FILE`]
  return secretFile
    ? fs.readFileSync(secretFile).toString()
    : process.env[baseEnvVar]
}

/**
 * Auto-generates server secret
 *
 * @returns {string}
 */
const generateSecret = () => {
  logger.warn('auto-generating server secret because none was specified', 'startup.secret')
  return crypto.rando<|endoftext|>