Make allowedEndpoints a read-only array

This commit is contained in:
artrejo 2022-01-24 11:08:37 -08:00
parent 54cd7a32d8
commit dc543b5ae3
4 changed files with 20 additions and 68 deletions

View File

@ -339,10 +339,7 @@ export function createMongoCollectionWithProxy(
export function getFeatureEndpointOrDefault(feature: string): string { export function getFeatureEndpointOrDefault(feature: string): string {
const endpoint = const endpoint =
hasFlag(userContext.features.mongoProxyAPIs, feature) && hasFlag(userContext.features.mongoProxyAPIs, feature) &&
validateEndpoint( validateEndpoint(userContext.features.mongoProxyEndpoint, allowedMongoProxyEndpoints)
userContext.features.mongoProxyEndpoint,
allowedMongoProxyEndpoints.map((endpoint) => endpoint)
)
? userContext.features.mongoProxyEndpoint ? userContext.features.mongoProxyEndpoint
: configContext.MONGO_BACKEND_ENDPOINT || configContext.BACKEND_ENDPOINT; : configContext.MONGO_BACKEND_ENDPOINT || configContext.BACKEND_ENDPOINT;

View File

@ -95,66 +95,31 @@ export function updateConfigContext(newContext: Partial<ConfigContext>): void {
return; return;
} }
if ( if (!validateEndpoint(newContext.ARM_ENDPOINT, allowedArmEndpoints)) {
!validateEndpoint(
newContext.ARM_ENDPOINT,
allowedArmEndpoints.map((endpoint) => endpoint)
)
) {
delete newContext.ARM_ENDPOINT; delete newContext.ARM_ENDPOINT;
} }
if ( if (!validateEndpoint(newContext.AAD_ENDPOINT, allowedAadEndpoints)) {
!validateEndpoint(
newContext.AAD_ENDPOINT,
allowedAadEndpoints.map((endpoint) => endpoint)
)
) {
delete newContext.AAD_ENDPOINT; delete newContext.AAD_ENDPOINT;
} }
if ( if (!validateEndpoint(newContext.EMULATOR_ENDPOINT, allowedEmulatorEndpoints)) {
!validateEndpoint(
newContext.EMULATOR_ENDPOINT,
allowedEmulatorEndpoints.map((endpoint) => endpoint)
)
) {
delete newContext.EMULATOR_ENDPOINT; delete newContext.EMULATOR_ENDPOINT;
} }
if ( if (!validateEndpoint(newContext.GRAPH_ENDPOINT, allowedGraphEndpoints)) {
!validateEndpoint(
newContext.GRAPH_ENDPOINT,
allowedGraphEndpoints.map((endpoint) => endpoint)
)
) {
delete newContext.GRAPH_ENDPOINT; delete newContext.GRAPH_ENDPOINT;
} }
if ( if (!validateEndpoint(newContext.ARCADIA_ENDPOINT, allowedArcadiaEndpoints)) {
!validateEndpoint(
newContext.ARCADIA_ENDPOINT,
allowedArcadiaEndpoints.map((endpoint) => endpoint)
)
) {
delete newContext.ARCADIA_ENDPOINT; delete newContext.ARCADIA_ENDPOINT;
} }
if ( if (!validateEndpoint(newContext.BACKEND_ENDPOINT, allowedBackendEndpoints)) {
!validateEndpoint(
newContext.BACKEND_ENDPOINT,
allowedBackendEndpoints.map((endpoint) => endpoint)
)
) {
delete newContext.BACKEND_ENDPOINT; delete newContext.BACKEND_ENDPOINT;
} }
if ( if (!validateEndpoint(newContext.MONGO_BACKEND_ENDPOINT, allowedMongoBackendEndpoints)) {
!validateEndpoint(
newContext.MONGO_BACKEND_ENDPOINT,
allowedMongoBackendEndpoints.map((endpoint) => endpoint)
)
) {
delete newContext.MONGO_BACKEND_ENDPOINT; delete newContext.MONGO_BACKEND_ENDPOINT;
} }
@ -162,21 +127,11 @@ export function updateConfigContext(newContext: Partial<ConfigContext>): void {
delete newContext.JUNO_ENDPOINT; delete newContext.JUNO_ENDPOINT;
} }
if ( if (!validateEndpoint(newContext.hostedExplorerURL, allowedHostedExplorerEndpoints)) {
!validateEndpoint(
newContext.hostedExplorerURL,
allowedHostedExplorerEndpoints.map((endpoint) => endpoint)
)
) {
delete newContext.hostedExplorerURL; delete newContext.hostedExplorerURL;
} }
if ( if (!validateEndpoint(newContext.msalRedirectURI, allowedMsalRedirectEndpoints)) {
!validateEndpoint(
newContext.msalRedirectURI,
allowedMsalRedirectEndpoints.map((endpoint) => endpoint)
)
) {
delete newContext.msalRedirectURI; delete newContext.msalRedirectURI;
} }

View File

@ -181,10 +181,7 @@ export default class Explorer {
// Override notebook server parameters from URL parameters // Override notebook server parameters from URL parameters
if ( if (
userContext.features.notebookServerUrl && userContext.features.notebookServerUrl &&
validateEndpoint( validateEndpoint(userContext.features.notebookServerUrl, allowedNotebookServerUrls) &&
userContext.features.notebookServerUrl,
allowedNotebookServerUrls.map((endpoint) => endpoint)
) &&
userContext.features.notebookServerToken userContext.features.notebookServerToken
) { ) {
useNotebook.getState().setNotebookServerInfo({ useNotebook.getState().setNotebookServerInfo({
@ -418,10 +415,7 @@ export default class Explorer {
useNotebook.getState().setConnectionInfo(connectionStatus); useNotebook.getState().setConnectionInfo(connectionStatus);
useNotebook.getState().setNotebookServerInfo({ useNotebook.getState().setNotebookServerInfo({
notebookServerEndpoint: notebookServerEndpoint:
(validateEndpoint( (validateEndpoint(userContext.features.notebookServerUrl, allowedNotebookServerUrls) &&
userContext.features.notebookServerUrl,
allowedNotebookServerUrls.map((endpoint) => endpoint)
) &&
userContext.features.notebookServerUrl) || userContext.features.notebookServerUrl) ||
connectionInfo.data.notebookServerUrl, connectionInfo.data.notebookServerUrl,
authToken: userContext.features.notebookServerToken || connectionInfo.data.notebookAuthToken, authToken: userContext.features.notebookServerToken || connectionInfo.data.notebookAuthToken,

View File

@ -1,8 +1,14 @@
import * as Logger from "../Common/Logger"; import * as Logger from "../Common/Logger";
export function validateEndpoint(endpointToValidate: string | undefined, allowedEndpoints: string[]): boolean { export function validateEndpoint(
endpointToValidate: string | undefined,
allowedEndpoints: ReadonlyArray<string>
): boolean {
try { try {
return validateEndpointInternal(endpointToValidate, allowedEndpoints); return validateEndpointInternal(
endpointToValidate,
allowedEndpoints.map((e) => e)
);
} catch (reason) { } catch (reason) {
Logger.logError(`${endpointToValidate} not allowed`, "validateEndpoint"); Logger.logError(`${endpointToValidate} not allowed`, "validateEndpoint");
Logger.logError(`${JSON.stringify(reason)}`, "validateEndpoint"); Logger.logError(`${JSON.stringify(reason)}`, "validateEndpoint");