mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-10-13 15:28:05 +01:00
* Cleaning up unused config from portal backend migration. * Remove config used during backend migration. * Add backend endpoint override from config.json. * Add AAD and ARM endpoint overrides from config.json. * Add GRAPH_ENDPOINT override from config.json. * Remove unused catalog api version. * Remove isTerminalEnabled from config. Cannot find reference in DE, DE Release, or Frontend. * Fix mongo client unit tests. * Removing BackendApi from constants since no longer referenced in the codebase. * Talked with Tara and added the CATALOG_API_VERSION back to the config and substituted out the hard coded string it was intended to replace. * Include existing portal backend endpoints in default allow list. * Add localhost:1234 endpoint for Mongo unit tests. * Removing old backend local test endpoint from backend endpoint list.
100 lines
3.2 KiB
TypeScript
100 lines
3.2 KiB
TypeScript
import { CassandraProxyEndpoints, JunoEndpoints, MongoProxyEndpoints, PortalBackendEndpoints } from "Common/Constants";
|
||
import * as Logger from "../Common/Logger";
|
||
|
||
export function validateEndpoint(
|
||
endpointToValidate: string | undefined,
|
||
allowedEndpoints: ReadonlyArray<string>,
|
||
): boolean {
|
||
try {
|
||
return validateEndpointInternal(
|
||
endpointToValidate,
|
||
allowedEndpoints.map((e) => e),
|
||
);
|
||
} catch (reason) {
|
||
Logger.logError(`${endpointToValidate} not allowed`, "validateEndpoint");
|
||
Logger.logError(`${JSON.stringify(reason)}`, "validateEndpoint");
|
||
return false;
|
||
}
|
||
}
|
||
|
||
function validateEndpointInternal(
|
||
endpointToValidate: string | undefined,
|
||
allowedEndpoints: ReadonlyArray<string>,
|
||
): boolean {
|
||
if (endpointToValidate === undefined) {
|
||
return false;
|
||
}
|
||
|
||
const originToValidate: string = new URL(endpointToValidate).origin;
|
||
const allowedOrigins: string[] = allowedEndpoints.map((allowedEndpoint) => new URL(allowedEndpoint).origin) || [];
|
||
const valid = allowedOrigins.indexOf(originToValidate) >= 0;
|
||
|
||
if (!valid) {
|
||
throw new Error(
|
||
`${endpointToValidate} is not an allowed endpoint. Allowed endpoints are ${allowedEndpoints.toString()}`,
|
||
);
|
||
}
|
||
|
||
return valid;
|
||
}
|
||
|
||
export const defaultAllowedArmEndpoints: ReadonlyArray<string> = [
|
||
"https://api-dogfood.resources.windows-int.net/",
|
||
"https://management.azure.com",
|
||
"https://management.usgovcloudapi.net",
|
||
"https://management.chinacloudapi.cn",
|
||
];
|
||
|
||
export const defaultAllowedAadEndpoints: ReadonlyArray<string> = [
|
||
"https://login.microsoftonline.com/",
|
||
"https://login.microsoftonline.us/",
|
||
"https://login.partner.microsoftonline.cn/",
|
||
];
|
||
|
||
export const defaultAllowedGraphEndpoints: ReadonlyArray<string> = ["https://graph.microsoft.com"];
|
||
|
||
export const defaultAllowedBackendEndpoints: ReadonlyArray<string> = [
|
||
"https://localhost:1234",
|
||
PortalBackendEndpoints.Development,
|
||
PortalBackendEndpoints.Mpac,
|
||
PortalBackendEndpoints.Prod,
|
||
PortalBackendEndpoints.Fairfax,
|
||
PortalBackendEndpoints.Mooncake,
|
||
];
|
||
|
||
export const defaultAllowedMongoProxyEndpoints: ReadonlyArray<string> = [
|
||
"https://localhost:1234",
|
||
MongoProxyEndpoints.Development,
|
||
MongoProxyEndpoints.Mpac,
|
||
MongoProxyEndpoints.Prod,
|
||
MongoProxyEndpoints.Fairfax,
|
||
MongoProxyEndpoints.Mooncake,
|
||
];
|
||
|
||
export const defaultAllowedCassandraProxyEndpoints: ReadonlyArray<string> = [
|
||
CassandraProxyEndpoints.Development,
|
||
CassandraProxyEndpoints.Mpac,
|
||
CassandraProxyEndpoints.Prod,
|
||
CassandraProxyEndpoints.Fairfax,
|
||
CassandraProxyEndpoints.Mooncake,
|
||
];
|
||
|
||
export const allowedEmulatorEndpoints: ReadonlyArray<string> = ["https://localhost:8081"];
|
||
|
||
export const allowedArcadiaEndpoints: ReadonlyArray<string> = ["https://workspaceartifacts.projectarcadia.net"];
|
||
|
||
export const allowedHostedExplorerEndpoints: ReadonlyArray<string> = ["https://cosmos.azure.com/"];
|
||
|
||
export const allowedMsalRedirectEndpoints: ReadonlyArray<string> = ["https://dataexplorer-preview.azurewebsites.net/"];
|
||
|
||
export const allowedJunoOrigins: ReadonlyArray<string> = [
|
||
JunoEndpoints.Test,
|
||
JunoEndpoints.Test2,
|
||
JunoEndpoints.Test3,
|
||
JunoEndpoints.Prod,
|
||
JunoEndpoints.Stage,
|
||
"https://localhost",
|
||
];
|
||
|
||
export const allowedNotebookServerUrls: ReadonlyArray<string> = [];
|